You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2012/07/05 11:16:20 UTC

svn commit: r1357508 - in /commons/proper/jexl/branches/2.0/src: main/java/org/apache/commons/jexl2/parser/Parser.jjt test/java/org/apache/commons/jexl2/IssuesTest.java

Author: henrib
Date: Thu Jul  5 09:16:20 2012
New Revision: 1357508

URL: http://svn.apache.org/viewvc?rev=1357508&view=rev
Log:
Added range operator (x .. y)  and supporting class (IntegerRange);
Added startsWith/endsWith (=^ and =$)  operators;
Added #NaN to grammar;

Added  charset support in JexlEngine & builder options;
Rafactored code for map and array literals (MapBuilder/ArrayBuilder), allow override in JexlArithmetic to customize behavior;
Updated constant JexlNode determination;
Updated exception handling during parsing,  more precise message and info;

Moved ReadonlyContext to test dir;
Moved some tests from 'issues' to arithmetic;
Updated doc and changes;

Modified:
    commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt
    commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/IssuesTest.java

Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt?rev=1357508&r1=1357507&r2=1357508&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt Thu Jul  5 09:16:20 2012
@@ -228,7 +228,7 @@ void WhileStatement() : {}
 
 
 void ForeachStatement() : {}
-{  
+{
     <FOR> <LPAREN> LValueVar() <COLON>  Expression() <RPAREN> Statement()
 |
     <FOREACH> <LPAREN> LValueVar() <IN>  Expression() <RPAREN> Statement()
@@ -268,8 +268,8 @@ void DeclareVar() #Var :
 }
 
 void LValueVar() #Reference : {}
-{   
-    LOOKAHEAD(1) <VAR> DeclareVar() DotReference() 
+{
+    LOOKAHEAD(1) <VAR> DeclareVar() DotReference()
 |
     LOOKAHEAD(1) Identifier(true) DotReference()
 }
@@ -411,7 +411,7 @@ void Identifier(boolean top) :
     t=<REGISTER> { jjtThis.image = t.image; jjtThis.setRegister(t.image); }
 }
 
-void StringIdentifier() #Identifier : 
+void StringIdentifier() #Identifier :
 {
     Token t;
 }
@@ -568,7 +568,7 @@ void PrimaryExpression() #void : {}
 
 void ArrayAccess() : {}
 {
-    Identifier() (LOOKAHEAD(1) <LBRACKET> Expression() <RBRACKET>)+
+    Identifier(true) (LOOKAHEAD(1) <LBRACKET> Expression() <RBRACKET>)+
 }
 
 void DotReference() #void : {}

Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/IssuesTest.java?rev=1357508&r1=1357507&r2=1357508&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/IssuesTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/IssuesTest.java Thu Jul  5 09:16:20 2012
@@ -1065,4 +1065,50 @@ public class IssuesTest extends JexlTest
         Object o = e.evaluate(jc);
         assertEquals("\r\n", o);
     }
+
+    public void test135() throws Exception {
+        JexlEngine jexl = new JexlEngine();
+        JexlContext jc = new MapContext();
+        Script script;
+        Object result;
+        Map<Integer, Object> foo = new HashMap<Integer, Object>();
+        foo.put(3, 42);
+        jc.set("state", foo);
+
+        script = jexl.createScript("var y = state[3]; y");
+        result = script.execute(jc, foo);
+        assertEquals(42, result);
+
+        jc.set("a", 3);
+        script = jexl.createScript("var y = state[a]; y");
+        result = script.execute(jc, foo);
+        assertEquals(42, result);
+
+        jc.set("a", 2);
+        script = jexl.createScript("var y = state[a + 1]; y");
+        result = script.execute(jc, foo);
+        assertEquals(42, result);
+
+        jc.set("a", 2);
+        jc.set("b", 1);
+        script = jexl.createScript("var y = state[a + b]; y");
+        result = script.execute(jc, foo);
+        assertEquals(42, result);
+
+        script = jexl.createScript("var y = state[3]; y", "state");
+        result = script.execute(null, foo, 3);
+        assertEquals(42, result);
+
+        script = jexl.createScript("var y = state[a]; y", "state", "a");
+        result = script.execute(null, foo, 3);
+        assertEquals(42, result);
+
+        script = jexl.createScript("var y = state[a + 1]; y", "state", "a");
+        result = script.execute(null, foo, 2);
+        assertEquals(42, result);
+
+        script = jexl.createScript("var y = state[a + b]; y", "state", "a", "b");
+        result = script.execute(null, foo, 2, 1);
+        assertEquals(42, result);
+    }
 }