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 2022/06/12 15:40:30 UTC
[commons-jexl] branch master updated: JEXL-369: allow multiple variable declarations in var/let/const (let x=0, y=1;)
This is an automated email from the ASF dual-hosted git repository.
henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
The following commit(s) were added to refs/heads/master by this push:
new 898b71fc JEXL-369: allow multiple variable declarations in var/let/const (let x=0, y=1;)
898b71fc is described below
commit 898b71fcfa4b5e48af58a9a96b1ed6b490c2b641
Author: henrib <he...@apache.org>
AuthorDate: Sun Jun 12 17:40:24 2022 +0200
JEXL-369: allow multiple variable declarations in var/let/const (let x=0, y=1;)
---
.../org/apache/commons/jexl3/parser/Parser.jjt | 21 ++++++++++++++++++---
.../java/org/apache/commons/jexl3/LexicalTest.java | 22 ++++++++++++++++++++++
2 files changed, 40 insertions(+), 3 deletions(-)
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 f8072a9f..18ad3509 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
+++ b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
@@ -466,11 +466,26 @@ void ForEachVar() #Reference : {}
void Var() #void : {}
{
- <VAR> DeclareVar(false, false) (LOOKAHEAD(1) <assign> Expression() #Assignment(2))?
+ <VAR> DefineVar() (<COMMA> DefineVar())*
|
- <LET> DeclareVar(true, false) (LOOKAHEAD(1) <assign> Expression() #Assignment(2))?
+ <LET> DefineLet() (<COMMA> DefineLet())*
|
- <CONST> DeclareVar(true, true) <assign> Expression() #Assignment(2)
+ <CONST> DefineConst() (<COMMA> DefineConst())*
+}
+
+ void DefineVar() #void : {}
+ {
+ DeclareVar(false, false) (LOOKAHEAD(1) <assign> Expression() #Assignment(2))?
+ }
+
+void DefineLet() #void : {}
+{
+ DeclareVar(true, false) (LOOKAHEAD(1) <assign> Expression() #Assignment(2))?
+}
+
+void DefineConst() #void : {}
+{
+ DeclareVar(true, true) <assign> Expression() #Assignment(2)
}
void DeclareVar(boolean lexical, boolean constant) #Var :
diff --git a/src/test/java/org/apache/commons/jexl3/LexicalTest.java b/src/test/java/org/apache/commons/jexl3/LexicalTest.java
index 90f7a9b8..e5faaef9 100644
--- a/src/test/java/org/apache/commons/jexl3/LexicalTest.java
+++ b/src/test/java/org/apache/commons/jexl3/LexicalTest.java
@@ -919,6 +919,28 @@ public class LexicalTest {
}
}
+ @Test public void testManyLet() {
+ String text = "let x = 1, y = 41, z; x + y";
+ JexlEngine jexl = new JexlBuilder().safe(true).create();
+ JexlScript script = jexl.createScript(text);
+ Object result = script.execute(null);
+ Assert.assertEquals(42, result);
+ String s0 = script.getParsedText();
+ String s1 = script.getSourceText();
+ Assert.assertNotEquals(s0, s1);
+ }
+
+ @Test public void testManyConst() {
+ String text = "const x = 1, y = 41; x + y";
+ JexlEngine jexl = new JexlBuilder().safe(true).create();
+ JexlScript script = jexl.createScript(text);
+ Object result = script.execute(null);
+ Assert.assertEquals(42, result);
+ String s0 = script.getParsedText();
+ String s1 = script.getSourceText();
+ Assert.assertNotEquals(s0, s1);
+ }
+
@Test
public void testConst2a() {
final JexlFeatures f = new JexlFeatures();