yurloc commented on code in PR #5759:
URL:
https://github.com/apache/incubator-kie-drools/pull/5759#discussion_r1511893933
##########
drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRL6Expressions.g4:
##########
@@ -770,72 +770,72 @@ assignmentOperator
// KEYWORDS
// --------------------------------------------------------
extends_key
- : {(helper.validateIdentifierKey(DroolsSoftKeywords.EXTENDS))}?
id=IDENTIFIER { helper.emit($id, DroolsEditorType.KEYWORD); }
+ : id=EXTENDS { helper.emit($id, DroolsEditorType.KEYWORD); }
;
super_key
- : {(helper.validateIdentifierKey(DroolsSoftKeywords.SUPER))}?
id=SUPER { helper.emit($id, DroolsEditorType.KEYWORD); }
+ : id=SUPER { helper.emit($id, DroolsEditorType.KEYWORD); }
;
instanceof_key
- : {(helper.validateIdentifierKey(DroolsSoftKeywords.INSTANCEOF))}?
id=IDENTIFIER { helper.emit($id, DroolsEditorType.KEYWORD); }
Review Comment:
Sure. Please read the first two paragraphs about [semantic
predicates](https://github.com/antlr/antlr4/blob/master/doc/predicates.md).
Semantic predicate at the start of an alternative is used to "kill" that
alternative although it is viable from the syntactic perspective.
The semantic predicate guard was necessary here in the previous version of
the grammar because the lexer grammar didn't have specific tokens for the
individual keywords (e.g. `SUPER` token for the `super` keyword). Instead, it
used the next most specific token (`IDENTIFIER`) in all the different keyword
rules and it used the semantic predicate to check whether the
`IDENTIFIER`-matching word is actually the keyword that the rule is about.
On this line, `helper.validateIdentifierKey(DroolsSoftKeywords.INSTANCEOF)`
simply looked at the next token in the token stream and checked whether the
string value of the token was equal to `DroolsSoftKeywords.INSTANCEOF` (which
is `"instanceof"`).
In the next parser version, we have `JavaLexer.g4` that has these specific
tokens (or [lexer
rules](https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md)) so we
can use them instead of `IDENTIFIER`, and that makes the syntactic predicate
redundant.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]