Skip to content

Commit

Permalink
Use the "modern" parser template
Browse files Browse the repository at this point in the history
This restores compatibility with JavaCC/JJTree. When set to classic,
ParserGeneratorCC and JavaCC/JJTree generate different output since
TokenMgrError is not supported by ParserGeneratorCC.
  • Loading branch information
csamak committed Jun 4, 2021
1 parent 3bbdc91 commit 2dce6b9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/main/java/org/apache/commons/jexl3/internal/Engine.java
Expand Up @@ -45,7 +45,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -149,7 +148,7 @@ private UberspectHolder() {}
* The {@link Parser}; when parsing expressions, this engine uses the parser if it
* is not already in use otherwise it will create a new temporary one.
*/
protected final Parser parser = new Parser(new StringReader(";")); //$NON-NLS-1$
protected final Parser parser = new Parser(";"); //$NON-NLS-1$
/**
* The expression max length to hit the cache.
*/
Expand Down Expand Up @@ -873,7 +872,7 @@ protected ASTJexlScript parse(final JexlInfo info, final JexlFeatures parsingf,
}
} else {
// ...otherwise parser was in use, create a new temporary one
final Parser lparser = new Parser(new StringReader(";"));
final Parser lparser = new Parser(";");
script = lparser.parse(ninfo, features, src, scope);
}
if (source != null) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
Expand Up @@ -20,6 +20,7 @@ options
{
MULTI=true;
//STATIC=false;
JAVA_TEMPLATE_TYPE="modern";
VISITOR=true;
NODE_SCOPE_HOOK=true;
NODE_CLASS="JexlNode";
Expand Down Expand Up @@ -59,7 +60,7 @@ public final class Parser extends JexlParser
source = jexlSrc;
pragmas = null;
frame = scope;
ReInit(new java.io.StringReader(jexlSrc));
ReInit(jexlSrc);
ASTJexlScript script = jexlFeatures.supportsScript()? JexlScript(scope) : JexlExpression(scope);
script.jjtSetValue(info.detach());
script.setFeatures(jexlFeatures);
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/apache/commons/jexl3/JexlTest.java
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.commons.jexl3;

import java.io.StringReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
Expand Down Expand Up @@ -692,7 +691,7 @@ public void testAssignment() throws Exception {
jc.set("aString", "Hello");
final Foo foo = new Foo();
jc.set("foo", foo);
final Parser parser = new Parser(new StringReader(";"));
final Parser parser = new Parser(";");
parser.parse(null, new JexlFeatures().register(false), "aString = 'World';", null);

assertExpression(jc, "hello = 'world'", "world");
Expand Down
8 changes: 3 additions & 5 deletions src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
Expand Up @@ -16,8 +16,6 @@
*/
package org.apache.commons.jexl3.parser;

import java.io.StringReader;

import org.apache.commons.jexl3.JexlException;
import org.apache.commons.jexl3.JexlFeatures;
import org.junit.Assert;
Expand All @@ -36,7 +34,7 @@ public ParserTest() {}
*/
@Test
public void testParse() throws Exception {
final Parser parser = new Parser(new StringReader(";"));
final Parser parser = new Parser(";");
JexlNode sn;
sn = parser.parse(null, FEATURES, "foo = 1;", null);
Assert.assertNotNull("parsed node is null", sn);
Expand All @@ -52,7 +50,7 @@ public void testParse() throws Exception {
public void testErrorAssign() throws Exception {
final String[] ops = { "=", "+=", "-=", "/=", "*=", "^=", "&=", "|=" };
for(final String op : ops) {
final Parser parser = new Parser(new StringReader(";"));
final Parser parser = new Parser(";");
try {
final JexlNode sn = parser.parse(null, FEATURES, "foo() "+op+" 1;", null);
Assert.fail("should have failed on invalid assignment " + op);
Expand All @@ -66,7 +64,7 @@ public void testErrorAssign() throws Exception {

@Test
public void testErrorAmbiguous() throws Exception {
final Parser parser = new Parser(new StringReader(";"));
final Parser parser = new Parser(";");
try {
final JexlNode sn = parser.parse(null, FEATURES, "x = 1 y = 5", null);
Assert.fail("should have failed on ambiguous statement");
Expand Down

0 comments on commit 2dce6b9

Please sign in to comment.