[jboss-jira] [JBoss JIRA] Commented: (JBRULES-1278) DSL Parser "eval"

M H (JIRA) jira-events at lists.jboss.org
Thu Feb 21 12:53:42 EST 2008


    [ http://jira.jboss.com/jira/browse/JBRULES-1278?page=comments#action_12400218 ] 
            
M H commented on JBRULES-1278:
------------------------------

The good news is, i'm not able to reproduce the first part of the bug with drools 4.0.4

BUT i found some strange behaviour about the "\s" pattern (which is pattern http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html for whitespaces  as says)

Following DSL:

[condition][]a TestItem=TestItem()
[condition][]- the field match {value}=title matches {value}
[condition][]- the field value {value}=eval(title.matches({value}))

Rules:

rule "TestRule"
	salience 1
	when
		$item: a TestItem
	then 
		>System.out.println("show item in workspace: " + $item);
end

rule "TestRule 1"
	salience 0
	when
		$item: a TestItem
			- the field value "^Test\s+"
	then 
		>System.out.println("Rule 1 eval(title.matches(^Test\s+)): " + $item);
end

rule "TestRule 2"
	salience 0
	when
		$item: a TestItem
			- the field match "^Test\s+"
	then 
		>System.out.println("Rule 2 (title matches ^Test\s+): " + $item);
end

rule "TestRule 3"
	salience 0
	when
		$item: a TestItem
			- the field match "^Test\s*"
	then 
		>System.out.println("Rule 3 (title matches ^Test\s*): " + $item);
end

rule "TestRule 4"
	salience 0
	when
		$item: a TestItem
			- the field match "^Test\s+.*"
	then 
		>System.out.println("Rule 4 (title matches ^Test\s*.*): " + $item);
end

rule "TestRule 5"
	salience 0
	when
		$item: a TestItem
			- the field value "^Test\s*"
	then 
		>System.out.println("Rule 5 eval(title.matches(^Test\s*)): " + $item);
end

rule "TestRule 6"
	salience 0
	when
		$item: a TestItem
			- the field value "^Test\s*"
	then 
		>System.out.println("Rule 6 eval(title.matches(^Test\s*): " + $item);
end

Following result:

1. show item in workspace: _Test (Hallo Welt!)_
2. show item in workspace: _Test_
3. show item in workspace: _Hallo Welt!_
4. show item in workspace: _Test   _
Rule 5 eval(title.matches(^Tests*)): _Test_
Rule 6 eval(title.matches(^Tests*): _Test_
Rule 3 (title matches ^Tests*): _Test_

in my point of view: 

Item 1 should match Rule 4 (check: System.out.println("Test (Hallo Welt!)".matches("^Test\\s+.*"));)
Item 2 should match Rule 3, 5 and 6 which is OK.
Item 3 should never match which is also OK
Item 4 should match Rule 1, Rule 2, Rule 3, Rule 4, Rule 5 and Rule 6 e.g.: System.out.println("Test   ".matches("^Test\\s*"));


So maybe i miss something very important, but currently after 10 hours work i am a bit confused ...


what i can reproduce is

rule "TestRule 7"
	salience 0
	when
		$item: a TestItem
			- the field value "^Test\\s+"
	then 
		>System.out.println("Rule 1 eval(title.matches(^Test\\s+)): " + $item);
end

resolves in an error when compiling:

line 1:20 no viable alternative at character '\'
line 1:25 mismatched character '<EOF>' expecting '"'
org.drools.rule.InvalidRulePackage: Rule Compilation error : [Rule name=TestRule 1, agendaGroup=MAIN, salience=0, no-loop=false]
	com/sample/Rule_TestRule_1_0.java (8:333) : Invalid escape sequence (valid ones are  \b  \t  \n  \f  \r  \"  \'  \\ )

the point is in pure Java code pattern i have to write title.matches("^Test\\s*"), ( the problem is \\ instead of \) and eval should direct to Java or not?

If i just use \s* the DRL Viewer shows s*, using \\s* it shows \s* which is right.

> DSL Parser "eval"
> -----------------
>
>                 Key: JBRULES-1278
>                 URL: http://jira.jboss.com/jira/browse/JBRULES-1278
>             Project: JBoss Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: Drl Parser/Builder
>    Affects Versions: 4.0.1
>            Reporter: M H
>         Assigned To: Edson Tirelli
>            Priority: Blocker
>             Fix For: 4.0.5
>
>
> 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 \" \' \\ )

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