commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject 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/
Date Wed, 02 Sep 2009 10:31:48 GMT
On 02/09/2009, henrib@apache.org <henrib@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


Mime
View raw message