From 4090621bebb1e1d70f75071210250ed0630a28bd Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Sat, 4 Aug 2012 13:51:18 -0700 Subject: [PATCH] same literal different modes gens no literal in .tokens, rm warning --- tool/playground/T.g | 21 +++---------------- .../antlr/v4/semantics/SemanticPipeline.java | 7 ++++--- tool/src/org/antlr/v4/tool/ErrorType.java | 2 +- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/tool/playground/T.g b/tool/playground/T.g index 1dfde4700..2921c2f2b 100644 --- a/tool/playground/T.g +++ b/tool/playground/T.g @@ -1,19 +1,4 @@ -grammar T; +lexer grammar T; -s: expr_or_assign* ; - -expr_or_assign - : expr '++' - | expr - ; - -expr : expr_primary ('<-' ID)? ; - -expr_primary - : '(' ID ')' - | ID '(' ID ')' - | ID - ; - -ID : [a-z]+ ; -WS : [ \t\r\n]+ -> skip ; +A : 'a' ; +B : 'a' ; diff --git a/tool/src/org/antlr/v4/semantics/SemanticPipeline.java b/tool/src/org/antlr/v4/semantics/SemanticPipeline.java index 1b89168a3..58f0977ad 100644 --- a/tool/src/org/antlr/v4/semantics/SemanticPipeline.java +++ b/tool/src/org/antlr/v4/semantics/SemanticPipeline.java @@ -171,9 +171,10 @@ public class SemanticPipeline { G.defineTokenAlias(nameAST.getText(), litAST.getText()); } else { - g.tool.errMgr.grammarError(ErrorType.ALIAS_REASSIGNMENT, - g.fileName, nameAST.token, - litAST.getText(), nameAST.getText()); + // oops two literal defs in two rules (within or across + // modes). Remove literal in either case so it's not + // found by parser. + G.stringLiteralToTypeMap.remove(litAST.getText()); } } } diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index 15da9c616..f6c22c090 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -145,7 +145,7 @@ public enum ErrorType { ALT_LABEL_CONFLICTS_WITH_RULE(124, "rule alt label conflicts with rule ", ErrorSeverity.ERROR), IMPLICIT_TOKEN_DEFINITION(125, "implicit definition of token in parser", ErrorSeverity.WARNING), IMPLICIT_STRING_DEFINITION(126, "cannot create implicit token for string literal in non-combined grammar", ErrorSeverity.ERROR), - ALIAS_REASSIGNMENT(127, "token literal aliased to new token name ", ErrorSeverity.WARNING), +// ALIAS_REASSIGNMENT(127, "token literal aliased to new token name ", ErrorSeverity.WARNING), /** Documentation comment is unterminated */ //UNTERMINATED_DOC_COMMENT(, "", ErrorSeverity.ERROR),