commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject [commons-jexl] branch master updated: JEXL-307: parser internal state clean up Task #JEXL-307 - Variable redeclaration option
Date Fri, 01 Nov 2019 10:17:33 GMT
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 32bfdc9  JEXL-307: parser internal state clean up Task #JEXL-307 - Variable redeclaration
option
32bfdc9 is described below

commit 32bfdc913223aac1282e9b64fdf198a1e4561dac
Author: Henri Biestro <hbiestro@gmail.com>
AuthorDate: Fri Nov 1 11:17:16 2019 +0100

    JEXL-307: parser internal state clean up
    Task #JEXL-307 - Variable redeclaration option
---
 .../apache/commons/jexl3/parser/JexlParser.java    | 26 ++++++++++++----------
 .../java/org/apache/commons/jexl3/LexicalTest.java | 15 +++++++++++++
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java b/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
index e557e7f..4aa2c05 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
@@ -98,25 +98,25 @@ public abstract class JexlParser extends StringParser {
          * @return true if declaration was successful, false if symbol was already declared
          */
         boolean declareSymbol(int symbol);
-        
+
         /**
          * Checks whether a symbol is declared in this lexical unit.
          * @param symbol the symbol
          * @return true if declared, false otherwise
          */
         boolean hasSymbol(int symbol);
-        
+
         /**
-         * @return the number of local variables declared in this unit 
+         * @return the number of local variables declared in this unit
          */
         int getSymbolCount();
-        
+
         /**
          * Clears this unit.
          */
         void clearUnit();
     }
-    
+
     /**
      * Cleanup.
      * @param features the feature set to restore if any
@@ -130,6 +130,8 @@ public abstract class JexlParser extends StringParser {
         loopCounts.clear();
         loopCount = 0;
         blocks.clear();
+        block = null;
+        mergeBlock = false;
     }
     /**
      * Utility function to create '.' separated string from a list of string.
@@ -170,7 +172,7 @@ public abstract class JexlParser extends StringParser {
         }
         return msg;
     }
-    
+
     /**
      * Internal, for debug purpose only.
      * @param registers whether register syntax is recognized by this parser
@@ -252,13 +254,13 @@ public abstract class JexlParser extends StringParser {
         } else if (mergeBlock) {
             mergeBlock = false;
             return;
-        } 
+        }
         if (block != null) {
             blocks.push(block);
         }
         block = unit;
     }
-    
+
     /**
      * Pushes a block as new lexical unit.
      * @param unit the lexical unit
@@ -272,7 +274,7 @@ public abstract class JexlParser extends StringParser {
      * @param unit restores the previous lexical scope
      */
     protected void popUnit(LexicalUnit unit) {
-        if (block == unit){ 
+        if (block == unit){
             if (!blocks.isEmpty()) {
                 block = blocks.pop();
             } else {
@@ -281,7 +283,7 @@ public abstract class JexlParser extends StringParser {
             //unit.clearUnit();
         }
     }
-    
+
     /**
      * Checks whether an identifier is a local variable or argument, ie a symbol, stored
in a register.
      * @param identifier the identifier
@@ -317,11 +319,11 @@ public abstract class JexlParser extends StringParser {
         }
         return true;
     }
-    
+
     /**
      * Declares a symbol.
      * @param symbol the symbol index
-     * @return true if symbol can be declared in lexical scope, false (error) 
+     * @return true if symbol can be declared in lexical scope, false (error)
      * if it is already declared
      */
     private boolean declareSymbol(int symbol) {
diff --git a/src/test/java/org/apache/commons/jexl3/LexicalTest.java b/src/test/java/org/apache/commons/jexl3/LexicalTest.java
index 5cf9bfd..0a6d7cf 100644
--- a/src/test/java/org/apache/commons/jexl3/LexicalTest.java
+++ b/src/test/java/org/apache/commons/jexl3/LexicalTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.jexl3;
 
+import java.util.Set;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -240,4 +241,18 @@ public class LexicalTest {
             String ww = xany.toString();
         }
     }
+
+    @Test
+    public void testLexical3() throws Exception {
+        String str = "var s = {}; for (var i : [1]) s.add(i); s";
+        JexlEngine jexl = new JexlBuilder().strict(true).create();
+        JexlScript e = jexl.createScript(str);
+        JexlContext jc = new MapContext();
+        Object o = e.execute(jc);
+        Assert.assertEquals(Boolean.TRUE, ((Set)o).contains(1));
+
+        e = jexl.createScript(str);
+        o = e.execute(jc);
+        Assert.assertEquals(Boolean.TRUE, ((Set)o).contains(1));
+    }
 }


Mime
View raw message