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 2009/09/02 12:23:03 UTC

svn commit: r810445 - in /commons/proper/jexl/branches/2.0/src: main/java/org/apache/commons/jexl/ main/java/org/apache/commons/jexl/parser/ test/java/org/apache/commons/jexl/

Author: henrib
Date: Wed Sep  2 10:23:03 2009
New Revision: 810445

URL: http://svn.apache.org/viewvc?rev=810445&view=rev
Log:
JEXL-90: fix in Parser, enforce 2 expressions are separated by a semi-colon (';') in StatementExpression. 

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

Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Debugger.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Debugger.java?rev=810445&r1=810444&r2=810445&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Debugger.java (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Debugger.java Wed Sep  2 10:23:03 2009
@@ -19,6 +19,7 @@
 import org.apache.commons.jexl.parser.ASTAdditiveNode;
 import org.apache.commons.jexl.parser.ASTAdditiveOperator;
 import org.apache.commons.jexl.parser.ASTAndNode;
+import org.apache.commons.jexl.parser.ASTAmbiguous;
 import org.apache.commons.jexl.parser.ASTArrayAccess;
 import org.apache.commons.jexl.parser.ASTArrayLiteral;
 import org.apache.commons.jexl.parser.ASTAssignment;
@@ -617,4 +618,9 @@
     public Object visit(SimpleNode node, Object data) {
         throw new UnsupportedOperationException("unexpected type of node");
     }
+
+    /** {@inheritDoc} */
+    public Object visit(ASTAmbiguous node, Object data) {
+        throw new UnsupportedOperationException("unexpected type of node");
+    }
 }
\ No newline at end of file

Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java?rev=810445&r1=810444&r2=810445&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java Wed Sep  2 10:23:03 2009
@@ -33,6 +33,7 @@
 import org.apache.commons.jexl.parser.ASTAdditiveNode;
 import org.apache.commons.jexl.parser.ASTAdditiveOperator;
 import org.apache.commons.jexl.parser.ASTAndNode;
+import org.apache.commons.jexl.parser.ASTAmbiguous;
 import org.apache.commons.jexl.parser.ASTArrayAccess;
 import org.apache.commons.jexl.parser.ASTArrayLiteral;
 import org.apache.commons.jexl.parser.ASTAssignment;
@@ -1287,4 +1288,14 @@
     public Object visit(SimpleNode node, Object data) {
         throw new UnsupportedOperationException("Not supported yet.");
     }
+
+    /**
+     * Unused, should throw in Parser.
+     * @param node a node
+     * @param data the data
+     * @return does not return
+     */
+    public Object visit(ASTAmbiguous node, Object data) {
+        throw new UnsupportedOperationException("unexpected type of node");
+    }
 }

Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt?rev=810445&r1=810444&r2=810445&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt Wed Sep  2 10:23:03 2009
@@ -29,6 +29,7 @@
    MULTI=true;
    STATIC=false;
    VISITOR=true;
+   NODE_SCOPE_HOOK=true;
    NODE_CLASS="JexlNode";
    UNICODE_INPUT=true;
 }
@@ -55,6 +56,22 @@
         tree.value = info;
         return tree;
     }
+
+    void jjtreeOpenNodeScope(Node n) {}
+    void jjtreeCloseNodeScope(Node n) throws ParseException {
+      if (n instanceof ASTAmbiguous && n.jjtGetNumChildren() > 0) {
+          Token tok = this.getToken(0);
+          StringBuilder strb = new StringBuilder("Ambiguous statement ");
+          if (tok != null) {
+              strb.append("@");
+              strb.append(tok.beginLine);
+              strb.append(":");
+              strb.append(tok.beginColumn);
+          }
+          strb.append(", missing ';' between expressions");
+         throw new ParseException(strb.toString());
+      }
+    }
 }
 
 PARSER_END(Parser)
@@ -113,7 +130,7 @@
 
 void ExpressionStatement() #void : {}
 {
-    Expression() (LOOKAHEAD(2) ";")?
+    Expression() (LOOKAHEAD(1) Expression() #Ambiguous())* (LOOKAHEAD(2) ";")?
 }
 
 

Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java?rev=810445&r1=810444&r2=810445&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java Wed Sep  2 10:23:03 2009
@@ -16,6 +16,7 @@
  */
 
 package org.apache.commons.jexl;
+import org.apache.commons.jexl.parser.ParseException;
 import java.util.Map;
 
 /**
@@ -26,7 +27,7 @@
     @Override
     public void setUp() throws Exception {
         // ensure jul logging is only error to avoid warning in silent mode
-        java.util.logging.Logger.getLogger(JexlEngine.class.getName()).setLevel(java.util.logging.Level.SEVERE);
+        //java.util.logging.Logger.getLogger(JexlEngine.class.getName()).setLevel(java.util.logging.Level.SEVERE);
     }
     
     // JEXL-49: blocks not parsed (fixed)
@@ -238,4 +239,31 @@
         }
 
     }
+
+    // JEXL-90: ';' is necessary between expressions
+    public void test90() throws Exception {
+        JexlContext ctxt = JexlHelper.createContext();
+        JexlEngine jexl = new JexlEngine();
+        jexl.setSilent(false);
+        jexl.setLenient(false);
+        String[] exprs = {
+            "a=3 b=4",
+            "while(a) while(a)",
+            "1 2",
+            "if (true) 2; 3 {}"
+        };
+        for(int s = 0; s < exprs.length; ++s) {
+            boolean fail = true;
+            try {
+                Script e = jexl.createScript(exprs[s]);
+            }
+            catch(ParseException xany) {
+                // expected to fail in parse
+                fail = false;
+            }
+            if (fail) {
+                fail(exprs[s] + ": Should have failed in parse");
+            }
+        }
+    }
 }
\ No newline at end of file



Re: svn commit: r810445 - in /commons/proper/jexl/branches/2.0/src: main/java/org/apache/commons/jexl/ main/java/org/apache/commons/jexl/parser/ test/java/org/apache/commons/jexl/

Posted by sebb <se...@gmail.com>.
On 02/09/2009, Henrib <hb...@gmail.com> wrote:
>
>
>
>  sebb-2-2 wrote:
>  >
>  >
>  > Seems like a complicated way of fixing the problem; I would have
>  > thought it was simpler to ensure that multiple statements are
>  > separated by ";" instead.
>  >
>  > i.e. a script consists of
>  >
>  > Statement ( ";" Statement )*
>  >
>  > So long as "Statement" includes a null statement, this would allow for
>  > a trailing ";".
>  >
>  > But I don't know JavaCC all that well.
>  >
>
>
> Did you try fixing the grammar using what you suggest ? If you actually have
>  implemented it in a simpler way - versus thought about one - please, share
>  the code so we can all learn; I've tried many solutions and did not come up
>  with the current code easily.

No, I've not tried fixing it. I may try later.

>  Besides, the fix forces 2 expressions to be separated by ';' in a statement
>  - which is not equivalent to separate all statements with ';' (';'  needed
>  between blocks?).

Not sure I follow what you mean by this - can you provide an example
of a script which used to be parsed incorrectly?

>
>
>  --
>  View this message in context: http://www.nabble.com/svn-commit%3A-r810445---in--commons-proper-jexl-branches-2.0-src%3A-main-java-org-apache-commons-jexl--main-java-org-apache-commons-jexl-parser--test-java-org-apache-commons-jexl--tp25255016p25259429.html
>  Sent from the Commons - Dev mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>  For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r810445 - in /commons/proper/jexl/branches/2.0/src: main/java/org/apache/commons/jexl/ main/java/org/apache/commons/jexl/parser/ test/java/org/apache/commons/jexl/

Posted by Henrib <hb...@gmail.com>.


sebb-2-2 wrote:
> 
> 
> Seems like a complicated way of fixing the problem; I would have
> thought it was simpler to ensure that multiple statements are
> separated by ";" instead.
> 
> i.e. a script consists of
> 
> Statement ( ";" Statement )*
> 
> So long as "Statement" includes a null statement, this would allow for
> a trailing ";".
> 
> But I don't know JavaCC all that well.
> 

Did you try fixing the grammar using what you suggest ? If you actually have
implemented it in a simpler way - versus thought about one - please, share
the code so we can all learn; I've tried many solutions and did not come up
with the current code easily.
Besides, the fix forces 2 expressions to be separated by ';' in a statement
- which is not equivalent to separate all statements with ';' (';'  needed
between blocks?).


-- 
View this message in context: http://www.nabble.com/svn-commit%3A-r810445---in--commons-proper-jexl-branches-2.0-src%3A-main-java-org-apache-commons-jexl--main-java-org-apache-commons-jexl-parser--test-java-org-apache-commons-jexl--tp25255016p25259429.html
Sent from the Commons - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r810445 - in /commons/proper/jexl/branches/2.0/src: main/java/org/apache/commons/jexl/ main/java/org/apache/commons/jexl/parser/ test/java/org/apache/commons/jexl/

Posted by sebb <se...@gmail.com>.
On 02/09/2009, henrib@apache.org <he...@apache.org> wrote:
> Author: henrib
>  Date: Wed Sep  2 10:23:03 2009
>  New Revision: 810445
>
>  URL: http://svn.apache.org/viewvc?rev=810445&view=rev
>  Log:
>  JEXL-90: fix in Parser, enforce 2 expressions are separated by a semi-colon (';') in StatementExpression.
>
>  Modified:
>     commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Debugger.java
>     commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java
>     commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt
>     commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java
>
>  Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Debugger.java
>  URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Debugger.java?rev=810445&r1=810444&r2=810445&view=diff
>  ==============================================================================
>  --- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Debugger.java (original)
>  +++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Debugger.java Wed Sep  2 10:23:03 2009
>  @@ -19,6 +19,7 @@
>   import org.apache.commons.jexl.parser.ASTAdditiveNode;
>   import org.apache.commons.jexl.parser.ASTAdditiveOperator;
>   import org.apache.commons.jexl.parser.ASTAndNode;
>  +import org.apache.commons.jexl.parser.ASTAmbiguous;
>   import org.apache.commons.jexl.parser.ASTArrayAccess;
>   import org.apache.commons.jexl.parser.ASTArrayLiteral;
>   import org.apache.commons.jexl.parser.ASTAssignment;
>  @@ -617,4 +618,9 @@
>      public Object visit(SimpleNode node, Object data) {
>          throw new UnsupportedOperationException("unexpected type of node");
>      }
>  +
>  +    /** {@inheritDoc} */
>  +    public Object visit(ASTAmbiguous node, Object data) {
>  +        throw new UnsupportedOperationException("unexpected type of node");
>  +    }
>   }
>  \ No newline at end of file
>
>  Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java
>  URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java?rev=810445&r1=810444&r2=810445&view=diff
>  ==============================================================================
>  --- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java (original)
>  +++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/Interpreter.java Wed Sep  2 10:23:03 2009
>  @@ -33,6 +33,7 @@
>   import org.apache.commons.jexl.parser.ASTAdditiveNode;
>   import org.apache.commons.jexl.parser.ASTAdditiveOperator;
>   import org.apache.commons.jexl.parser.ASTAndNode;
>  +import org.apache.commons.jexl.parser.ASTAmbiguous;
>   import org.apache.commons.jexl.parser.ASTArrayAccess;
>   import org.apache.commons.jexl.parser.ASTArrayLiteral;
>   import org.apache.commons.jexl.parser.ASTAssignment;
>  @@ -1287,4 +1288,14 @@
>      public Object visit(SimpleNode node, Object data) {
>          throw new UnsupportedOperationException("Not supported yet.");
>      }
>  +
>  +    /**
>  +     * Unused, should throw in Parser.
>  +     * @param node a node
>  +     * @param data the data
>  +     * @return does not return
>  +     */
>  +    public Object visit(ASTAmbiguous node, Object data) {
>  +        throw new UnsupportedOperationException("unexpected type of node");
>  +    }
>   }
>
>  Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt
>  URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt?rev=810445&r1=810444&r2=810445&view=diff
>  ==============================================================================
>  --- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt (original)
>  +++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt Wed Sep  2 10:23:03 2009
>  @@ -29,6 +29,7 @@
>     MULTI=true;
>     STATIC=false;
>     VISITOR=true;
>  +   NODE_SCOPE_HOOK=true;
>     NODE_CLASS="JexlNode";
>     UNICODE_INPUT=true;
>   }
>  @@ -55,6 +56,22 @@
>          tree.value = info;
>          return tree;
>      }
>  +
>  +    void jjtreeOpenNodeScope(Node n) {}
>  +    void jjtreeCloseNodeScope(Node n) throws ParseException {
>  +      if (n instanceof ASTAmbiguous && n.jjtGetNumChildren() > 0) {
>  +          Token tok = this.getToken(0);
>  +          StringBuilder strb = new StringBuilder("Ambiguous statement ");
>  +          if (tok != null) {
>  +              strb.append("@");
>  +              strb.append(tok.beginLine);
>  +              strb.append(":");
>  +              strb.append(tok.beginColumn);
>  +          }
>  +          strb.append(", missing ';' between expressions");
>  +         throw new ParseException(strb.toString());
>  +      }
>  +    }
>   }
>
>   PARSER_END(Parser)
>  @@ -113,7 +130,7 @@
>
>   void ExpressionStatement() #void : {}
>   {
>  -    Expression() (LOOKAHEAD(2) ";")?
>  +    Expression() (LOOKAHEAD(1) Expression() #Ambiguous())* (LOOKAHEAD(2) ";")?
>   }
>

Seems like a complicated way of fixing the problem; I would have
thought it was simpler to ensure that multiple statements are
separated by ";" instead.

i.e. a script consists of

Statement ( ";" Statement )*

So long as "Statement" includes a null statement, this would allow for
a trailing ";".

But I don't know JavaCC all that well.

>
>  Modified: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java
>  URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java?rev=810445&r1=810444&r2=810445&view=diff
>  ==============================================================================
>  --- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java (original)
>  +++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/IssuesTest.java Wed Sep  2 10:23:03 2009
>  @@ -16,6 +16,7 @@
>   */
>
>   package org.apache.commons.jexl;
>  +import org.apache.commons.jexl.parser.ParseException;
>   import java.util.Map;
>
>   /**
>  @@ -26,7 +27,7 @@
>      @Override
>      public void setUp() throws Exception {
>          // ensure jul logging is only error to avoid warning in silent mode
>  -        java.util.logging.Logger.getLogger(JexlEngine.class.getName()).setLevel(java.util.logging.Level.SEVERE);
>  +        //java.util.logging.Logger.getLogger(JexlEngine.class.getName()).setLevel(java.util.logging.Level.SEVERE);
>      }
>
>      // JEXL-49: blocks not parsed (fixed)
>  @@ -238,4 +239,31 @@
>          }
>
>      }
>  +
>  +    // JEXL-90: ';' is necessary between expressions
>  +    public void test90() throws Exception {
>  +        JexlContext ctxt = JexlHelper.createContext();
>  +        JexlEngine jexl = new JexlEngine();
>  +        jexl.setSilent(false);
>  +        jexl.setLenient(false);
>  +        String[] exprs = {
>  +            "a=3 b=4",
>  +            "while(a) while(a)",
>  +            "1 2",
>  +            "if (true) 2; 3 {}"
>  +        };
>  +        for(int s = 0; s < exprs.length; ++s) {
>  +            boolean fail = true;
>  +            try {
>  +                Script e = jexl.createScript(exprs[s]);
>  +            }
>  +            catch(ParseException xany) {
>  +                // expected to fail in parse
>  +                fail = false;
>  +            }
>  +            if (fail) {
>  +                fail(exprs[s] + ": Should have failed in parse");
>  +            }
>  +        }
>  +    }
>   }
>  \ No newline at end of file
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org