146 lines
5.6 KiB
XML
146 lines
5.6 KiB
XML
|
<?xml version="1.0"?>
|
||
|
<project name="ant-stuff">
|
||
|
|
||
|
<!--
|
||
|
grammar regeneration logic
|
||
|
we do this with ant for several reasons:
|
||
|
* remove generated tabs for forbidden-apis
|
||
|
* remove generated timestamps/filenames for reproducible build
|
||
|
* fix CRLF line endings for windows consistency
|
||
|
* ability to make classes package-private
|
||
|
* keeping in source code control is easier on IDEs
|
||
|
* regeneration should be rare, no reason to be religious about generated files
|
||
|
* all logic already written and battle tested in lucene build
|
||
|
-->
|
||
|
<target name="regenerate" description="Regenerate antlr lexer and parser" depends="run-antlr"/>
|
||
|
|
||
|
<target name="run-antlr">
|
||
|
<regen-delete grammar="PlanA"/>
|
||
|
<regen-lexer grammar="PlanA"/>
|
||
|
<regen-parser grammar="PlanA"/>
|
||
|
<regen-fix grammar="PlanA"/>
|
||
|
</target>
|
||
|
|
||
|
<macrodef name="replace-value">
|
||
|
<attribute name="value" />
|
||
|
<attribute name="property" />
|
||
|
<attribute name="from" />
|
||
|
<attribute name="to" />
|
||
|
<sequential>
|
||
|
<loadresource property="@{property}">
|
||
|
<string value="@{value}"/>
|
||
|
<filterchain>
|
||
|
<tokenfilter>
|
||
|
<filetokenizer/>
|
||
|
<replacestring from="@{from}" to="@{to}"/>
|
||
|
</tokenfilter>
|
||
|
</filterchain>
|
||
|
</loadresource>
|
||
|
</sequential>
|
||
|
</macrodef>
|
||
|
|
||
|
<macrodef name="regen-delete">
|
||
|
<attribute name="grammar" />
|
||
|
<sequential>
|
||
|
<local name="output.path"/>
|
||
|
<patternset id="grammar.@{grammar}.patternset">
|
||
|
<include name="@{grammar}Lexer.java" />
|
||
|
<include name="@{grammar}Parser.java" />
|
||
|
<include name="@{grammar}ParserVisitor.java" />
|
||
|
<include name="@{grammar}ParserBaseVisitor.java" />
|
||
|
</patternset>
|
||
|
<property name="output.path" location="src/main/java/org/elasticsearch/plan/a"/>
|
||
|
<!-- delete parser and lexer so files will be generated -->
|
||
|
<delete dir="${output.path}">
|
||
|
<patternset refid="grammar.@{grammar}.patternset"/>
|
||
|
</delete>
|
||
|
</sequential>
|
||
|
</macrodef>
|
||
|
|
||
|
<macrodef name="regen-lexer">
|
||
|
<attribute name="grammar" />
|
||
|
<sequential>
|
||
|
<local name="grammar.path"/>
|
||
|
<local name="output.path"/>
|
||
|
<property name="grammar.path" location="src/main/antlr"/>
|
||
|
<property name="output.path" location="src/main/java/org/elasticsearch/plan/a"/>
|
||
|
<!-- invoke ANTLR4 -->
|
||
|
<java classname="org.antlr.v4.Tool" fork="true" failonerror="true" classpathref="regenerate.classpath" taskname="antlr">
|
||
|
<sysproperty key="file.encoding" value="UTF-8"/>
|
||
|
<sysproperty key="user.language" value="en"/>
|
||
|
<sysproperty key="user.country" value="US"/>
|
||
|
<sysproperty key="user.variant" value=""/>
|
||
|
<arg value="-package"/>
|
||
|
<arg value="org.elasticsearch.plan.a"/>
|
||
|
<arg value="-o"/>
|
||
|
<arg path="${output.path}"/>
|
||
|
<arg path="${grammar.path}/@{grammar}Lexer.g4"/>
|
||
|
</java>
|
||
|
</sequential>
|
||
|
</macrodef>
|
||
|
|
||
|
<macrodef name="regen-parser">
|
||
|
<attribute name="grammar" />
|
||
|
<sequential>
|
||
|
<local name="grammar.path"/>
|
||
|
<local name="output.path"/>
|
||
|
<property name="grammar.path" location="src/main/antlr"/>
|
||
|
<property name="output.path" location="src/main/java/org/elasticsearch/plan/a"/>
|
||
|
<!-- invoke ANTLR4 -->
|
||
|
<java classname="org.antlr.v4.Tool" fork="true" failonerror="true" classpathref="regenerate.classpath" taskname="antlr">
|
||
|
<sysproperty key="file.encoding" value="UTF-8"/>
|
||
|
<sysproperty key="user.language" value="en"/>
|
||
|
<sysproperty key="user.country" value="US"/>
|
||
|
<sysproperty key="user.variant" value=""/>
|
||
|
<arg value="-package"/>
|
||
|
<arg value="org.elasticsearch.plan.a"/>
|
||
|
<arg value="-no-listener"/>
|
||
|
<arg value="-visitor"/>
|
||
|
<!-- <arg value="-Xlog"/> -->
|
||
|
<arg value="-o"/>
|
||
|
<arg path="${output.path}"/>
|
||
|
<arg path="${grammar.path}/@{grammar}Parser.g4"/>
|
||
|
</java>
|
||
|
</sequential>
|
||
|
</macrodef>
|
||
|
|
||
|
<macrodef name="regen-fix">
|
||
|
<attribute name="grammar" />
|
||
|
<sequential>
|
||
|
<local name="grammar.path"/>
|
||
|
<local name="output.path"/>
|
||
|
<property name="grammar.path" location="src/main/antlr"/>
|
||
|
<property name="output.path" location="src/main/java/org/elasticsearch/plan/a"/>
|
||
|
<patternset id="grammar.@{grammar}.patternset">
|
||
|
<include name="@{grammar}Lexer.java" />
|
||
|
<include name="@{grammar}Parser.java" />
|
||
|
<include name="@{grammar}ParserVisitor.java" />
|
||
|
<include name="@{grammar}ParserBaseVisitor.java" />
|
||
|
</patternset>
|
||
|
<!-- fileset with files to edit -->
|
||
|
<fileset id="grammar.fileset" dir="${output.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"/>
|
||
|
<delete dir="${output.path}" includes="@{grammar}*.tokens"/>
|
||
|
<!-- make the generated classes package private -->
|
||
|
<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 match="\t" flags="g" replace=" " encoding="UTF-8">
|
||
|
<fileset refid="grammar.fileset"/>
|
||
|
</replaceregexp>
|
||
|
<!-- fix line endings -->
|
||
|
<fixcrlf srcdir="${output.path}">
|
||
|
<patternset refid="grammar.@{grammar}.patternset"/>
|
||
|
</fixcrlf>
|
||
|
</sequential>
|
||
|
</macrodef>
|
||
|
</project>
|