Skip to content

Commit 34a5c1a

Browse files
committed
feat: #523 warn users that predicates and actions are not run by the interpreter
1 parent 9d507af commit 34a5c1a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/main/java/org/antlr/intellij/plugin/parsing/PreviewParser.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class PreviewParser extends GrammarParserInterpreter {
1919

2020
protected int lastSuccessfulMatchState = ATNState.INVALID_STATE_NUMBER; // not sure about error nodes
2121

22+
private boolean warnedAboutPredicates = false;
23+
2224
public PreviewParser(Grammar g, ATN atn, TokenStream input) {
2325
super(g, atn, input);
2426
lexerWatchdog = new LexerWatchdog(input, this);
@@ -33,6 +35,7 @@ public void reset() {
3335
super.reset();
3436
if ( inputTokenToStateMap!=null ) inputTokenToStateMap.clear();
3537
lastSuccessfulMatchState = ATNState.INVALID_STATE_NUMBER;
38+
warnedAboutPredicates = false;
3639
}
3740

3841
@Override
@@ -75,4 +78,23 @@ public Token matchWildcard() throws RecognitionException {
7578
lastSuccessfulMatchState = getState();
7679
return super.matchWildcard();
7780
}
81+
82+
@Override
83+
public void action(RuleContext _localctx, int ruleIndex, int actionIndex) {
84+
warnAboutPredicatesAndActions();
85+
}
86+
87+
@Override
88+
public boolean sempred(RuleContext _localctx, int ruleIndex, int actionIndex) {
89+
warnAboutPredicatesAndActions();
90+
return super.sempred(_localctx, ruleIndex, actionIndex);
91+
}
92+
93+
private void warnAboutPredicatesAndActions() {
94+
if (!warnedAboutPredicates) {
95+
notifyErrorListeners("WARNING: predicates and actions are not run by this interpreter. " +
96+
"Results may vary from the actual generated parser!");
97+
warnedAboutPredicates = true;
98+
}
99+
}
78100
}

0 commit comments

Comments
 (0)