tkobayas commented on PR #5899:
URL:
https://github.com/apache/incubator-kie-drools/pull/5899#issuecomment-2097813623
This issue is pretty puzzling. In this PR, I add 2 test cases
`orWithMethodCall` and `orWithMethodCallWithArg` to some test classes. Probably
it's easy to debug with `DRLExprParserTest` because this issue focuses on a
constraint.
`orWithMethodCall` is correctly parsed to `value == 10` `||` ` someMethod()
== 4`. `||` matches `OR` in `conditionalOrExpression`
`orWithMethodCallWithArg` raises an error `no viable alternative at input
'someMethod'`, because the parser look into `orRestriction` and `||` matches
`OR` in the `orRestriction`. Then, it evaluates the semantic predicate
`{(helper.isPluggableEvaluator(false))}?` in `operator_key` and returns false.
I expected that the parser recovers from the path and goes back to
`conditionalOrExpression` and results in the same structure as
`orWithMethodCall` case.
At first, I thought the error recovery was wrong, so I raise a SO thread
(https://stackoverflow.com/questions/78417977/semantic-predicate-false-throws-noviablealtexception-in-adaptivepredict-then),
but probably I was wrong. Error recovery is to proceed the parser as possible
just to help developers to understand the error. We should avoid "error" in the
first place.
In Antlr3, we use "syntactic predicate" :
https://github.com/apache/incubator-kie-drools/blob/main/drools-drl/drools-drl-parser/src/main/resources/org/drools/drl/parser/DRL6Expressions.g#L412-L424
`(DOUBLE_PIPE fullAnnotation[null]? andRestriction)=>` triggers
"backtracking" which explores the possible paths and doesn't raise an error
even if it hits the semantic predicate false. It just thinks, "okay, we cannot
match this path".
Antlr4 says it no longer has "syntactic predicate" because Antlr4 can
explore paths better, so no need of "syntactic predicate". However, in our
case, it results in an error while it has other alternative match (= same as
`orWithMethodCall` case)
--
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]