commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1068459 - in /commons/proper/jexl/trunk/src: main/java/org/apache/commons/jexl2/ main/java/org/apache/commons/jexl2/parser/ test/java/org/apache/commons/jexl2/
Date Tue, 08 Feb 2011 16:06:11 GMT
Author: henrib
Date: Tue Feb  8 16:06:10 2011
New Revision: 1068459

URL: http://svn.apache.org/viewvc?rev=1068459&view=rev
Log:
JEXL-107; modified grammar and added debugger/interpreter support

Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Debugger.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Debugger.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Debugger.java?rev=1068459&r1=1068458&r2=1068459&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Debugger.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Debugger.java Tue Feb
 8 16:06:10 2011
@@ -56,6 +56,7 @@ import org.apache.commons.jexl2.parser.A
 import org.apache.commons.jexl2.parser.ASTNullLiteral;
 import org.apache.commons.jexl2.parser.ASTOrNode;
 import org.apache.commons.jexl2.parser.ASTReference;
+import org.apache.commons.jexl2.parser.ASTReferenceExpression;
 import org.apache.commons.jexl2.parser.ASTSizeFunction;
 import org.apache.commons.jexl2.parser.ASTSizeMethod;
 import org.apache.commons.jexl2.parser.ASTStringLiteral;
@@ -638,4 +639,11 @@ final class Debugger implements ParserVi
     public Object visit(ASTAmbiguous node, Object data) {
         throw new UnsupportedOperationException("unexpected type of node");
     }
+
+    public Object visit(ASTReferenceExpression node, Object data) {
+        builder.append("(");
+        accept(node.jjtGetChild(0), data);
+        builder.append(")");
+        return data;
+    }
 }
\ No newline at end of file

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java?rev=1068459&r1=1068458&r2=1068459&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java Tue
Feb  8 16:06:10 2011
@@ -25,6 +25,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import org.apache.commons.jexl2.parser.ASTReferenceExpression;
 
 import org.apache.commons.jexl2.parser.SimpleNode;
 import org.apache.commons.logging.Log;
@@ -1066,6 +1067,10 @@ public class Interpreter implements Pars
         return result;
     }
 
+    public Object visit(ASTReferenceExpression node, Object data) {
+        return node.jjtGetChild(0).jjtAccept(this, data);
+    }
+    
     /**
      * Check if a null evaluated expression is protected by a ternary expression.
      * The rationale is that the ternary / elvis expressions are meant for the user to explictly
take
@@ -1364,4 +1369,5 @@ public class Interpreter implements Pars
     public Object visit(ASTAmbiguous node, Object data) {
         throw new UnsupportedOperationException("unexpected type of node");
     }
+
 }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt?rev=1068459&r1=1068458&r2=1068459&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt Tue
Feb  8 16:06:10 2011
@@ -130,7 +130,7 @@ PARSER_END(Parser)
     | < SEMICOL : ";" >
     | < COLON : ":" >
     | < COMMA : "," >
-    | <DOT : "." >
+    | < DOT : "." >
 }
 
 <*> TOKEN : { /* CONDITIONALS */
@@ -257,15 +257,12 @@ void ForeachStatement() : {}
 
 void Expression() #void : {}
 {
-    LOOKAHEAD( Reference() <assign> )  Assignment()
-|
-    ConditionalExpression()
+    ConditionalExpression() ( <assign> Expression() #Assignment(2) )?
 }
 
-
 void Assignment() #Assignment(2) : {}
 {
-    Reference() <assign> Expression()
+    ConditionalExpression() <assign> Expression()
 }
 
 /***************************************
@@ -528,12 +525,8 @@ void Constructor() #ConstructorNode() : 
 
 void PrimaryExpression() #void : {}
 {
-  Literal()
-|
   LOOKAHEAD(3)  Reference()
 |
-  LOOKAHEAD( <LPAREN> ) <LPAREN> Expression() <RPAREN>
-|
   LOOKAHEAD( <EMPTY> ) EmptyFunction()
 |
   LOOKAHEAD( <SIZE> ) SizeFunction()
@@ -543,9 +536,10 @@ void PrimaryExpression() #void : {}
   LOOKAHEAD( <LCURLY> MapEntry() ) MapLiteral()
 |
   LOOKAHEAD( <LBRACKET> Expression() ) ArrayLiteral()
+|
+  Literal()
 }
 
-
 void ArrayAccess() : {}
 {
     Identifier() (LOOKAHEAD(2) <LBRACKET> Expression() <RBRACKET>)+
@@ -570,7 +564,8 @@ void DotReference() #void : {}
 
 void Reference() : {}
 {
-  ( LOOKAHEAD(<NEW>) Constructor()
+  (
+   LOOKAHEAD(<NEW>) Constructor()
 |
    LOOKAHEAD(Identifier() <LBRACKET> ) ArrayAccess()
 |
@@ -578,10 +573,20 @@ void Reference() : {}
 |
    LOOKAHEAD(Identifier() <LPAREN>) Method()
 |
-   Identifier()
-|
    LOOKAHEAD(<LCURLY>) MapLiteral()
 |
-   LOOKAHEAD(<LBRACKET>) ArrayLiteral() ) DotReference()
+   LOOKAHEAD(<LBRACKET>) ArrayLiteral()
+|
+   LOOKAHEAD( <LPAREN> Expression() ) ReferenceExpression()
+|
+   StringLiteral()
+|
+   Identifier()
+  )  DotReference()
+}
+
+void ReferenceExpression() : {}
+{
+    <LPAREN> Expression() <RPAREN>
 }
 

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java?rev=1068459&r1=1068458&r2=1068459&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java Tue Feb
 8 16:06:10 2011
@@ -452,4 +452,33 @@ public class IssuesTest extends JexlTest
             //ok  to fail
         }
     }
+
+    public void test107() throws Exception {
+        JexlContext context = new MapContext();
+        context.set("Q4", "Q4");
+        JexlEngine jexl = new JexlEngine();
+        Expression expr;
+        Object value;
+        expr = jexl.createExpression("'Q4'.toLowerCase()");
+        value = expr.evaluate(context);
+        assertEquals("q4", value);
+        expr = jexl.createExpression("(Q4).toLowerCase()");
+        value = expr.evaluate(context);
+        assertEquals("q4", value);
+        expr = jexl.createExpression("(4).toString()");
+        value = expr.evaluate(context);
+        assertEquals("4", value);
+        value = jexl.createExpression("(1 + 3).toString()");
+        value = expr.evaluate(context);
+        assertEquals("4", value);
+        expr = jexl.createExpression("({ 'Q4' : 'Q4'}).get('Q4').toLowerCase()");
+        value = expr.evaluate(context);
+        assertEquals("q4", value);
+        expr = jexl.createExpression("{ 'Q4' : 'Q4'}.get('Q4').toLowerCase()");
+        value = expr.evaluate(context);
+        assertEquals("q4", value);
+        expr = jexl.createExpression("({ 'Q4' : 'Q4'}).get('Q4').toLowerCase()");
+        value = expr.evaluate(context);
+        assertEquals("q4", value);
+    }
 }



Mime
View raw message