pmd/antlr4-wrapper.xml

44 lines
1.9 KiB
XML
Raw Normal View History

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"/>
<target name="adapt-antlr-sources" description="Adapt antlr sources to the PMD codebase">
<replace file="${target-package-dir}/${lang-name}Parser.java"
2020-05-02 21:48:50 +02:00
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"/>
2020-05-02 02:57:14 +02:00
<replace file="${target-package-dir}/${lang-name}Parser.java"
token="_ctx = _localctx;"
value="_ctx = _localctx.asAntlrNode();"/>
<replace file="${target-package-dir}/${lang-name}Parser.java"
token="else return visitor.visitChildren(this);"
value="
else if (visitor instanceof PmdAntlrVisitor) return ((PmdAntlrVisitor&lt;? extends T>) visitor).visitChildren(this);
else return visitor.visitChildren(asAntlrNode());"/>
2020-05-02 02:57:14 +02:00
<replaceregexp flags="g" file="${target-package-dir}/${lang-name}Parser.java">
<regexp pattern="_sempred\(\((\w+)\)_localctx,"/>
<substitution expression="_sempred\((\1) asPmdNode(_localctx),"/>
</replaceregexp>
<replace file="${target-package-dir}/${lang-name}Visitor.java"
token="extends ParseTreeVisitor"
value="extends net.sourceforge.pmd.lang.ast.impl.antlr4.PmdAntlrVisitor"/>
</target>
</project>