diff --git a/.mvn/jvm.config b/.mvn/jvm.config new file mode 100644 index 000000000..7fecadb38 --- /dev/null +++ b/.mvn/jvm.config @@ -0,0 +1 @@ +-Dfile.encoding=UTF-8 diff --git a/pom.xml b/pom.xml index b6154d92f..23c7796d6 100644 --- a/pom.xml +++ b/pom.xml @@ -173,21 +173,44 @@ - com.helger.maven - ph-javacc-maven-plugin - 4.1.5 + + org.javacc.plugin + javacc-maven-plugin + 3.8.0 jexl-jjtree ${basedir}/src/main/java/org/apache/commons/jexl3/parser - ${project.build.directory}/generated-sources/java + + -CODE_GENERATOR="Java" + -NODE_DIRECTORY="${basedir}/src/main/java" + -NODE_PACKAGE="org.apache.commons.jexl3.parser" + -JJTREE_OUTPUT_DIRECTORY="${project.build.directory}/generated-sources/jjtree" + + + -CODE_GENERATOR="Java" + -OUTPUT_DIRECTORY="${project.build.directory}/generated-sources/java" + jjtree-javacc + + + org.javacc + core + 8.1.0 + + + org.javacc.generator + java + 8.1.0 + + maven-antrun-plugin diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 603885a8a..2023fc782 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -33,6 +33,7 @@ Declare antish variable names at parse time through JexlFeatures.antishTest(Predicate), disabling runtime antish resolution; add JexlFeatures.namePatterns(Collection). + Generate the parser with JavaCC 8.1.0. Bump org.apache.commons:commons-parent from 105 to 107. [test] Bump org.apache.commons:commons-lang3 from 3.21.0 to 3.22.0. diff --git a/src/main/config/findbugs-exclude-filter.xml b/src/main/config/findbugs-exclude-filter.xml index d0005c7c4..07c1fbfa6 100644 --- a/src/main/config/findbugs-exclude-filter.xml +++ b/src/main/config/findbugs-exclude-filter.xml @@ -52,6 +52,9 @@ + + + diff --git a/src/main/java/org/apache/commons/jexl3/parser/Node.java b/src/main/java/org/apache/commons/jexl3/parser/Node.java new file mode 100644 index 000000000..e1c1cb2de --- /dev/null +++ b/src/main/java/org/apache/commons/jexl3/parser/Node.java @@ -0,0 +1,90 @@ +/* + * 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 + * + * https://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; + +import java.io.Serializable; + +/** + * The interface all AST nodes implement. + *

It provides the basic machinery for constructing the parent and child relationships between nodes. + * This is the interface JJTree expects; it is written by hand so the nodes do not depend on + * the base class the parser generator would otherwise create.

+ */ +public interface Node extends Serializable { + /** + * Called after the node has been made the current node; child nodes can now be added to it. + */ + void jjtOpen(); + + /** + * Called after all the child nodes have been added. + */ + void jjtClose(); + + /** + * Sets the parent node of this node. + * + * @param n the parent node + */ + void jjtSetParent(Node n); + + /** + * Gets the parent node of this node. + * + * @return the parent node + */ + Node jjtGetParent(); + + /** + * Adds a node to the list of children of this node. + * + * @param n the node to add as a child + * @param i the zero-based index where to add the child + */ + void jjtAddChild(Node n, int i); + + /** + * Gets a child node; children are numbered from zero, left to right. + * + * @param i the zero-based child index + * @return the child node + */ + Node jjtGetChild(int i); + + /** + * Gets the number of children of this node. + * + * @return the number of children, always ≥ 0 + */ + int jjtGetNumChildren(); + + /** + * Gets the node identifier, one of the {@link ParserTreeConstants}. + * + * @return the node identifier + */ + int getId(); + + /** + * Accepts a visitor. + * + * @param visitor the visitor + * @param data contextual data + * @return the result of the visit + */ + Object jjtAccept(ParserVisitor visitor, Object data); +} 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 a0e56ae90..b2fc2598d 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt +++ b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt @@ -19,6 +19,7 @@ options { MULTI=true; + SINGLE_TREE_FILE=false; STATIC=false; JAVA_TEMPLATE_TYPE="modern"; VISITOR=true; @@ -117,7 +118,6 @@ public final class Parser extends JexlParser : "invalid number literal"; throw new JexlException.Parsing(ji, msg).clean(); } finally { - token_source.defaultLexState = DEFAULT; token_source.ignoredTokens = Collections.emptySet(); cleanup(previous); jjtree.reset(); @@ -145,7 +145,7 @@ TOKEN_MGR_DECLS : { | "\r" | "\f" | <"##" (~["\n","\r"])* ("\n" | "\r" | "\r\n")? > - | <"/*" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/"> + | <"/*" (~["*"] | ("*")+ ~["*","/"])* ("*")+ "/"> | <"//" (~["\n","\r"])* ("\n" | "\r" | "\r\n")? > } @@ -370,7 +370,6 @@ TOKEN_MGR_DECLS : { )? | (["0"-"9"])+ (".")? () - | "." (["0"-"9"])+ () | "#NaN" > | <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+> @@ -378,6 +377,11 @@ TOKEN_MGR_DECLS : { | <#FLT_SFX : ()? | > } +<*> TOKEN : /* A float starting with a dot: in all states as the dot token is, mapped to FLOAT_LITERAL */ +{ + < DOT_FLOAT_LITERAL: "." (["0"-"9"])+ () > { matchedToken.kind = FLOAT_LITERAL; } : DEFAULT +} + <*> TOKEN : { < STRING_LITERAL: diff --git a/src/test/java/org/apache/commons/jexl3/ExpressionsTest.java b/src/test/java/org/apache/commons/jexl3/ExpressionsTest.java index b90e784bb..ae48d58fe 100644 --- a/src/test/java/org/apache/commons/jexl3/ExpressionsTest.java +++ b/src/test/java/org/apache/commons/jexl3/ExpressionsTest.java @@ -37,6 +37,7 @@ import java.util.Set; import org.apache.commons.jexl3.parser.Parser; +import org.apache.commons.jexl3.parser.StringProvider; import org.junit.jupiter.api.Test; /** @@ -143,7 +144,7 @@ void testAssignment() { jc.set("aString", "Hello"); final Foo foo = new Foo(); jc.set("foo", foo); - final Parser parser = new Parser(";"); + final Parser parser = new Parser(new StringProvider(";")); parser.parse(null, new JexlFeatures().register(false), "aString = 'World';", null); assertExpression(jc, "hello = 'world'", "world"); diff --git a/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java b/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java index 6e777a02e..71e14275e 100644 --- a/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java +++ b/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java @@ -73,7 +73,7 @@ void testUnicodeEscape() { @Test void testErrorAmbiguous() throws Exception { - final Parser parser = new Parser(";"); + final Parser parser = new Parser(new StringProvider(";")); assertThrows(JexlException.Ambiguous.class, () -> parser.parse(null, FEATURES, "x = 1 y = 5", null), "should have failed on ambiguous statement"); } @@ -81,7 +81,7 @@ void testErrorAmbiguous() throws Exception { void testErrorAssign() throws Exception { final String[] ops = { "=", "+=", "-=", "/=", "*=", "^=", "&=", "|=" }; for (final String op : ops) { - final Parser parser = new Parser(";"); + final Parser parser = new Parser(new StringProvider(";")); final JexlException.Parsing xparse = assertThrows(JexlException.Parsing.class, () -> parser.parse(null, FEATURES, "foo() " + op + " 1;", null), () -> "should have failed on invalid assignment " + op); assertNotNull(xparse.getDetail()); @@ -105,7 +105,7 @@ void testIdentifierEscape() { */ @Test void testParse() throws Exception { - final Parser parser = new Parser(";"); + final Parser parser = new Parser(new StringProvider(";")); JexlNode sn; sn = parser.parse(null, FEATURES, "foo = 1;", null); assertNotNull(sn, "parsed node is null");