[jboss-jira] [JBoss JIRA] Updated: (JBRULES-1055) Regex-Special characters can not be used in DSLs.
Michael Wiedmer (JIRA)
jira-events at lists.jboss.org
Thu Aug 2 11:59:49 EDT 2007
[ http://jira.jboss.com/jira/browse/JBRULES-1055?page=all ]
Michael Wiedmer updated JBRULES-1055:
-------------------------------------
Workaround Description: Users could replace the square brackets with other characters, e.g. the angle brackets. I do not want to be the one who has to bring it to the users to use a new syntax, though. (was: Users could replace the square brackets with other characters, e.g. the angle brackets.)
> Regex-Special characters can not be used in DSLs.
> -------------------------------------------------
>
> Key: JBRULES-1055
> URL: http://jira.jboss.com/jira/browse/JBRULES-1055
> Project: JBoss Rules
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Components: Drl Parser/Builder
> Affects Versions: 4.0.0.GA
> Environment: Windows XP, Java 5
> Reporter: Michael Wiedmer
> Assigned To: Mark Proctor
>
> Up until Drools 3.0.6 one could write DSLs to allow expressions such as
> EXAMPLE IS IN [ "one" "two"]
> This has changed now. The square brackes (being part of special characters for regular expressions) deny the DefaultDSLMappingEntry class to define a valid keyPattern.
> Here is a (not) working example, using the default sample project:
> 8<---- regexError.drl -----
> package some.test
> import com.sample.*;
> expander regexError.dsl
> rule "Test"
> when
> STRING "UK" IS IN < "USA", "UK", "GERMANY" >
> then
> LOG "Square Brackets will not work."
> end
> 8<---- regexError.dsl -----
> [consequence][]LOG {msg}=System.out.println({msg});
> [condition][]STRING "{string}" IS IN < {sequence} >=eval(true == true)
> 8<---- DroolsTest.javal -----
> package com.sample;
> import java.io.InputStreamReader;
> import java.io.Reader;
> import org.drools.RuleBase;
> import org.drools.RuleBaseFactory;
> import org.drools.WorkingMemory;
> import org.drools.compiler.PackageBuilder;
> import org.drools.rule.Package;
> public class DroolsTest {
> public static final void main(String[] args) {
> try {
> // load up the rulebase
> RuleBase ruleBase = readRule();
> WorkingMemory workingMemory = ruleBase.newStatefulSession();
> // go !
> Message message = new Message();
> message.setMessage("Hello World");
> message.setStatus(Message.HELLO);
> workingMemory.insert(message);
> workingMemory.fireAllRules();
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
> private static RuleBase readRule() throws Exception {
> Reader source = new InputStreamReader(DroolsTest.class.getResourceAsStream("/regexError.drl"));
> Reader dsl = new InputStreamReader(DroolsTest.class.getResourceAsStream("/regexError.dsl"));
> PackageBuilder builder = new PackageBuilder();
> builder.addPackageFromDrl(source, dsl);
> Package pkg = builder.getPackage();
> RuleBase ruleBase = RuleBaseFactory.newRuleBase();
> ruleBase.addPackage(pkg);
> return ruleBase;
> }
> }
> If one was to change the files regexError.dsl and regexError.drl and use square brackets instead of angle brackets, the DroolsTest will fail with the same error as shown in the Eclipse IDE:
> org.drools.rule.InvalidRulePackage: org.drools.lang.ExpanderException at 14c1103[9,2]: unknown:9:2 Unexpected token 'STRING'[9,22]: unknown:9:22 mismatched token: [@31,115:119='"USA"',<20>,9:22]; expecting type RIGHT_SQUARE[11,1]: unknown:11:1 mismatched token: [@43,150:155='System',<8>,11:1]; expecting type RIGHT_PAREN[11,20]: unknown:11:20 mismatched token: [@49,169:200='"Square Brackets will not work."',<20>,11:20]; expecting type RIGHT_PAREN[12,0]: unknown:12:0 mismatched token: [@53,205:207='end',<15>,12:0]; expecting type THEN
> at org.drools.rule.Package.checkValidity(Package.java:408)
> at org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:288)
> at com.sample.DroolsTest.readRule(DroolsTest.java:44)
> at com.sample.DroolsTest.main(DroolsTest.java:18)
> It does not matter what the RHS of the DSL says, as the LHS will not be matched in DefaultExpander.expandLHS(final String lhs, int lineOffset), line 231.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list