[jboss-svn-commits] JBL Code SVN: r14451 - in labs/jbossrules/trunk: documentation/manual/en/Chapter-Rule_Language and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Aug 22 13:49:28 EDT 2007


Author: tirelli
Date: 2007-08-22 13:49:27 -0400 (Wed, 22 Aug 2007)
New Revision: 14451

Modified:
   labs/jbossrules/trunk/documentation/manual/en/Chapter-Release_Notes/Section-Upgrade_tips.xml
   labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-DSL.xml
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultDSLMappingEntryTest.java
Log:
JBRULES-1055: improving docs and adding unit tests

Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Release_Notes/Section-Upgrade_tips.xml
===================================================================
--- labs/jbossrules/trunk/documentation/manual/en/Chapter-Release_Notes/Section-Upgrade_tips.xml	2007-08-22 17:07:39 UTC (rev 14450)
+++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Release_Notes/Section-Upgrade_tips.xml	2007-08-22 17:49:27 UTC (rev 14451)
@@ -171,16 +171,11 @@
   </section>
 
   <section>
-     
-
     <title>Drools Update Tool</title>
 
-     
-
     <para>The Drools Update tools is a simple program to help with the upgrade
     of DRL files from Drools 3.0.x to Drools 4.0.x.</para>
 
-
     <para>At this point, its main objective is to upgrade the memory action
     calls from 3.0.x to 4.0.x, but expect it to grow over the next few weeks
     covering additional scenarios. It is important to note that it does not
@@ -189,41 +184,63 @@
     and as so, it is a safe tool to use for upgrade large sets of rule
     files.</para>
 
-
     <para>The drools update tool can be found as a maven project in the
     following source repository
     http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/experimental/drools-update/
-    you just need to check it out, and execute the maven clean install action with the
-    project's pom.xml file. After resolve all the class path dependencies you
-    are able to run the toll with the following command:</para>
+    you just need to check it out, and execute the maven clean install action
+    with the project's pom.xml file. After resolve all the class path
+    dependencies you are able to run the toll with the following
+    command:</para>
 
     <programlisting>java -cp $CLASSPATH org.drools.tools.update.UpdateTool -f &lt;filemask&gt; [-d &lt;basedir&gt;] [-s &lt;sufix&gt;]</programlisting>
 
-	<para> 
-		The program parameters are very easy to understand as following.
-		
-	 <itemizedlist>
-	      <listitem>
-	        <para>-h,--help, Shows a very simple list the usage help</para>
-	      </listitem>
+    <para>The program parameters are very easy to understand as following.
+    <itemizedlist>
+        <listitem>
+          <para>-h,--help, Shows a very simple list the usage help</para>
+        </listitem>
 
-	      <listitem>
-	        <para>-d your source base directory</para>
-	      </listitem>
-	
-	      <listitem>
-	        <para>-f pattern for the files to be updated. The format is the same as used by ANT:
-		       * = single file, directory
-               ** = any level of subdirectories
-               EXAMPLE:
-               src/main/resources/**/*.drl = matches all DRL files inside any subdirectory of /src/main/resources
-		 	</para>
-	      </listitem>
-	
-	      <listitem>
-	        <para> -s,--sufix    the sufix to be added to all updated files</para>
-	      </listitem>
-	 </itemizedlist>
-	</para>
+        <listitem>
+          <para>-d your source base directory</para>
+        </listitem>
+
+        <listitem>
+          <para>-f pattern for the files to be updated. The format is the same
+          as used by ANT: * = single file, directory ** = any level of
+          subdirectories EXAMPLE: src/main/resources/**/*.drl = matches all
+          DRL files inside any subdirectory of /src/main/resources</para>
+        </listitem>
+
+        <listitem>
+          <para>-s,--sufix the sufix to be added to all updated files</para>
+        </listitem>
+      </itemizedlist></para>
   </section>
-</section>
+
+  <section>
+    <title>DSL Grammars in Drools 4.0</title>
+
+    <para>It is important to note that the DSL template engine was rewritten
+    from scratch to improve flexibility. One of the new features of DSL
+    grammars is the support to Regular Expressions. This way, now you can
+    write your mappings using regexp to have additional flexibility, as
+    explained in the DSL chapter. Although, now you have to escape characters
+    with regexp meaning. Example: if previously you had a matching
+    like:</para>
+
+    <example>
+      <title>Drools 3.0.x mapping</title>
+
+      <programlisting>[when][]- the {attr} is in [ {values} ]={attr} in ( {values} )</programlisting>
+    </example>
+
+    <para>Now, you need to escape '[' and ']' characters, as they have special
+    meaning in regexps. So, the same mapping in Drools 4.0 would be:</para>
+
+    <example>
+      <title>Drools 4.0.x mapping with escaped characters</title>
+
+      <programlisting>[when][]- the {attr} is in \[ {values} \]={attr} in ( {values} )</programlisting>
+    </example>
+  </section>
+</section>
\ No newline at end of file

Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-DSL.xml
===================================================================
--- labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-DSL.xml	2007-08-22 17:07:39 UTC (rev 14450)
+++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-DSL.xml	2007-08-22 17:49:27 UTC (rev 14451)
@@ -25,10 +25,10 @@
     <para>DSLs have no impact on the rules at runtime, they are just a
     parse/compile time feature.</para>
 
-    <para>Note that Drools 3 DSLs are quite different from Drools 2 XML based
+    <para>Note that Drools 4 DSLs are quite different from Drools 2 XML based
     DSLs. It is still possible to do Drools 2 style XML languages - if you
-    require this, then take a look at the Drools 3 XML rule language, and
-    consider using XSLT to map from your XML language to the Drools 3 XML
+    require this, then take a look at the Drools 4 XML rule language, and
+    consider using XSLT to map from your XML language to the Drools 4 XML
     language.</para>
   </section>
 
@@ -45,17 +45,17 @@
           <primary>DSL</primary>
         </indexterm> mapping</title>
 
-      <programlisting>[when]This is {something}=Something(something=={something})</programlisting>
+      <programlisting>[when][]This is {something}=Something(something=={something})</programlisting>
     </example>
 
-    <para>Referring to the above example, the [when] refers to the scope of the
-    expression: ie does it belong on the LHS or the RHS of a rule. The part
-    after the [scope] is the expression that you use in the rule (typically a
-    natural language expression, but it doesn't have to be). The part on the
-    right of the "=" is the mapping into the rule language (of course the form
-    of this depends on if you are talking about the RHS or the LHS - if its
-    the LHS, then its the normal LHS syntax, if its the RHS then its fragments
-    of java code for instance).</para>
+    <para>Referring to the above example, the [when] refers to the scope of
+    the expression: ie does it belong on the LHS or the RHS of a rule. The
+    part after the [scope] is the expression that you use in the rule
+    (typically a natural language expression, but it doesn't have to be). The
+    part on the right of the "=" is the mapping into the rule language (of
+    course the form of this depends on if you are talking about the RHS or the
+    LHS - if its the LHS, then its the normal LHS syntax, if its the RHS then
+    its fragments of java code for instance).</para>
 
     <para>The parser will take the expression you specify, and extract the
     values that match where the {something} (named Tokens) appear in the
@@ -71,10 +71,11 @@
     DSL expressions to generate a target expression. The best way around this
     is to make sure that the {tokens} are enclosed with characters or words.
     This means that the parser will scan along the sentence, and pluck out the
-    value BETWEEN the characters (in the example below they are double-quotes).
-    Note that the characters that surround the token are not included in when
-    interpolating, just the contents between them (rather then all the way to
-    the end of the line, as would otherwise be the case).</para>
+    value BETWEEN the characters (in the example below they are
+    double-quotes). Note that the characters that surround the token are not
+    included in when interpolating, just the contents between them (rather
+    then all the way to the end of the line, as would otherwise be the
+    case).</para>
 
     <para>As a rule of thumb, use quotes for textual data that a rule editor
     may want to enter. You can also wrap words around the {tokens} to make
@@ -203,7 +204,7 @@
     <para><emphasis role="bold">IMPORTANT:</emphasis> There must be an space
     between the "-" (dash) and the constraint mappings.</para>
 
-    <para> You can then write rules with conditions like the following:
+    <para>You can then write rules with conditions like the following:
     <programlisting>There is a Cheese with
         - age is less than 42
         - type is 'stilton'</programlisting> The parser will pick up the "-"

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java	2007-08-22 17:07:39 UTC (rev 14450)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java	2007-08-22 17:49:27 UTC (rev 14451)
@@ -109,7 +109,12 @@
                     section = DSLMappingEntry.CONSEQUENCE;
                 }
 
-                final DSLMappingEntry.MetaData metadata = new DefaultDSLEntryMetaData( metadataStr );
+                DSLMappingEntry.MetaData metadata;
+                if( metadataStr == null || metadataStr.length() == 0 ) {
+                    metadata = DSLMappingEntry.EMPTY_METADATA;
+                } else {
+                    metadata = new DefaultDSLEntryMetaData( metadataStr );
+                }
 
                 final DSLMappingEntry entry = new DefaultDSLMappingEntry( section,
                                                                     metadata,

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java	2007-08-22 17:07:39 UTC (rev 14450)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DSLMappingFileTest.java	2007-08-22 17:49:27 UTC (rev 14451)
@@ -55,11 +55,56 @@
 
             assertEquals( 1,
                           this.file.getMapping().getEntries().size() );
+
+            DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get( 0 );
+
+            assertEquals( DSLMappingEntry.CONDITION,
+                          entry.getSection() );
+            assertEquals( DSLMappingEntry.EMPTY_METADATA,
+                          entry.getMetaData() );
+            assertEquals( "ATTRIBUTE \"{attr}\" IS IN [{list}]",
+                          entry.getMappingKey() );
+            assertEquals( "Attribute( {attr} in ({list}) )",
+                          entry.getMappingValue() );
+
         } catch ( final IOException e ) {
             e.printStackTrace();
             fail( "Should not raise exception " );
         }
+    }
 
+    public void testParseFileWithEscaptedBrackets() {
+        String file = "[when][]ATTRIBUTE \"{attr}\" IS IN \\[{list}\\]=Attribute( {attr} in ({list}) )";
+        try {
+            final Reader reader = new StringReader( file );
+            this.file = new DSLMappingFile();
+
+            final boolean parsingResult = this.file.parseAndLoad( reader );
+            reader.close();
+
+            assertTrue( this.file.getErrors().toString(),
+                        parsingResult );
+            assertTrue( this.file.getErrors().isEmpty() );
+
+            assertEquals( 1,
+                          this.file.getMapping().getEntries().size() );
+
+            DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get( 0 );
+
+            assertEquals( DSLMappingEntry.CONDITION,
+                          entry.getSection() );
+            assertEquals( DSLMappingEntry.EMPTY_METADATA,
+                          entry.getMetaData() );
+            assertEquals( "ATTRIBUTE \"{attr}\" IS IN \\[{list}\\]",
+                          entry.getMappingKey() );
+            assertEquals( "Attribute( {attr} in ({list}) )",
+                          entry.getMappingValue() );
+
+        } catch ( final IOException e ) {
+            e.printStackTrace();
+            fail( "Should not raise exception " );
+        }
+
     }
 
 }

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultDSLMappingEntryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultDSLMappingEntryTest.java	2007-08-22 17:07:39 UTC (rev 14450)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/lang/dsl/DefaultDSLMappingEntryTest.java	2007-08-22 17:49:27 UTC (rev 14451)
@@ -194,4 +194,18 @@
                       result );
     }
     
+    public void testExpandWithBrackets() {
+        final String inputKey = "attr {attr_name} is in \\[ {values} \\]";
+        final String inputValue = "{attr_name} in ( {values} )";
+
+        this.entry = new DefaultDSLMappingEntry( DSLMappingEntry.CONDITION,
+                                            null,
+                                            inputKey,
+                                            inputValue );
+
+        String result = this.entry.getKeyPattern().matcher( "attr name is in [ 'Edson', 'Bob' ]" ).replaceAll( this.entry.getValuePattern() );
+        assertEquals( result,
+                      "name in ( 'Edson', 'Bob' )",
+                      result );
+    }
 }




More information about the jboss-svn-commits mailing list