2015-12-09 19:32:37 -05:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<project name="ant-stuff">
|
|
|
|
|
2017-01-19 11:41:50 -05:00
|
|
|
<!--
|
2015-12-09 19:32:37 -05:00
|
|
|
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
|
2017-01-19 11:41:50 -05:00
|
|
|
* regeneration should be rare, no reason to be religious about generated files
|
2015-12-09 19:32:37 -05:00
|
|
|
* 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">
|
2016-01-27 13:37:34 -05:00
|
|
|
<regen-delete grammar="Painless"/>
|
|
|
|
<regen-lexer grammar="Painless"/>
|
|
|
|
<regen-parser grammar="Painless"/>
|
|
|
|
<regen-fix grammar="Painless"/>
|
2015-12-09 19:32:37 -05:00
|
|
|
</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>
|
2016-05-23 19:36:01 -04:00
|
|
|
<local name="grammar.path"/>
|
|
|
|
<property name="grammar.path" location="src/main/antlr"/>
|
|
|
|
<!-- delete token files so files will be generated -->
|
|
|
|
<delete dir="${grammar.path}" includes="@{grammar}*.tokens"/>
|
2015-12-09 19:32:37 -05:00
|
|
|
<local name="output.path"/>
|
|
|
|
<patternset id="grammar.@{grammar}.patternset">
|
|
|
|
<include name="@{grammar}Lexer.java" />
|
|
|
|
<include name="@{grammar}Parser.java" />
|
2016-05-23 19:36:01 -04:00
|
|
|
<include name="@{grammar}Lexer.tokens" />
|
|
|
|
<include name="@{grammar}Parser.tokens" />
|
2015-12-09 19:32:37 -05:00
|
|
|
<include name="@{grammar}ParserVisitor.java" />
|
|
|
|
<include name="@{grammar}ParserBaseVisitor.java" />
|
|
|
|
</patternset>
|
2016-05-12 03:46:48 -04:00
|
|
|
<property name="output.path" location="src/main/java/org/elasticsearch/painless/antlr"/>
|
2015-12-09 19:32:37 -05:00
|
|
|
<!-- 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"/>
|
2016-05-12 03:46:48 -04:00
|
|
|
<property name="output.path" location="src/main/java/org/elasticsearch/painless/antlr"/>
|
2015-12-09 19:32:37 -05:00
|
|
|
<!-- 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=""/>
|
2016-05-23 19:36:01 -04:00
|
|
|
<arg value="-Werror"/>
|
2015-12-09 19:32:37 -05:00
|
|
|
<arg value="-package"/>
|
2016-05-12 03:46:48 -04:00
|
|
|
<arg value="org.elasticsearch.painless.antlr"/>
|
2015-12-09 19:32:37 -05:00
|
|
|
<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"/>
|
2016-05-12 03:46:48 -04:00
|
|
|
<property name="output.path" location="src/main/java/org/elasticsearch/painless/antlr"/>
|
2015-12-09 19:32:37 -05:00
|
|
|
<!-- 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=""/>
|
2016-05-23 19:36:01 -04:00
|
|
|
<arg value="-Werror"/>
|
2015-12-09 19:32:37 -05:00
|
|
|
<arg value="-package"/>
|
2016-05-12 03:46:48 -04:00
|
|
|
<arg value="org.elasticsearch.painless.antlr"/>
|
2015-12-09 19:32:37 -05:00
|
|
|
<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"/>
|
2016-05-12 03:46:48 -04:00
|
|
|
<property name="output.path" location="src/main/java/org/elasticsearch/painless/antlr"/>
|
2015-12-09 19:32:37 -05:00
|
|
|
<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>
|
2016-05-23 19:36:01 -04:00
|
|
|
<!-- moves token files to grammar directory for use with IDE's -->
|
|
|
|
<move file="${output.path}/@{grammar}Lexer.tokens" todir="${grammar.path}"/>
|
|
|
|
<move file="${output.path}/@{grammar}Parser.tokens" todir="${grammar.path}"/>
|
2015-12-09 19:32:37 -05:00
|
|
|
<!-- 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>
|
2017-01-19 11:41:50 -05:00
|
|
|
<!-- make the lexer abstract -->
|
|
|
|
<replaceregexp match="(class \Q@{grammar}\ELexer)" replace="abstract \1" encoding="UTF-8">
|
|
|
|
<fileset refid="grammar.fileset"/>
|
|
|
|
</replaceregexp>
|
2015-12-09 19:32:37 -05:00
|
|
|
<!-- 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>
|