You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Carlos Durán <ca...@gmail.com> on 2008/11/15 12:36:20 UTC

Bug in jexl library

Hello,
I have checked that there is a conflict(in jexl library) when a method is
called "foreach",for example.If method's name is the same than the beginning
of a statement defined("foraech" is already defined but you can define other
like "forall","exists"..) the parser doesnt recognize that method,the
statement defined is expected.

This is the grammar.

void Statement() #void :
{}
{
  ";"
|
  Block()
|
  LOOKAHEAD( Reference() ";" ) ReferenceExpression()
|
  LOOKAHEAD( PrimaryExpression() "=" ) StatementExpression()
|
  LOOKAHEAD( Expression() ";" ) ExpressionExpression()
|
  Expression()
|
  IfStatement()
|
 * ForeachStatement()*
|
  WhileStatement()

}



void ForeachStatement() :
{}
{
  "foreach" "(" Reference() "in"  Reference() ")" Statement()
}


---------------------------------------------------------------------------------------------

If I do something like this:

String jexlExp = "foreach(x)";  //there is no problem if the name is not the
same than something defined in the grammar(for example "foreac(x)")
Script script = ScriptFactory.createScript(jexlExp);


the result is:

Exception in thread "main" org.apache.commons.jexl.parser.ParseException:
Encountered ")" at line 1, column 10.
Was expecting one of:
    "in" ...
    "(" ...
    "[" ...
    "." ...

    at
org.apache.commons.jexl.parser.Parser.generateParseException(Parser.java:3786)
    at
org.apache.commons.jexl.parser.Parser.jj_consume_token(Parser.java:3663)
    at
org.apache.commons.jexl.parser.Parser.ForeachStatement(Parser.java:1729)
    at org.apache.commons.jexl.parser.Parser.Statement(Parser.java:1546)
    at org.apache.commons.jexl.parser.Parser.JexlScript(Parser.java:60)
    at org.apache.commons.jexl.parser.Parser.parse(Parser.java:18)
    at
org.apache.commons.jexl.ScriptFactory.createNewScript(ScriptFactory.java:162)
    at
org.apache.commons.jexl.ScriptFactory.createScript(ScriptFactory.java:99)
    at parser.pruebillas.main(pruebillas.java:134)



I think this is connected to Tokenizer Lookahead, but I dont know well what
is the best way to solve the problem,I need help.

Thanks.

Re: Bug in jexl library

Posted by Rahul Akolkar <ra...@gmail.com>.
On Sat, Nov 15, 2008 at 6:36 AM, Carlos Durán <ca...@gmail.com> wrote:
> Hello,
> I have checked that there is a conflict(in jexl library) when a method is
> called "foreach",for example.If method's name is the same than the beginning
> of a statement defined("foraech" is already defined but you can define other
> like "forall","exists"..) the parser doesnt recognize that method,the
> statement defined is expected.
>
<snip/>

'foreach' is a keyword in JEXL, best to avoid using it as a method or
variable name.

-Rahul


> This is the grammar.
>
> void Statement() #void :
> {}
> {
>  ";"
> |
>  Block()
> |
>  LOOKAHEAD( Reference() ";" ) ReferenceExpression()
> |
>  LOOKAHEAD( PrimaryExpression() "=" ) StatementExpression()
> |
>  LOOKAHEAD( Expression() ";" ) ExpressionExpression()
> |
>  Expression()
> |
>  IfStatement()
> |
>  * ForeachStatement()*
> |
>  WhileStatement()
>
> }
>
>
>
> void ForeachStatement() :
> {}
> {
>  "foreach" "(" Reference() "in"  Reference() ")" Statement()
> }
>
>
> ---------------------------------------------------------------------------------------------
>
> If I do something like this:
>
> String jexlExp = "foreach(x)";  //there is no problem if the name is not the
> same than something defined in the grammar(for example "foreac(x)")
> Script script = ScriptFactory.createScript(jexlExp);
>
>
> the result is:
>
> Exception in thread "main" org.apache.commons.jexl.parser.ParseException:
> Encountered ")" at line 1, column 10.
> Was expecting one of:
>    "in" ...
>    "(" ...
>    "[" ...
>    "." ...
>
>    at
> org.apache.commons.jexl.parser.Parser.generateParseException(Parser.java:3786)
>    at
> org.apache.commons.jexl.parser.Parser.jj_consume_token(Parser.java:3663)
>    at
> org.apache.commons.jexl.parser.Parser.ForeachStatement(Parser.java:1729)
>    at org.apache.commons.jexl.parser.Parser.Statement(Parser.java:1546)
>    at org.apache.commons.jexl.parser.Parser.JexlScript(Parser.java:60)
>    at org.apache.commons.jexl.parser.Parser.parse(Parser.java:18)
>    at
> org.apache.commons.jexl.ScriptFactory.createNewScript(ScriptFactory.java:162)
>    at
> org.apache.commons.jexl.ScriptFactory.createScript(ScriptFactory.java:99)
>    at parser.pruebillas.main(pruebillas.java:134)
>
>
>
> I think this is connected to Tokenizer Lookahead, but I dont know well what
> is the best way to solve the problem,I need help.
>
> Thanks.
>

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