JEXL-418: fix try-with-resources grammar; more tests;
diff --git a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
index 4d0202d..8694e3f 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
+++ b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
@@ -444,8 +444,7 @@
pushUnit(jjtThis);
}
<LPAREN>
- (LOOKAHEAD(2) Var() | Identifier(true))
- (LOOKAHEAD(1) <SEMICOL> TryResources())*
+ TryResource() ( LOOKAHEAD(2) <SEMICOL> TryResource() )* (<SEMICOL>)?
<RPAREN>
Block()
{
@@ -453,6 +452,11 @@
}
}
+void TryResource() #void : {}
+{
+(LOOKAHEAD(2) Var() | Identifier(true))
+}
+
void WhileStatement() : {}
{
<WHILE> <LPAREN> Expression() <RPAREN> { loopCount += 1; } (LOOKAHEAD(1) Block() | StatementNoVar()) { loopCount -= 1; }
diff --git a/src/test/java/org/apache/commons/jexl3/TryCatchFinallyTest.java b/src/test/java/org/apache/commons/jexl3/TryCatchFinallyTest.java
index ea75980..9aada2c 100644
--- a/src/test/java/org/apache/commons/jexl3/TryCatchFinallyTest.java
+++ b/src/test/java/org/apache/commons/jexl3/TryCatchFinallyTest.java
@@ -45,6 +45,30 @@
Object result = script.execute(null);
Assert.assertEquals(42, result);
}
+ @Test
+ public void testForm0x2b() {
+ String src = "try(let x = 19, y = 23) { x + y; } finally { 169; }";
+ JexlScript script = JEXL.createScript(src);
+ Assert.assertNotNull(script);
+ Object result = script.execute(null);
+ Assert.assertEquals(42, result);
+ }
+ @Test
+ public void testForm0x2c() {
+ String src = "try(const x = 19; let y = 23; ) { x + y; } finally { 169; }";
+ JexlScript script = JEXL.createScript(src);
+ Assert.assertNotNull(script);
+ Object result = script.execute(null);
+ Assert.assertEquals(42, result);
+ }
+ @Test
+ public void testForm0x2d() {
+ String src = "try(var x = 19; const y = 23;) { x + y; } finally { 169; }";
+ JexlScript script = JEXL.createScript(src);
+ Assert.assertNotNull(script);
+ Object result = script.execute(null);
+ Assert.assertEquals(42, result);
+ }
@Test
public void testThrow0x2a() {