Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Dfile.encoding=UTF-8
31 changes: 27 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,44 @@
</configuration>
</plugin>
<plugin>
<groupId>com.helger.maven</groupId>
<artifactId>ph-javacc-maven-plugin</artifactId>
<version>4.1.5</version>
<!-- JJTree 8.1.0 writes the characters that the grammar declares as unicode escapes in the platform
encoding, where they may be lost: .mvn/jvm.config makes that encoding UTF-8. -->
<groupId>org.javacc.plugin</groupId>
<artifactId>javacc-maven-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>jexl-jjtree</id>
<configuration>
<sourceDirectory>${basedir}/src/main/java/org/apache/commons/jexl3/parser</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
<jjtreeCmdLineArgs>
<arg>-CODE_GENERATOR="Java"</arg>
<arg>-NODE_DIRECTORY="${basedir}/src/main/java"</arg>
<arg>-NODE_PACKAGE="org.apache.commons.jexl3.parser"</arg>
<arg>-JJTREE_OUTPUT_DIRECTORY="${project.build.directory}/generated-sources/jjtree"</arg>
</jjtreeCmdLineArgs>
<javaccCmdLineArgs>
<arg>-CODE_GENERATOR="Java"</arg>
<arg>-OUTPUT_DIRECTORY="${project.build.directory}/generated-sources/java"</arg>
</javaccCmdLineArgs>
</configuration>
<goals>
<goal>jjtree-javacc</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.javacc</groupId>
<artifactId>core</artifactId>
<version>8.1.0</version>
</dependency>
<dependency>
<groupId>org.javacc.generator</groupId>
<artifactId>java</artifactId>
<version>8.1.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
Expand Down
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<!-- ADD -->
<action dev="henrib" due-to="Claude" type="add" issue="JEXL-474">Declare antish variable names at parse time through JexlFeatures.antishTest(Predicate), disabling runtime antish resolution; add JexlFeatures.namePatterns(Collection).</action>
<!-- UPDATE -->
<action type="update" dev="henrib" due-to="Claude" issue="JEXL-445">Generate the parser with JavaCC 8.1.0.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 105 to 107.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">[test] Bump org.apache.commons:commons-lang3 from 3.21.0 to 3.22.0.</action>
</release>
Expand Down
3 changes: 3 additions & 0 deletions src/main/config/findbugs-exclude-filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<Match>
<Class name="org.apache.commons.jexl3.parser.TokenMgrError"/>
</Match>
<Match>
<Class name="org.apache.commons.jexl3.parser.StreamProvider"/>
</Match>
<Match>
<Class name="org.apache.commons.jexl3.parser.SimpleNode"/>
</Match>
Expand Down
90 changes: 90 additions & 0 deletions src/main/java/org/apache/commons/jexl3/parser/Node.java
Original file line number Diff line number Diff line change
@@ -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.
* <p>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.</p>
*/
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 &ge; 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);
}
10 changes: 7 additions & 3 deletions src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
options
{
MULTI=true;
SINGLE_TREE_FILE=false;
STATIC=false;
JAVA_TEMPLATE_TYPE="modern";
VISITOR=true;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -145,7 +145,7 @@ TOKEN_MGR_DECLS : {
| "\r"
| "\f"
| <"##" (~["\n","\r"])* ("\n" | "\r" | "\r\n")? >
| <"/*" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/">
| <"/*" (~["*"] | ("*")+ ~["*","/"])* ("*")+ "/">
| <"//" (~["\n","\r"])* ("\n" | "\r" | "\r\n")? >
}

Expand Down Expand Up @@ -370,14 +370,18 @@ TOKEN_MGR_DECLS : {
<FLOAT_LITERAL:
(["0"-"9"])+ "." (["0"-"9"])+ (<FLT_SFX>)?
| (["0"-"9"])+ (".")? (<FLT_SFX>)
| "." (["0"-"9"])+ (<FLT_SFX>)
| "#NaN"
>
| <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+>
| <#FLT_CLS : ["f","F","d","D","b","B"]>
| <#FLT_SFX : <EXPONENT> (<FLT_CLS>)? | <FLT_CLS> >
}

<*> TOKEN : /* A float starting with a dot: in all states as the dot token is, mapped to FLOAT_LITERAL */
{
< DOT_FLOAT_LITERAL: "." (["0"-"9"])+ (<FLT_SFX>) > { matchedToken.kind = FLOAT_LITERAL; } : DEFAULT
}

<*> TOKEN :
{
< STRING_LITERAL:
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/apache/commons/jexl3/ExpressionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ 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");
}

@Test
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());
Expand All @@ -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");
Expand Down
Loading