yesamer commented on code in PR #7096:
URL: https://github.com/apache/incubator-kie/pull/7096#discussion_r3976538021


##########
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:
   @tkobayas My only question: Is that compatible with 7.x code?



-- 
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]

Reply via email to