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/05/06 16:20:55 UTC

[commons-jexl] 02/05: JEXL-369: add fat-arrow to syntax

This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch JEXL-369
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit a2e1aaa30725e677ed7c74748462e67900df75c6
Author: henrib <he...@apache.org>
AuthorDate: Tue May 3 18:52:01 2022 +0200

    JEXL-369: add fat-arrow to syntax
---
 .../org/apache/commons/jexl3/parser/ASTLet.java    | 35 ++++++++++++++++++++++
 .../apache/commons/jexl3/parser/JexlParser.java    |  4 +--
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTLet.java b/src/main/java/org/apache/commons/jexl3/parser/ASTLet.java
new file mode 100644
index 00000000..687ad610
--- /dev/null
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTLet.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jexl3.parser;
+
+/**
+ * Declares a local variable.
+ */
+public class ASTLet extends ASTIdentifier {
+    public ASTLet(final int id) {
+        super(id);
+    }
+
+    public ASTLet(final Parser p, final int id) {
+        super(p, id);
+    }
+
+    @Override
+    public Object jjtAccept(final ParserVisitor visitor, final Object data) {
+        return visitor.visit(this, data);
+    }
+}
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 ed171ba1..5151cbac 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
@@ -382,7 +382,7 @@ public abstract class JexlParser extends StringParser {
      * @param variable the identifier used to declare
      * @param token      the variable name toekn
      */
-    protected void declareVariable(final ASTVar variable, final Token token) {
+    protected void declareVariable(final ASTVar variable, final Token token, boolean lexical) {
         final String name = token.image;
         if (!allowVariable(name)) {
             throwFeatureException(JexlFeatures.LOCAL_VAR, token);
@@ -397,7 +397,7 @@ public abstract class JexlParser extends StringParser {
         }
         // lexical feature error
         if (!declareSymbol(symbol)) {
-            if (getFeatures().isLexical()) {
+            if (lexical || getFeatures().isLexical()) {
                 throw new JexlException(variable, name + ": variable is already declared");
             }
             variable.setRedefined(true);