tkobayas commented on code in PR #7096:
URL: https://github.com/apache/incubator-kie/pull/7096#discussion_r3977268610
##########
drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/Drl6ExprParser.java:
##########
@@ -68,6 +70,26 @@ public ConstraintConnectiveDescr parse( final String text ) {
return constraint;
}
+ /**
+ * Returns whether to preserve the eval wrapper around the supplied
contents.
+ * The constraint parser enters at conditionalOrExpression, which is below
+ * ternaryExpression in the grammar, so a top-level ternary's branches are
+ * silently discarded. Question-mark tokens at any nesting depth may
indicate
+ * such a ternary. Strings and comments are ignored.
+ * Lexer errors also preserve the wrapper, leaving validation to
compilation.
+ * This is a conservative check, not validation of ternary syntax.
+ */
+ public static boolean shouldPreserveEval(String expression) {
+ DRL6Lexer lexer = new DRL6Lexer(new ANTLRStringStream(expression));
+ for (Token token = lexer.nextToken(); token.getType() != Token.EOF;
token = lexer.nextToken()) {
+ // QUESTION_DIV also covers a ternary immediately followed by a
comment: x?/*...*/y:z.
+ if (token.getType() == DRL6Lexer.QUESTION || token.getType() ==
DRL6Lexer.QUESTION_DIV) {
+ return true;
+ }
+ }
+ return !lexer.getErrors().isEmpty();
+ }
Review Comment:
@yesamer It should work, because the DRL6 resources exist in 7.x. (note that
`Drl6ExprParser` is `DrlExprParser` in 7.x)
--
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]