[
https://jira.jboss.org/jira/browse/JBRULES-1262?page=com.atlassian.jira.p...
]
Jörg Harm commented on JBRULES-1262:
------------------------------------
Changing in the class DefaultExpander
final Matcher m2 = patternFinder.matcher( expanded[lastPattern] );
to
final ParenthesesMatcher m2 = new ParenthesesMatcher( expanded[lastPattern] );
with the ParenthesesMatcher being
private static class ParenthesesMatcher implements MatchResult {
private final String input;
int start = -1;
int end = -1;
public ParenthesesMatcher(String input) {
this.input = input;
}
public boolean find() {
start = input.indexOf('(', end + 1);
if (start >= 0) {
char stringDelimiter = 0;
for (int i = start + 1, count = 1; i < input.length()
&& count > 0; i++) {
if (stringDelimiter == 0) {
final char ch = input.charAt(i);
switch (ch) {
case '(':
count++;
break;
case ')':
count--;
if (count == 0) {
end = i;
}
break;
case '\'':
case '"':
stringDelimiter = ch;
default:
break;
}
} else {
if (input.charAt(i) == stringDelimiter
&& input.charAt(i - 1) != '\\') {
stringDelimiter = 0;
}
}
}
}
return 0 <= start && start < end;
}
public int start() {
return start(0);
}
public int start(int group) {
checkMatched();
checkGroup(group);
return startUnchecked(group);
}
private int startUnchecked(int group) {
return start + group;
}
public int end() {
return end(0);
}
public int end(int group) {
checkMatched();
checkGroup(group);
return endUnchecked(group);
}
private int endUnchecked(int group) {
return end + 1 - group;
}
public String group() {
return group(0);
}
public String group(int group) {
checkMatched();
checkGroup(group);
return input.substring(startUnchecked(group), endUnchecked(group));
}
public int groupCount() {
return 1;
}
private void checkGroup(int group) {
if (group > groupCount()) {
throw new IndexOutOfBoundsException("No group " + group);
}
}
private void checkMatched() {
if (0 > start || start >= end) {
throw new IllegalStateException("No match found");
}
}
}
"eval" can be used even if there parentheses in string literals somewhere. With
this change the builds works and shows no failures.
DSL Parser "eval"
-----------------
Key: JBRULES-1262
URL:
https://jira.jboss.org/jira/browse/JBRULES-1262
Project: Drools
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: drools-compiler-DSL
Affects Versions: 4.0.1
Reporter: M H
Assignee: Edson Tirelli
Priority: Minor
Fix For: FUTURE
[when]of type Item=Item()
[when]- Title equals "{value}"=eval(title.isEqual("{value}")
[when]- Event equals "{value}"=eval(id.isEqual("{value}")
[then]Log : "{message}"=System.out.println("{message}");
the dslr File:
expander Test.dsl
rule "Your First Rule"
when
$p : of type Item
- Title equals "test"
- Event equals "test"
then
#actions
end
resolves to (could be seen in the drl viewer)
rule "Your First Rule"
when
$p :Item( eval(title.isEqual("test",
eval(id.isEqual("test") ) )
then
#actions
end
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira