Apache Solr open-source search software
LUCENE-6417: Cleanup ANTLR code generator
Uwe Schindlercc45d912f7f1
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 2980499f589..77fe9f19cfc 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -64,7 +64,7 @@ OptimizationsOther* LUCENE-6417: Upgrade ANTLR used in expressions module to version 4.5.- (Jack Conradson via Uwe Schindler)+ (Jack Conradson, Uwe Schindler)======================= Lucene 5.3.0 =======================diff --git a/lucene/expressions/build.xml b/lucene/expressions/build.xmlindex 70d589ada05..a6c81e6d2d3 100644--- a/lucene/expressions/build.xml+++ b/lucene/expressions/build.xml@@ -21,9 +21,6 @@Dynamically computed values to sort/facet/search on based on a pluggable grammar.</description>- <!-- some files for testing that do not have license headers -->- <property name="rat.excludes" value="**/*.tokens"/>-<import file="../module-build.xml"/><path id="classpath">@@ -81,22 +78,19 @@<attribute name="package" /><attribute name="grammar" /><sequential>- <!-- delete parser and lexer so files will be generated -->- <delete>- <fileset dir="src/java/org/apache/lucene/expressions/@{package}">- <include name="@{grammar}Lexer.java" />- <include name="@{grammar}Parser.java" />- </fileset>- </delete><local name="grammar.path"/>- <local name="grammar.matchpath"/>- <local name="-grammar.relative.path"/>- <local name="grammar.relative.path"/>+ <patternset id="grammar.@{grammar}.patternset">+ <include name="@{grammar}Lexer.java" />+ <include name="@{grammar}Parser.java" />+ <include name="@{grammar}Visitor.java" />+ <include name="@{grammar}BaseVisitor.java" />+ </patternset><property name="grammar.path" location="src/java/org/apache/lucene/expressions/@{package}"/>- <!-- this is a hack for windows, because antlr writes absolute paths with double backslashes (no idea why...): -->- <replace-value property="grammar.matchpath" value="${grammar.path}${file.separator}" from="\" to="\\"/>- <property name="-grammar.relative.path" location="${grammar.path}" relative="true"/>- <replace-value property="grammar.relative.path" value="${-grammar.relative.path}${file.separator}" from="${file.separator}" to="/"/>+ <!-- delete parser and lexer so files will be generated -->+ <delete dir="${grammar.path}">+ <patternset refid="grammar.@{grammar}.patternset"/>+ </delete>+ <!-- invoke ANTLR4 --><java classname="org.antlr.v4.Tool" fork="true" failonerror="true" classpathref="antlr.classpath" taskname="antlr"><sysproperty key="file.encoding" value="UTF-8"/><sysproperty key="user.language" value="en"/>@@ -108,33 +102,30 @@<arg value="-visitor"/><arg value="-o"/><arg path="${grammar.path}"/>- <arg path="${grammar.path}/@{grammar}.g"/>+ <arg path="${grammar.path}/@{grammar}.g4"/></java>- <!-- replace absolute paths by relative ones -->- <replace file="${grammar.path}/@{grammar}Parser.java" token="${grammar.matchpath}" value="${grammar.relative.path}" encoding="UTF-8"/>- <replace file="${grammar.path}/@{grammar}Lexer.java" token="${grammar.matchpath}" value="${grammar.relative.path}" encoding="UTF-8"/>- <replace file="${grammar.path}/@{grammar}Visitor.java" token="${grammar.matchpath}" value="${grammar.relative.path}" encoding="UTF-8"/>- <replace file="${grammar.path}/@{grammar}BaseVisitor.java" token="${grammar.matchpath}" value="${grammar.relative.path}" encoding="UTF-8"/>+ <!-- fileset with files to edit -->+ <fileset id="grammar.fileset" dir="${grammar.path}">+ <patternset refid="grammar.@{grammar}.patternset"/>+ </fileset>+ <!-- remove files that are not needed to compile or at runtime -->+ <delete dir="${grammar.path}" includes="@{grammar}*.tokens"/><!-- make the generated classes package private -->- <replace file="${grammar.path}/@{grammar}Parser.java" token="public class @{grammar}Parser" value="class @{grammar}Parser" encoding="UTF-8"/>- <replace file="${grammar.path}/@{grammar}Lexer.java" token="public class @{grammar}Lexer" value="class @{grammar}Lexer" encoding="UTF-8"/>- <replace file="${grammar.path}/@{grammar}Visitor.java" token="public interface @{grammar}Visitor" value="interface @{grammar}Visitor" encoding="UTF-8"/>- <replace file="${grammar.path}/@{grammar}BaseVisitor.java" token="public class @{grammar}BaseVisitor" value="class @{grammar}BaseVisitor" encoding="UTF-8"/>- <!-- nuke timestamps in generated files -->- <replaceregexp file="${grammar.path}/@{grammar}Parser.java" match=".*" replace="\/\/ ANTLR GENERATED CODE: DO NOT EDIT" encoding="UTF-8"/>- <replaceregexp file="${grammar.path}/@{grammar}Lexer.java" match=".*" replace="\/\/ ANTLR GENERATED CODE: DO NOT EDIT" encoding="UTF-8"/>- <replaceregexp file="${grammar.path}/@{grammar}Visitor.java" match=".*" replace="\/\/ ANTLR GENERATED CODE: DO NOT EDIT" encoding="UTF-8"/>- <replaceregexp file="${grammar.path}/@{grammar}BaseVisitor.java" match=".*" replace="\/\/ ANTLR GENERATED CODE: DO NOT EDIT" encoding="UTF-8"/>+ <replaceregexp match="public ((interface|class) \Q@{grammar}\E\w+)" replace="\1" encoding="UTF-8">+ <fileset refid="grammar.fileset"/>+ </replaceregexp>+ <!-- nuke timestamps/filenames in generated files -->+ <replaceregexp match="\Q// Generated from \E.*" replace="\/\/ ANTLR GENERATED CODE: DO NOT EDIT" encoding="UTF-8">+ <fileset refid="grammar.fileset"/>+ </replaceregexp><!-- remove tabs in antlr generated files -->- <replaceregexp file="${grammar.path}/@{grammar}Parser.java" match="\t" flags="g" replace=" " encoding="UTF-8"/>- <replaceregexp file="${grammar.path}/@{grammar}Lexer.java" match="\t" flags="g" replace=" " encoding="UTF-8"/>- <replaceregexp file="${grammar.path}/@{grammar}Visitor.java" match="\t" flags="g" replace=" " encoding="UTF-8"/>- <replaceregexp file="${grammar.path}/@{grammar}BaseVisitor.java" match="\t" flags="g" replace=" " encoding="UTF-8"/>+ <replaceregexp match="\t" flags="g" replace=" " encoding="UTF-8">+ <fileset refid="grammar.fileset"/>+ </replaceregexp><!-- fix line endings -->- <fixcrlf file="${grammar.path}/@{grammar}Parser.java"/>- <fixcrlf file="${grammar.path}/@{grammar}Lexer.java"/>- <fixcrlf file="${grammar.path}/@{grammar}Visitor.java"/>- <fixcrlf file="${grammar.path}/@{grammar}BaseVisitor.java"/>+ <fixcrlf srcdir="${grammar.path}">+ <patternset refid="grammar.@{grammar}.patternset"/>+ </fixcrlf></sequential></macrodef></project>diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/js/Javascript.g b/lucene/expressions/src/java/org/apache/lucene/expressions/js/Javascript.g4similarity index 100%rename from lucene/expressions/src/java/org/apache/lucene/expressions/js/Javascript.grename to lucene/expressions/src/java/org/apache/lucene/expressions/js/Javascript.g4diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/js/Javascript.tokens b/lucene/expressions/src/java/org/apache/lucene/expressions/js/Javascript.tokensdeleted file mode 100644index 01e31ee7105..00000000000--- a/lucene/expressions/src/java/org/apache/lucene/expressions/js/Javascript.tokens+++ /dev/null@@ -1,40 +0,0 @@-LP=1-RP=2-COMMA=3-BOOLNOT=4-BWNOT=5-MUL=6-DIV=7-REM=8-ADD=9-SUB=10-LSH=11-RSH=12-USH=13-LT=14-LTE=15-GT=16-GTE=17-EQ=18-NE=19-BWAND=20-BWXOR=21-BWOR=22-BOOLAND=23-BOOLOR=24-COND=25-COLON=26-WS=27-VARIABLE=28-OCTAL=29-HEX=30-DECIMAL=31-'<<'=11-'>>'=12-'>>>'=13-'<='=15-'>='=17-'=='=18-'!='=19-'&&'=23-'||'=24diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptLexer.java b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptLexer.javaindex 8a61829a0a2..a574add6be9 100644--- a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptLexer.java+++ b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptLexer.java@@ -83,7 +83,7 @@ class JavascriptLexer extends Lexer {}@Override- public String getGrammarFileName() { return "Javascript.g"; }+ public String getGrammarFileName() { return "Javascript.g4"; }@Overridepublic String[] getRuleNames() { return ruleNames; }diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptLexer.tokens b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptLexer.tokensdeleted file mode 100644index 01e31ee7105..00000000000--- a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptLexer.tokens+++ /dev/null@@ -1,40 +0,0 @@-LP=1-RP=2-COMMA=3-BOOLNOT=4-BWNOT=5-MUL=6-DIV=7-REM=8-ADD=9-SUB=10-LSH=11-RSH=12-USH=13-LT=14-LTE=15-GT=16-GTE=17-EQ=18-NE=19-BWAND=20-BWXOR=21-BWOR=22-BOOLAND=23-BOOLOR=24-COND=25-COLON=26-WS=27-VARIABLE=28-OCTAL=29-HEX=30-DECIMAL=31-'<<'=11-'>>'=12-'>>>'=13-'<='=15-'>='=17-'=='=18-'!='=19-'&&'=23-'||'=24diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptParser.java b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptParser.javaindex e93486b0200..d682a47d066 100644--- a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptParser.java+++ b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptParser.java@@ -72,7 +72,7 @@ class JavascriptParser extends Parser {}@Override- public String getGrammarFileName() { return "Javascript.g"; }+ public String getGrammarFileName() { return "Javascript.g4"; }@Overridepublic String[] getRuleNames() { return ruleNames; }