2020-05-02 02:57:14 +02:00
|
|
|
<!--
|
|
|
|
~ BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
|
|
|
-->
|
|
|
|
|
|
|
|
<project name="pmd" default="adapt-antlr-sources" basedir="../../../../">
|
|
|
|
|
2020-05-02 21:48:50 +02:00
|
|
|
<!-- Input properties:
|
|
|
|
- lang-name: matches the grammar name (eg "Swift")
|
|
|
|
- lang-terse-name: uncapitalized package name (eg "swift")
|
|
|
|
- root-node-name: name of the root node (eg "TopLevel"), will be made to implement RootNode
|
|
|
|
|
|
|
|
See AntlrGeneratedParserBase
|
|
|
|
|
|
|
|
-->
|
|
|
|
|
2020-05-02 02:57:14 +02:00
|
|
|
<property name="target-package-dir" value="${antlr4.outputDirectory}/net/sourceforge/pmd/lang/${lang-terse-name}/ast"/>
|
|
|
|
|
2020-06-17 20:25:56 +02:00
|
|
|
|
|
|
|
<property name="lang-ast-package" value="net.sourceforge.pmd.lang.${lang-terse-name}.ast" />
|
|
|
|
<property name="ast-api-package" value="net.sourceforge.pmd.lang.ast" />
|
|
|
|
<property name="ast-impl-package" value="${ast-api-package}.impl.antlr4" />
|
|
|
|
|
|
|
|
|
|
|
|
<property name="parser-name" value="${lang-name}Parser"/>
|
|
|
|
<property name="parser-file" value="${target-package-dir}/${parser-name}.java"/>
|
|
|
|
|
|
|
|
<property name="visitor-name" value="${lang-name}Visitor"/>
|
|
|
|
<property name="visitor-file" value="${target-package-dir}/${visitor-name}.java"/>
|
|
|
|
|
|
|
|
<property name="base-visitor-name" value="${lang-name}BaseVisitor"/>
|
|
|
|
<property name="base-visitor-file" value="${target-package-dir}/${base-visitor-name}.java"/>
|
|
|
|
|
|
|
|
<property name="node-itf-name" value="${lang-name}Node"/>
|
|
|
|
<property name="base-class-name" value="Abstract${lang-name}Node"/>
|
|
|
|
|
2020-05-02 02:57:14 +02:00
|
|
|
<target name="adapt-antlr-sources" description="Adapt antlr sources to the PMD codebase">
|
|
|
|
|
2020-06-17 20:25:56 +02:00
|
|
|
<!-- Adapt parser. -->
|
|
|
|
<replace file="${parser-file}">
|
|
|
|
<replacefilter token="${root-node-name}Context extends ${lang-name}InnerNode"
|
|
|
|
value="${root-node-name}Context extends ${lang-name}InnerNode implements net.sourceforge.pmd.lang.ast.RootNode"/>
|
|
|
|
|
|
|
|
<replacefilter token="_ctx = _localctx;"
|
|
|
|
value="_ctx = _localctx.asAntlrNode();"/>
|
|
|
|
|
|
|
|
<replacefilter token="public <T> T accept(ParseTreeVisitor<? extends T> visitor)"
|
|
|
|
value="public <P, R> R acceptVisitor(AstVisitor<? super P, ? extends R> visitor, P data)" />
|
|
|
|
|
|
|
|
<replacefilter token="((${visitor-name}<? extends T>)visitor)"
|
|
|
|
value="((${visitor-name}<? super P, ? extends R>) visitor)" />
|
2020-05-02 02:57:14 +02:00
|
|
|
|
2020-06-17 20:25:56 +02:00
|
|
|
<replacefilter token="return visitor.visitChildren(this);"
|
|
|
|
value="return visitor.visitNode(this, data);" />
|
2020-05-02 02:57:14 +02:00
|
|
|
|
2020-06-17 20:25:56 +02:00
|
|
|
</replace>
|
2020-05-02 02:57:14 +02:00
|
|
|
|
2020-06-17 20:25:56 +02:00
|
|
|
<replaceregexp flags="g" file="${parser-file}">
|
|
|
|
<regexp pattern="\.visit(\w++)\(this\);"/>
|
|
|
|
<substitution expression=".visit\1(this, data);"/>
|
|
|
|
</replaceregexp>
|
|
|
|
|
|
|
|
<replaceregexp flags="g" file="${parser-file}">
|
2020-05-02 02:57:14 +02:00
|
|
|
<regexp pattern="_sempred\(\((\w+)\)_localctx,"/>
|
|
|
|
<substitution expression="_sempred\((\1) asPmdNode(_localctx),"/>
|
|
|
|
</replaceregexp>
|
|
|
|
|
2020-06-17 20:25:56 +02:00
|
|
|
<!-- Transform the visitor to PMD-style. -->
|
|
|
|
<replace file="${visitor-file}">
|
|
|
|
|
|
|
|
<replacefilter token="Visitor<T> extends ParseTreeVisitor<T> {"
|
|
|
|
value="Visitor<P, R> extends net.sourceforge.pmd.lang.ast.AstVisitor<P, R> {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default visit method for ${lang-name} nodes. Unless overridden,
|
|
|
|
* the default implementations of the methods of this interface delegate
|
|
|
|
* to this method. The default calls {@link #visitNode(Node, Object)}.
|
|
|
|
*
|
|
|
|
* @param node Node to visit
|
|
|
|
* @param data Parameter of the visit
|
|
|
|
* @return Result of the visit
|
|
|
|
*/
|
|
|
|
default R visit${node-itf-name}(${node-itf-name} node, P data) { return visitNode(node, data); }
|
|
|
|
|
|
|
|
"/>
|
|
|
|
|
|
|
|
<replacefilter token="T visit" value="default R visit"/>
|
|
|
|
<replacefilter token="ctx);" value="node, P data) { return visit${node-itf-name}(node, data); }"/>
|
|
|
|
|
|
|
|
</replace>
|
|
|
|
|
|
|
|
<replace file="${visitor-file}">
|
|
|
|
|
|
|
|
<replacefilter token="Visitor<T> extends ParseTreeVisitor<T> {"
|
|
|
|
value="Visitor<P, R> extends net.sourceforge.pmd.lang.ast.AstVisitor<P, R> {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default visit method for ${lang-name} nodes. Unless overridden,
|
|
|
|
* the default implementations of the methods of this interface delegate
|
|
|
|
* to this method. The default calls {@link #visitNode(Node, Object)}.
|
|
|
|
*
|
|
|
|
* @param node Node to visit
|
|
|
|
* @param data Parameter of the visit
|
|
|
|
* @return Result of the visit
|
|
|
|
*/
|
|
|
|
default R visit${node-itf-name}(${node-itf-name} node, P data) { return visitNode(node, data); }
|
|
|
|
|
|
|
|
"/>
|
|
|
|
|
|
|
|
<replacefilter token="T visit" value="default R visit"/>
|
|
|
|
<replacefilter token="ctx);" value="node, P data) { return visit${node-itf-name}(node, data); }"/>
|
|
|
|
|
|
|
|
</replace>
|
|
|
|
|
|
|
|
<!-- This is in the main sources (not much to do). -->
|
|
|
|
<delete file="${base-visitor-file}" />
|
2020-05-02 02:57:14 +02:00
|
|
|
</target>
|
|
|
|
</project>
|