pmd/antlr4-wrapper.xml
2020-05-02 22:56:42 +02:00

35 lines
1.6 KiB
XML

<!--
~ BSD-style license; for more info see http://pmd.sourceforge.net/license.html
-->
<project name="pmd" default="adapt-antlr-sources" basedir="../../../../">
<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"
token="TopLevelContext extends ${lang-name}InnerNode"
value="TopLevelContext extends ${lang-name}InnerNode implements net.sourceforge.pmd.lang.ast.RootNode"/>
<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());"/>
<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>