From ae111eddbdfd926e25b8c60aa23e5144d2c6e2df Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Sun, 18 Nov 2012 13:03:37 -0800 Subject: [PATCH] * added check for v3 backward incompatibilities: ** labels in lexer rules --- CHANGES.txt | 1 + tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java | 9 +++++++++ tool/src/org/antlr/v4/tool/ErrorType.java | 3 +++ 3 files changed, 13 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index ba8d15efb..f8588db15 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -7,6 +7,7 @@ November 18, 2012 * added notion of one-off error * added check for v3 backward incompatibilities: ** tree grammars +** labels in lexer rules November 17, 2012 diff --git a/tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java b/tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java index 9b0bc57ad..f4793a63b 100644 --- a/tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java +++ b/tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java @@ -382,6 +382,15 @@ public class BasicSemanticChecks extends GrammarTreeVisitor { } } + @Override + protected void enterLabeledLexerElement(GrammarAST tree) { + Token label = ((GrammarAST)tree.getChild(0)).getToken(); + g.tool.errMgr.grammarError(ErrorType.V3_LEXER_LABEL, + g.fileName, + label, + label.getText()); + } + /** Check option is appropriate for grammar, rule, subrule */ boolean checkOptions(GrammarAST parent, Token optionID, diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index b6c632f47..5777d6631 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -118,6 +118,9 @@ public enum ErrorType { // Backward incompatibility errors V3_TREE_GRAMMAR(200, "tree grammars are not supported in ANTLR v4", ErrorSeverity.ERROR_ONE_OFF), + V3_LEXER_LABEL(201, "labels in lexer rules are not supported in ANTLR v4; " + + "actions cannot reference elements of lexical rules but you can use " + + "getText() to get the entire text matched for the rule", ErrorSeverity.ERROR_ONE_OFF), // Dependency sorting errors