diff --git a/runtime/Java/src/org/antlr/v4/runtime/Parser.java b/runtime/Java/src/org/antlr/v4/runtime/Parser.java index dc9693d22..7c128eede 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/Parser.java +++ b/runtime/Java/src/org/antlr/v4/runtime/Parser.java @@ -142,7 +142,7 @@ public abstract class Parser extends Recognizer */ public Token match(int ttype) throws RecognitionException { Token t = getCurrentToken(); - if ( getInputStream().LA(1)==ttype ) { + if ( t.getType()==ttype ) { _errHandler.endErrorCondition(this); consume(); } @@ -157,6 +157,24 @@ public abstract class Parser extends Recognizer return t; } + public Token matchWildcard() throws RecognitionException { + Token t = getCurrentToken(); + if (t.getType() > 0) { + _errHandler.endErrorCondition(this); + consume(); + } + else { + t = _errHandler.recoverInline(this); + if (_buildParseTrees && t.getTokenIndex() == -1) { + // we must have conjured up a new token during single token insertion + // if it's not the current symbol + _ctx.addErrorNode(t); + } + } + + return t; + } + /** Track the RuleContext objects during the parse and hook them up * using the children list so that it forms a parse tree. * The RuleContext returned from the start rule represents the root diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg index 0aee59a37..4e7a52183 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg @@ -450,7 +450,7 @@ CommonSetStuff(m, expr, capture, invert) ::= << setState(); = }>_input.LT(1); -if ( !() ) { +if ( \<= 0 || !() ) { = (Token)}>_errHandler.recoverInline(this); } consume(); @@ -458,7 +458,7 @@ consume(); Wildcard(w) ::= << setState(); - = }>_input.LT(1); consume(); + = }>matchWildcard(); >> // ACTION STUFF diff --git a/tool/src/org/antlr/v4/codegen/model/MatchNotSet.java b/tool/src/org/antlr/v4/codegen/model/MatchNotSet.java index 9e8433b39..2d7ce71f7 100644 --- a/tool/src/org/antlr/v4/codegen/model/MatchNotSet.java +++ b/tool/src/org/antlr/v4/codegen/model/MatchNotSet.java @@ -33,6 +33,7 @@ import org.antlr.v4.codegen.OutputModelFactory; import org.antlr.v4.tool.ast.GrammarAST; public class MatchNotSet extends MatchSet { + public String varName = "_la"; public MatchNotSet(OutputModelFactory factory, GrammarAST ast) { super(factory, ast); }