[jboss-svn-commits] JBL Code SVN: r34910 - in labs/jbossrules/branches/DRLv6/src: test/java/org/drools/lang and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Aug 26 12:33:18 EDT 2010


Author: dsotty
Date: 2010-08-26 12:33:17 -0400 (Thu, 26 Aug 2010)
New Revision: 34910

Modified:
   labs/jbossrules/branches/DRLv6/src/main/resources/DRLv6Lexer.g
   labs/jbossrules/branches/DRLv6/src/main/resources/DRLv6Parser.g
   labs/jbossrules/branches/DRLv6/src/test/java/org/drools/lang/Rule_Test.java
Log:


Modified: labs/jbossrules/branches/DRLv6/src/main/resources/DRLv6Lexer.g
===================================================================
--- labs/jbossrules/branches/DRLv6/src/main/resources/DRLv6Lexer.g	2010-08-26 16:14:05 UTC (rev 34909)
+++ labs/jbossrules/branches/DRLv6/src/main/resources/DRLv6Lexer.g	2010-08-26 16:33:17 UTC (rev 34910)
@@ -760,9 +760,6 @@
 COMMA : ','
   ;
 
-DOLLAR
-  : '$'
-  ;
       
 DOT : '.'
   ; 

Modified: labs/jbossrules/branches/DRLv6/src/main/resources/DRLv6Parser.g
===================================================================
--- labs/jbossrules/branches/DRLv6/src/main/resources/DRLv6Parser.g	2010-08-26 16:14:05 UTC (rev 34909)
+++ labs/jbossrules/branches/DRLv6/src/main/resources/DRLv6Parser.g	2010-08-26 16:33:17 UTC (rev 34910)
@@ -6,6 +6,7 @@
   tokenVocab = DRLv6Lexer;  
   ASTLabelType=CommonTree;
   backtrack=true;
+  memoize=true;
 }
       
      
@@ -1534,17 +1535,19 @@
 
 
 constraints
-  : positional_constraints
-    -> ^(VT_AND positional_constraints)
-  | slotted_constraints
+  : slotted_constraints
     -> ^(VT_AND slotted_constraints)
+  | positional_constraints
+    -> ^(VT_AND positional_constraints) 
   ;
   
 positional_constraints
- at init{
-  int j = 0;
+scope {
+  int j;
 }
-  : positional_constraint[j++] (COMMA! positional_constraint[j++])* (COMMA! slotted_constraint)*
+  : positional_constraint {$positional_constraints::j++;} 
+  (COMMA! positional_constraint {$positional_constraints::j++;})* 
+  (COMMA! slotted_constraint)*
   ;
     
 slotted_constraints
@@ -1552,9 +1555,9 @@
   ;   
   
   
-positional_constraint[int j]
+positional_constraint
 @init{
-  String idx = ""+j;
+  String idx = ""+$positional_constraints::j;
 }
   : literal  
     -> ^(VT_POSITIONAL_CONST VT_POSITIONAL_INDEX[$start,idx] ^(EQUAL ^(VT_EXPR literal)))   
@@ -1794,18 +1797,41 @@
   
 
 constr_unary
-  : unary_operator^ operator_attributes? constr_unary
-  | constr_atom
-  | LEFT_PAREN! constr_implies RIGHT_PAREN! 
+  : {System.out.println(">>>>>>U1 " + input.LT(-1)  + input.LT(0) + " " + input.LT(1) + " " + input.LT(2) );} 
+    unary_operator^ operator_attributes? constr_unary
+  | {System.out.println(">>>>>>U2 " + input.LT(-1) + input.LT(0) + " " + input.LT(1) + " " + input.LT(2) );}
+    constr_atom
+  | {System.out.println(">>>>>>U3 " + input.LT(-1)  + input.LT(0) + " " + input.LT(1) + " " + input.LT(2) );}
+    LEFT_PAREN! constr_implies RIGHT_PAREN! 
   ;
   
+/*  
 constr_atom
   : left=left_expression rest=restriction_root?
     -> {rest==null}? ^(left_expression)
     -> ^(VT_AND_IMPLICIT left_expression restriction_root)
   ;   
+*/
+ 
+constr_atom
+  :  {System.out.println(">>>>>>U11 " + input.LT(-1)  + input.LT(0) + " " + input.LT(1) + " " + input.LT(2) );}
+      label expr_root restr=restriction_root? 
+      -> {restr==null}? ^(VT_BINDING label ^(VT_EXPR expr_root))
+      -> ^(VT_AND_IMPLICIT
+            ^(VT_BINDING label ^(VT_EXPR expr_root))
+            $restr 
+         )   
+    
+    |  {System.out.println(">>>>>>U12 " + input.LT(-1)  + input.LT(0) + " " + input.LT(1) + " " + input.LT(2) );}
+      expr_root restr=restriction_root? 
+      -> {restr==null}? ^(VT_EXPR expr_root restriction_root?)
+      -> ^(VT_AND_IMPLICIT
+            ^(VT_EXPR expr_root restriction_root?)
+            $restr 
+         )
+         
+  ;    
   
-  
 
   
 restriction_root
@@ -1907,19 +1933,19 @@
     -> ^(inner_quantifier ^(evaluator operator_attributes? right_expression))
   ;
 
-  
+   
 left_expression
-  : label
+  : (VAR COLON) => label
     ( 
-      accessor_path 
-      -> ^(VT_BINDING label accessor_path)
-      | PIPE expr_root PIPE
+      //accessor_path 
+      //-> ^(VT_BINDING label accessor_path)
+      expr_root 
       -> ^(VT_BINDING label ^(VT_EXPR expr_root))
     )
-  | PIPE expr_root PIPE
+  | expr_root 
     -> ^(VT_EXPR expr_root)
-  | accessor_path    
-    -> accessor_path
+  //| accessor_path    
+  //  -> accessor_path
   ;
 
 right_expression

Modified: labs/jbossrules/branches/DRLv6/src/test/java/org/drools/lang/Rule_Test.java
===================================================================
--- labs/jbossrules/branches/DRLv6/src/test/java/org/drools/lang/Rule_Test.java	2010-08-26 16:14:05 UTC (rev 34909)
+++ labs/jbossrules/branches/DRLv6/src/test/java/org/drools/lang/Rule_Test.java	2010-08-26 16:33:17 UTC (rev 34910)
@@ -568,7 +568,7 @@
 				"then end",
 				
 				"rule \"inNest2\" when " + "\n" +
-				" Person( $p : | pets[ #Dog(color == \"red\") ].age * $v1 | == $v2 - 3 ) " +
+				" Person( $p : (pets[ #Dog(color == \"red\") ].age * $v1)  == $v2 - 3 ) " +
 				"then end",
 		};
 		check(rule,testDRL);										
@@ -678,7 +678,26 @@
 	}
 	
 	
+	@Test	
+	public void test_constr_atom() {
+		String rule = "constr_atom";
+		String[] testDRL = new String[] {
+				"$a : age" + "\n" ,
+				
+				"$a : age > 18" + "\n" ,
+				
+				"$a : (2*age) > 18" + "\n" ,
+				
+				" age > 18 " + "\n" ,
+				
+				" 2*age > height*weight" + "\n" ,
+				
+				
+		};
+		check(rule,testDRL);										
+	}
 	
+	
 	@Test	
 	public void test_constr_unary() {
 		String rule = "rule";
@@ -901,11 +920,11 @@
 		String[] testDRL = new String[] {				
 				" $a : age " + "\n",
 				
-				"| (age + 2) * $x + 4 * weight.subField |", 
+				" (age + 2) * $x + 4 * weight.subField ", 
 				
-				"$x : | $z + 4 * weight |",
+				"$x : $z + 4 * weight ",
 				
-				"$a : | (age * 2 + 4 * weight + height) |",								
+				"$a : (age * 2 + 4 * weight + height) ",								
 		};
 		check(rule,testDRL);								
 	}
@@ -917,11 +936,11 @@
 		String rule = "rule";
 		String[] testDRL = new String[] {
 				"rule test when " + "\n" +
-				" Person( $a : age )" + "\n" +
+				" Person( $a: age )" + "\n" +
 				"then end",
 							
 				"rule test when " + "\n" +
-				" Person( ($a : | age * 2 + 4 * weight |  == 18) -> (age < 25 && age > 4)  )" + "\n" +
+				" Person( ($a : ( age * 2 + 4 * weight ) == 18) -> (age < 25 && age > 4)  )" + "\n" +
 				"then end",								
 		};
 		check(rule,testDRL);										
@@ -991,7 +1010,7 @@
 				" then end ",
 				
 				" rule test when " + "\n" +
-				" Person( |2*age()| == 3*height*method(weight + 2 *$k*sqrt(x)) )" + "\n" +
+				" Person( 2*age() == 3*height*method(weight + 2 *$k*sqrt(x)) )" + "\n" +
 				" then end ",								
 		};
 		check(rule,testDRL);										
@@ -1086,9 +1105,9 @@
 				" Person( $a : age ) " + "\n" +
 				"then end",	
 				
-				"rule test when" + "\n" +
-				" Person( $a : | age + 4 | ) " + "\n" +
-				"then end",
+//				"rule test when" + "\n" +
+//				" Person( $a : ( age + 4 ) ) " + "\n" +
+//				"then end",
 		};
 		check(rule,testDRL);
 	}
@@ -1313,7 +1332,7 @@
 	public void test_dle_free_expr() {
 		String rule = "lhs_label_atom_pattern";
 		String[] testDRL = {			
-				"Person( |pets[\"rover\"].age| ==  ($otherAge.someMethod( $x ) + 3 ) / 2 )"
+				"Person( pets[\"rover\"].age ==  ($otherAge.someMethod( $x ) + 3 ) / 2 )"
 		};
 		check(rule,testDRL);										
 	}
@@ -1416,7 +1435,7 @@
 				
 				"acc ( " + "\n" +
 				"  $n : Number() from [1 .. 5], " + "\n" +
-				"  collectList( | $n + 1 | ) " + "\n" +
+				"  collectList( $n + 1  ) " + "\n" +
 				") ",
 				
 				"acc ( " + "\n" +
@@ -1437,13 +1456,13 @@
 				
 				"acc ( " + "\n" +
 				"  $n : Number() from [2,4,8,16,32], " + "\n" +
-				"  collectList( | $n | < 10  ) " + "\n" +
+				"  collectList( $n < 10  ) " + "\n" +
 				") ",
 				
 				"acc ( " + "\n" +
-				"  $n : Number( | intValue / 2 | == 0 ) " + "\n" +
+				"  $n : Number( intValue / 2 == 0 ) " + "\n" +
 				"     from acc( $n2 : Number() from [0 .. 10], " + "\n" +
-				"               collectList( |$n2*$n2| )" + "\n" +
+				"               collectList( $n2*$n2 )" + "\n" +
 				"             ), " + "\n" +
 				"  collectList( $n ) " + "\n" +
 				") ",



More information about the jboss-svn-commits mailing list