[ https://issues.apache.org/jira/browse/JEXL-303?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16846530#comment-16846530 ]
Dmitri Blinov commented on JEXL-303: ------------------------------------ Sorry, but it has turned out the solution I proposed does not take into account nested blocks in {{StatementLookahead()}}. Now I think I understand the real reason for the initial issue. The problem is with {{ExpressionStatement()}} grammar which may have trailing semicolon. In the failing case {{if (0) 1 else 2;}} that last semicolon was treated as part of {{ExpressionStatement()}} of {{else}} part, not the statement separator, thats why the {{LOOKAHEAD(<LCURLY> Statement() <SEMICOL>) Block()}} didn't work. Anyway, I think I have more robust grammar proposal for this. First, we need to change {{SetLiteral}} lookahead from {code:java} void PrimaryExpression() #void : {} { ... LOOKAHEAD( <LCURLY> Expression()) SetLiteral() ... } {code} to {code:java} void PrimaryExpression() #void : {} { ... LOOKAHEAD( <LCURLY> Expression() (<COMMA> | <RCURLY>)) SetLiteral() ... } {code} Second, we can change the Statement() grammar to this {code:java} void Statement() #void : {} { <SEMICOL> | LOOKAHEAD(<ANNOTATION>) AnnotatedStatement() | LOOKAHEAD(Expression()) ExpressionStatement() | Block() | IfStatement() | ForeachStatement() | WhileStatement() | DoWhileStatement() | ReturnStatement() | Continue() | Break() | Var() | Pragma() } {code} So that we don't need {{StatementLookahead()}} anymore... > Block syntax is broken > ---------------------- > > Key: JEXL-303 > URL: https://issues.apache.org/jira/browse/JEXL-303 > Project: Commons JEXL > Issue Type: Bug > Affects Versions: 3.1 > Reporter: Dmitri Blinov > Assignee: Henri Biestro > Priority: Major > Fix For: 3.2 > > > The following script fails to parse correctly > {code} > {if (0) 1 else 2; var x = 1;} > {code} > while the following script parses perfectly > {code} > {var x = 1; if (0) 1 else 2;} > {code} > Tested with > {code} > @Test > public void testOuterBlock() throws Exception { > JexlScript e = JEXL.createScript("{if (0) 1 else 2; var x = 1;}"); > JexlContext jc = new MapContext(); > Object o = e.execute(jc); > Assert.assertEquals("Block result is wrong", 1, o); > } > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)