All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.contextmapper.tactic.dsl.validation.TacticDslSyntaxErrorMessageProvider Maven / Gradle / Ivy

/**
 * Copyright 2013 The Sculptor Project Team, including the original
 * author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.contextmapper.tactic.dsl.validation;

import com.google.inject.Inject;
import org.antlr.runtime.MismatchedTokenException;
import org.antlr.runtime.MissingTokenException;
import org.contextmapper.tactic.dsl.validation.IssueCodes;
import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.IGrammarAccess;
import org.eclipse.xtext.nodemodel.SyntaxErrorMessage;
import org.eclipse.xtext.parser.antlr.ISyntaxErrorMessageProvider;
import org.eclipse.xtext.parser.antlr.SyntaxErrorMessageProvider;

/**
 * Customizes syntax error message of the ANTLR lexer / parser.
 * 

* see http://zarnekow.blogspot.com/2010/06/customizing-error-messages-in-xtext-10.html */ @SuppressWarnings("all") public class TacticDslSyntaxErrorMessageProvider extends SyntaxErrorMessageProvider { @Inject private IGrammarAccess grammarAccess; /** * Customizes error message for reserved keywords "mismatched input 'xxx' expecting RULE_ID". */ @Override public SyntaxErrorMessage getSyntaxErrorMessage(final ISyntaxErrorMessageProvider.IParserErrorContext context) { SyntaxErrorMessage _xblockexpression = null; { if (((context.getRecognitionException() instanceof MissingTokenException) || (context.getRecognitionException() instanceof MismatchedTokenException))) { final String missingTokenText = context.getRecognitionException().token.getText(); boolean _contains = GrammarUtil.getAllKeywords(this.grammarAccess.getGrammar()).contains(missingTokenText); if (_contains) { return new SyntaxErrorMessage( ((((("\'" + missingTokenText) + "\' is a reserved keyword which is not allowed as Identifier. ") + "Please choose another word or alternatively escape it with the caret (^) character, e.g. \'^") + missingTokenText) + "\'"), IssueCodes.USED_RESERVED_KEYWORD, new String[] { missingTokenText }); } } _xblockexpression = super.getSyntaxErrorMessage(context); } return _xblockexpression; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy