| Summary: | DSL Parser "eval" | ||
|---|---|---|---|
| Product: | [JBoss] JBoss Enterprise BRMS Platform 5 | Reporter: | nwallace <nwallace> |
| Component: | unspecified | Assignee: | Edson Tirelli <ed.tirelli> |
| Status: | CLOSED NEXTRELEASE | QA Contact: | |
| Severity: | unspecified | Docs Contact: | |
| Priority: | medium | ||
| Version: | unspecified | CC: | dlesage |
| Target Milestone: | --- | ||
| Target Release: | 5.0.1 | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| URL: | http://jira.jboss.org/jira/browse/BRMS-147 | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | Bug Fix | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2009-09-21 05:36:46 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
Link: Added: This issue is related to JBRULES-1278 This question is for the Resolved Jiras in the Release Notes: Is the bug referring to the eval argument being parsed instead of the output of eval? Can I please have some more details about this? I am not sure I understand your question. The related JIRA is this: https://jira.jboss.org/jira/browse/JBRULES-1278 The problem was in old drools parsers, where not all escapes were listed. In Drools 5, the parser supports all java documented escapes. Also, in Drools 4, drools used single escapes (instead of double escapes like java), so outside eval, you would only write single escapes while inside eval (java) you would use double. There were also other corner cases. Now, in Drools 5, it uses the same standard as java, i.e., double escapes. So the behavior will be consistent everywhere. Edson, thanks for explaining that. As tech writers are not subject matter experts or programmers, we just needed extra information to understand the nature of the problem in this case. Just one more question: What is the difference between double- and single-escapes? Can you please explain this a little more? Hi David, Oh, ok. Let me try to explain. In Java, when you are writing strings in the code, you can use escapes to represent special characters, like \n to represent a line break, etc. You can check the link bellow for the complete list of escapes accepted by java (under the section: "Summary of regular-expression constructs" ): http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html Additionally, when writing code in a java file, you need to use double \\ to escape a character, because the java parser requires you to escape the \ itself. So, for instance writing my name in two lines in a java file would look like: "Edson \\n Tirelli" Where \\n is the line break character. Now, there were 2 problems in previous Drools versions: 1. Not all escapes were previously accepted by Drools parser. For instance, this jira reports a problem with \s not being accepted. This was fixed and now Drools accepts all escapes accepted by java. 2. Drools up to version 4 would use single escapes (like "\n") instead of ("\\n"). This allowed for some situations where it was not possible to represent some characters, and was not consistent with the overall java experience. So, in Drools 5, that changed and now Drools uses double escapes the same way as java. BUT, to avoid forcing customers migrating to immediately change all their code, we added an option to KnowledgeBuilderConfiguration for the cases where customers still want the old behavior. They can configure Drools 5 to use single escape (as Drools 4) by setting the configuration option: KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(); config.setOption( ProcessStringEscapesOption.NO ); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( conf ); or, if they prefer to use properties: KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(); config.setProperty( ProcessStringEscapesOption.PROPERTY_NAME, "false" ); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( conf ); Let me know if you have further questions. Thanks, Edson. That is great detail. We didn't realise you were referring to regular expressions. Just one more bit of info, please, for the release notes: 1 - Was the actual *fix* here to add the ProcessStringEscapesOption? Just a side note, this one has a corresponding test case in 5.0.1: http://anonsvn.jboss.org/repos/labs/labs/jbossrules/soa_branches/BRMS-5.0.1/drools-compiler/src/test/resources/org/drools/integrationtests/test_MatchesNotMatches.drl http://anonsvn.jboss.org/repos/labs/labs/jbossrules/soa_branches/BRMS-5.0.1/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java (testMatchesNotMatchesCheese) David, Yes, the fix was to enable the processing of string escapes and add the option in case the user wants backward compatible behavior. It is not only used for regexp. It is used for any strings used by rules, be it regular expression or simple strings. []s Edson |
Date of First Response: 2009-09-01 01:18:49 securitylevel_name: Public rule "PatternTest" when $pli:Item( title matches "^Test\s*") then # end this one compiles but on Runtime it ends in an Exception when title looks for example like this "BlaBla (Test)". as workaround i thought about using the next part, but rule "PatternTest" when $pli:Item( eval(title.matches("^Test\s*")) ) then # end it resolves into, also it shouldn't (because title.matches() is Java Code a shouldn't be parsed by the DSL Parser itself): SyntaxfehlerRule Compilation error : [Rule name=OnlineStreaming Start, agendaGroup=MAIN, salience=100, no-loop=true] com/p7s1/swi/phoenix/n24/Rule_OnlineStreaming_Start_0.java (19:923) : Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )