-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[new-parser] Fix super_key failed predicate #5748
[new-parser] Fix super_key failed predicate #5748
Conversation
Many thanks @yurloc for the explanation.
My personal focus, here, is to improve the "readability" (at least in general terms) also by someone that does not work on it daily: does this make sense ? |
b26c82a
to
ecdb23b
Compare
Thanks @gitgabrio. While working on your suggestions, I realized that my original fix was completely wrong. I've pushed a new fix which is more self-explanatory and I'll see tomorrow if it can be improved with some comments. |
Fixing progress: There were 549 failed tests (-0). |
How it works on
main
This is how the
selector
rule and its first alternative looks like in the old parser:The whole first alternative is guarded by a syntactic predicate that is used to make the decision whether this alternative is viable. The syntactic predicate relies on the
super_key
rule, which looks like this:If the next token is not
super
,validateIdentifierKey()
will evaluate tofalse
, rendering the first alternative of theselector
rule non-viable.What is the problem on the
dev-new-parser
branch?Syntactic predicates were removed in ANTLR 4 so the
selector
rule became:The semantic predicate
{(helper.validateIdentifierKey(DroolsSoftKeywords.SUPER))}?
now cannot be used to make the decision about the viability of the first alternative because it is now "invisible". See https://github.com/antlr/antlr4/blob/master/doc/predicates.md#finding-visible-predicates that explains how predicates can become invisible. The thing that makes the predicate invisible here is the action after DOT. And since thesuper_key
rule matches theIDENTIFIER
type of token, this alternative seems viable and the parser takes it even if the next token is notsuper
.When the decision has been made and the alternative is taken, the parser executes the action after
DOT
and the semantic predicate insidesuper_key
is no longer invisible. It is now evaluated as well. But if the next token is notsuper
it evaluates to false, which is an error condition because there is no other alternative insidesuper_key
.The fix is to replace the
IDENTIFIER
token type withSUPER
.Fixes #5703.