diff --git a/tool/src/org/antlr/v4/semantics/SemanticPipeline.java b/tool/src/org/antlr/v4/semantics/SemanticPipeline.java index 89adf24df..da87b3b64 100644 --- a/tool/src/org/antlr/v4/semantics/SemanticPipeline.java +++ b/tool/src/org/antlr/v4/semantics/SemanticPipeline.java @@ -221,16 +221,13 @@ public class SemanticPipeline { { //Grammar G = g.getOutermostGrammar(); // put in root, even if imported - // DEFINE tokens { X='x'; } ALIASES + // create token types for tokens { A, B, C } ALIASES for (GrammarAST alias : tokensDefs) { - if ( alias.getType()== ANTLRParser.ASSIGN ) { - String name = alias.getChild(0).getText(); - String lit = alias.getChild(1).getText(); - g.defineTokenAlias(name, lit); - } - else { - g.defineTokenName(alias.getText()); + if (g.getTokenType(alias.getText()) != Token.INVALID_TYPE) { + g.tool.errMgr.grammarError(ErrorType.TOKEN_NAME_REASSIGNMENT, g.fileName, alias.token, alias.getText()); } + + g.defineTokenName(alias.getText()); } // DEFINE TOKEN TYPES FOR TOKEN REFS LIKE ID, INT diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index 51a969544..b34cd04f6 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -126,7 +126,7 @@ public enum ErrorType { NO_SUCH_GRAMMAR_SCOPE(105, "reference to undefined grammar in rule reference: .", ErrorSeverity.ERROR), NO_SUCH_RULE_IN_SCOPE(106, "rule is not defined in grammar ", ErrorSeverity.ERROR), // TOKEN_STRING_REASSIGNMENT(107, "cannot alias in tokens {}; string already assigned to ", ErrorSeverity.ERROR), -// TOKEN_NAME_REASSIGNMENT(108, "cannot redefine ; token name already assigned to defined", ErrorSeverity.ERROR), + TOKEN_NAME_REASSIGNMENT(108, "token name is already defined", ErrorSeverity.WARNING), //TOKEN_VOCAB_IN_DELEGATE(, "tokenVocab option ignored in imported grammar ", ErrorSeverity.ERROR), OPTIONS_IN_DELEGATE(109, "options ignored in imported grammar ", ErrorSeverity.WARNING), // TOKEN_ALIAS_IN_DELEGATE(, "can't assign string to token name to string in imported grammar ", ErrorSeverity.ERROR),