[jboss-jira] [JBoss JIRA] Closed: (JBRULES-855) Jboss regex does not support all escape sequence
Edson Tirelli (JIRA)
jira-events at lists.jboss.org
Wed May 23 17:08:08 EDT 2007
[ http://jira.jboss.com/jira/browse/JBRULES-855?page=all ]
Edson Tirelli closed JBRULES-855.
---------------------------------
Resolution: Done
Support to escapes added to the grammar.
I hope I did not forgot anyone... :)
STRING
: ('"' ( EscapeSequence | ~('\\'|'"') )* '"')
| ('\'' ( EscapeSequence | ~('\\'|'\'') )* '\'')
;
fragment
HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;
fragment
EscapeSequence
: '\\' ('b'|'B'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\'|'.'|'o'|
'x'|'a'|'e'|'c'|'d'|'D'|'s'|'S'|'w'|'W'|'p'|'A'|
'G'|'Z'|'z'|'Q'|'E'|'*'|'['|']'|'('|')'|'$'|'^'|
'{'|'}'|'?'|'+'|'-'|'&'|'|')
| UnicodeEscape
| OctalEscape
;
fragment
OctalEscape
: '\\' ('0'..'3') ('0'..'7') ('0'..'7')
| '\\' ('0'..'7') ('0'..'7')
| '\\' ('0'..'7')
;
fragment
UnicodeEscape
: '\\' 'u' HexDigit HexDigit HexDigit HexDigit
;
> Jboss regex does not support all escape sequence
> ------------------------------------------------
>
> Key: JBRULES-855
> URL: http://jira.jboss.com/jira/browse/JBRULES-855
> Project: JBoss Rules
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Affects Versions: 4.0.0.MR2
> Environment: Windows XP
> Reporter: Krishnan Sivaramakrishna Iyer
> Assigned To: Edson Tirelli
> Fix For: 4.0.0.MR3
>
>
> Currently, if there exists a string such as
> final String version = "version 12.2";
> and you try to match it against the following regex
> version\\s*\\d+\\.\\d+.*
> It will not match. This is because of the following problem
> <tirelli> newbie: found the problem
> <tirelli> it is a bug
> <tirelli> but there is a workaround
> <tirelli> problem is the current DRL grammar does not allow to escape things like \s and \d
> <tirelli> EscapeSequence
> <tirelli> : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\'|'.')
> <tirelli> those are the only accepted symbols to be escaped today
> <tirelli> may I ask you plz to open a JIRA requesting support to all regexp symbols? I will fix that for 4.0 final
> <tirelli> meanwhile, you can do this to work:
> <tirelli> line matches "version[ \t]*[0-9]+\.[0-9]+.*"
> Thanks,
> Krishnan
> Test case :
> #created on: May 16, 2007
> package com.sample
>
> #list any import classes here.
> import com.sample.Device;
> import com.sample.Line;
>
> #declare any global variables here
>
> rule "Check for Cisco Version Exp"
>
> when
> Line ( line matches "version\\s*\\d+\\.\\d+\\.*" )
> then
> System.out.println("There exists a line that matches cisco version expression.");
> end
>
> ====
> package com.sample;
>
> import java.lang.String;
>
> /**
> * @author kiyer
> *
> */
> public class Line {
>
> private String line;
>
> public Line(String line) {
> setLine(line);
> }
>
> /**
> * @return the line
> */
> public String getLine() {
> return line;
> }
>
> /**
> * @param line the line to set
> */
> public void setLine(String line) {
> this.line = line;
> }
>
> }
> ===
>
> package com.sample;
>
> import java.io.BufferedReader;
> import java.io.FileReader;
> import java.io.InputStreamReader;
> import java.io.Reader;
>
> import org.drools.RuleBase;
> import org.drools.RuleBaseFactory;
> import org.drools.compiler.PackageBuilder;
> import org.drools.StatefulSession;
> import org.drools.rule.Package;
>
> /**
> * This is a sample file to launch a rule package from a rule source file.
> */
> public class CfiTest {
>
> public static final void main(String[] args) {
> try {
>
> //load up the rulebase
> final RuleBase ruleBase = readRule();
> final StatefulSession session = ruleBase.newStatefulSession();
>
> Line lineObj = new Line("version 12.2");
> session.assertObject(lineObj);
> session.fireAllRules();
> session.dispose();
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
>
> /**
> * Please note that this is the "low level" rule assembly API.
> */
> private static RuleBase readRule() throws Exception {
> //read in the source
> final Reader source = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/CfiTest.drl" ) );
>
> //optionally read in the DSL (if you are using it).
> //Reader dsl = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/mylang.dsl" ) );
>
> //Use package builder to build up a rule package.
> //An alternative lower level class called "DrlParser" can also be used...
>
> final PackageBuilder builder = new PackageBuilder();
>
> //this wil parse and compile in one step
> //NOTE: There are 2 methods here, the one argument one is for normal DRL.
> builder.addPackageFromDrl( source );
>
> //Use the following instead of above if you are using a DSL:
> //builder.addPackageFromDrl( source, dsl );
>
> //get the compiled package (which is serializable)
> final Package pkg = builder.getPackage();
>
> //add the package to a rulebase (deploy the rule package).
> final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
> ruleBase.addPackage( pkg );
> System.out.println("Successfully loaded the rules file.");
> return ruleBase;
> }
>
> }
--
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