* added check for v3 backward incompatibilities:

** {...}?=> gate semantic predicates
This commit is contained in:
Terence Parr 2012-11-18 13:59:43 -08:00
parent 405a447ada
commit c5bf2ba0bd
5 changed files with 35 additions and 3 deletions

View File

@ -10,6 +10,7 @@ November 18, 2012
** labels in lexer rules
** tokens {A;B;} syntax
** tokens {A='C';} syntax
** {...}?=> gate semantic predicates
November 17, 2012

View File

@ -41,10 +41,10 @@ import org.antlr.v4.automata.LexerATNFactory;
import org.antlr.v4.automata.ParserATNFactory;
import org.antlr.v4.codegen.CodeGenPipeline;
import org.antlr.v4.misc.Graph;
import org.antlr.v4.parse.ANTLRLexer;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.parse.GrammarASTAdaptor;
import org.antlr.v4.parse.GrammarTreeVisitor;
import org.antlr.v4.parse.ToolANTLRLexer;
import org.antlr.v4.parse.ToolANTLRParser;
import org.antlr.v4.parse.v3TreeGrammarException;
import org.antlr.v4.runtime.misc.LogManager;
@ -600,7 +600,7 @@ public class Tool {
public GrammarRootAST load(String fileName, CharStream in) {
try {
GrammarASTAdaptor adaptor = new GrammarASTAdaptor(in);
ANTLRLexer lexer = new ANTLRLexer(in);
ToolANTLRLexer lexer = new ToolANTLRLexer(in, this);
CommonTokenStream tokens = new CommonTokenStream(lexer);
lexer.tokens = tokens;
ToolANTLRParser p = new ToolANTLRParser(tokens, this);

View File

@ -297,7 +297,17 @@ ARG_ACTION
// the delimiting {} is no additional overhead.
//
ACTION
: NESTED_ACTION ('?' {$type = SEMPRED;} )?
: NESTED_ACTION
('?' {$type = SEMPRED;} )?
( '=>' // v3 gated sempred
{
Token t = new CommonToken(input, state.type, state.channel, state.tokenStartCharIndex, getCharIndex()-1);
t.setLine(state.tokenStartLine);
t.setText(state.text);
t.setCharPositionInLine(state.tokenStartCharPositionInLine);
grammarError(ErrorType.V3_GATED_SEMPRED, t);
}
)?
;
// ----------------

View File

@ -0,0 +1,20 @@
package org.antlr.v4.parse;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.Token;
import org.antlr.v4.Tool;
import org.antlr.v4.tool.ErrorType;
public class ToolANTLRLexer extends ANTLRLexer {
public Tool tool;
public ToolANTLRLexer(CharStream input, Tool tool) {
super(input);
this.tool = tool;
}
@Override
public void grammarError(ErrorType etype, Token token, Object... args) {
tool.errMgr.grammarError(etype, getSourceName(), token, args);
}
}

View File

@ -123,6 +123,7 @@ public enum ErrorType {
"getText() to get the entire text matched for the rule", ErrorSeverity.WARNING_ONE_OFF),
V3_TOKENS_SYNTAX(202, "'tokens {A; B;}' syntax is now 'tokens {A, B}' in ANTLR v4", ErrorSeverity.WARNING),
V3_ASSIGN_IN_TOKENS(203, "assignments in tokens{} are not supported in ANTLR v4; use lexical rule '<arg> : <arg2>;' instead", ErrorSeverity.ERROR_ONE_OFF),
V3_GATED_SEMPRED(204, "{...}?=> gate semantic predicates in v3 behave like normal predicates in ANTLR v4; use {...}? instead", ErrorSeverity.WARNING_ONE_OFF),
// Dependency sorting errors