yurloc commented on code in PR #5793:
URL: 
https://github.com/apache/incubator-kie-drools/pull/5793#discussion_r1530332949


##########
drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java:
##########
@@ -193,7 +194,7 @@ public FunctionDescr 
visitFunctiondef(DRLParser.FunctiondefContext ctx) {
                 functionDescr.addParameter(typeTypeContext.getText(), 
variableDeclaratorIdContext.getText());
             });
         }
-        functionDescr.setBody(getTextPreservingWhitespace(ctx.block()));
+        
functionDescr.setBody(stripBracesFromBlock(getTextPreservingWhitespace(ctx.drlBlock())));

Review Comment:
   ```suggestion
           
functionDescr.setBody(getTextPreservingWhitespace(ctx.drlBlock().drlBlockStatement()));
   ```
   @tkobayas by using block statements instead of the whole block, we could 
avoid "manually" trimming away the braces.
   
   Of course, this requires a new whitespace-text-preserving function that 
works on a list of contexts, something like this:
   ```java
       public static String getTextPreservingWhitespace(List<? extends 
ParserRuleContext> ctx) {
           return 
ctx.stream().map(Antlr4ParserStringUtils::getTextPreservingWhitespace).collect(Collectors.joining());
       }
   ```
   I find this simpler to understand and less error-prone (and maybe also 
reusable for other use cases) than the low-level string manipulation in 
`stripBracesFromBlock()`.
   
   Wdyt?



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