v4: check for null before evaluating sempreds in the lexer (issue a warning if no recognizer is available for evaluation)

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9486]
This commit is contained in:
sharwell 2011-11-29 18:59:32 -08:00
parent c25f3ff3d8
commit a71a9f04ea
1 changed files with 5 additions and 1 deletions

View File

@ -458,8 +458,12 @@ public class LexerATNSimulator extends ATNSimulator {
c = new ATNConfig(config, t.target, newContext);
}
else if ( t.getClass() == PredicateTransition.class ) {
if (recog == null) {
System.out.printf("Predicates cannot be evaluated without a recognizer; assuming true.\n");
}
PredicateTransition pt = (PredicateTransition)t;
if ( recog.sempred(null, pt.ruleIndex, pt.predIndex) ) {
if ( recog == null || recog.sempred(null, pt.ruleIndex, pt.predIndex) ) {
c = new ATNConfig(config, t.target);
c.traversedPredicate = true;
}