2020-01-10 21:54:37 +01:00
<!--
~ BSD-style license; for more info see http://pmd.sourceforge.net/license.html
-->
<project name= "pmd" default= "alljavacc" basedir= "/" >
<!-- Wraps a JavaCC/JJTree task and adapts the generated sources to the PMD
codebase.
Input parameters:
- lang-name: Capitalized name of the language eg Jsp or Java.
By convention the grammar file must be named exactly
so with a .jj[t] extension.
2020-08-26 19:25:21 +02:00
- lang-name-camelcase: Name of the language in camelcase. Useful for languages
whose name is an acronym, eg PLSQL (in camelcase, "Plsql").
Defaults to lang-name.
2024-02-23 17:45:23 +01:00
- lang-id: The language id, used in the conventional package names
2020-01-10 23:23:39 +01:00
2024-03-07 12:01:57 +01:00
- no-jjtree: true/false. Use true for CPD-only languages. Then a parser won't
be generated. By default, a parser will be generated (and jjtree will be called).
2020-01-10 23:23:39 +01:00
It also uses the following maven properties:
- javacc.outputDirectory: Directory in which to root the generated package tree
2024-10-13 12:03:17 +02:00
- plugin-classpath: The classpath of maven-antrun-plugin with javacc.jar dependency
Provided by maven via "<property name= "plugin-classpath" refid= "maven.plugin.classpath" /> "
2020-01-10 23:23:39 +01:00
- some properties of project.build
2020-01-10 21:54:37 +01:00
-->
2020-08-26 19:25:21 +02:00
<condition property= "lang-name-camelcase" value= "${lang-name}" >
<!-- Eg for "PLSQL": "Plsql" -->
<not >
<isset property= "lang-name-camelcase" />
</not>
</condition>
2024-02-23 17:45:23 +01:00
<property name= "target-package-dir" value= "${javacc.outputDirectory}/net/sourceforge/pmd/lang/${lang-id}/ast" />
2020-01-10 23:23:39 +01:00
<property name= "stamp-file" value= "${project.build.directory}/last-generated-timestamp" />
2020-01-10 21:54:37 +01:00
2024-02-23 17:45:23 +01:00
<property name= "lang-ast-package" value= "net.sourceforge.pmd.lang.${lang-id}.ast" />
2020-01-10 21:54:37 +01:00
<property name= "ast-api-package" value= "net.sourceforge.pmd.lang.ast" />
<property name= "ast-impl-package" value= "${ast-api-package}.impl.javacc" />
2023-08-10 11:27:53 +02:00
<property name= "grammar-file" value= "${basedir}/etc/grammar/${lang-name}.jjt" />
2020-01-11 00:58:49 +01:00
2020-01-11 02:39:24 +01:00
<property name= "parser-name" value= "${lang-name}ParserImpl" />
2020-01-11 00:58:49 +01:00
<property name= "parser-file" value= "${target-package-dir}/${parser-name}.java" />
2020-01-11 02:39:24 +01:00
<property name= "ast-prefix" value= "AST" />
<property name= "constants-itf-name" value= "${parser-name}Constants" />
<property name= "constants-itf-file" value= "${target-package-dir}/${constants-itf-name}.java" />
<property name= "token-constants-name" value= "${lang-name}TokenKinds" />
<property name= "token-constants-file" value= "${target-package-dir}/${token-constants-name}.java" />
2020-01-10 21:54:37 +01:00
<property name= "node-name" value= "${lang-name}Node" />
<property name= "base-class-name" value= "Abstract${lang-name}Node" />
<!-- This will be moved to impl package when all language modules have been ported -->
2020-04-29 00:48:57 +02:00
<property name= "base-tokenmgr" value= "${ast-impl-package}.AbstractTokenManager" />
2020-09-02 08:41:23 +02:00
<property name= "charstream-itf" value= "${ast-impl-package}.CharStream" />
2020-01-10 21:54:37 +01:00
<property name= "tokenmgr-name" value= "${parser-name}TokenManager" />
<property name= "tokenmgr-file" value= "${target-package-dir}/${tokenmgr-name}.java" />
2020-01-11 02:39:24 +01:00
<!-- Visitor names -->
2020-08-26 19:25:21 +02:00
<!-- This is the default name generated by JJTree -->
2020-01-11 02:39:24 +01:00
<property name= "gen-visitor-name" value= "${parser-name}Visitor" />
2020-08-26 19:25:21 +02:00
<!-- This is the actual name we use -->
<property name= "generic-visitor-interface-name" value= "${lang-name-camelcase}Visitor" />
2020-07-01 11:06:48 +02:00
<property name= "generic-visitor-interface-file"
2020-04-28 08:38:10 +02:00
value="${target-package-dir}/${generic-visitor-interface-name}.java" />
2020-01-11 02:39:24 +01:00
2020-01-10 21:54:37 +01:00
<!-- TARGETS -->
<target name= "alljavacc"
description="Generates JavaCC sources and cleans them up"
2024-10-13 12:03:17 +02:00
depends="checkUpToDate,init,jjtree,jjtree-ersatz,javacc,adapt-generated,default-visitor" />
2020-01-10 21:54:37 +01:00
<target name= "checkUpToDate"
description="Checks the input files are up to date">
<uptodate property= "javaccBuildNotRequired" targetfile= "${stamp-file}" >
<srcfiles dir= "etc/grammar" includes= "${lang-name}.jj*" />
<srcfiles file= "${ant.file}" />
</uptodate>
<echo message= "Up-to-date check: javaccBuildNotRequired=${javaccBuildNotRequired}" />
<condition property= "jjtreeBuildNotRequired" >
<or >
<isset property= "no-jjtree" />
<isset property= "javaccBuildNotRequired" />
</or>
</condition>
</target>
<target name= "init" unless= "javaccBuildNotRequired" description= "Initialize build" >
2020-01-10 23:23:39 +01:00
<mkdir dir= "${javacc.outputDirectory}" />
2020-01-10 21:54:37 +01:00
<touch file= "${stamp-file}" />
<delete dir= "${target-package-dir}" />
<mkdir dir= "${target-package-dir}" />
2023-08-10 11:27:53 +02:00
<condition property= "option-token-manager-uses-parser" >
2024-04-28 20:10:22 +02:00
<resourcecontains resource= "${grammar-file}" substring= "TOKEN_MANAGER_USES_PARSER = true" />
2023-08-10 11:27:53 +02:00
</condition>
2020-01-10 21:54:37 +01:00
</target>
<target name= "jjtree" unless= "jjtreeBuildNotRequired" description= "Runs JJTree" >
2020-03-19 17:57:30 +01:00
<!--
Token-tracking behavior is implemented in the JJTree builder,
so the grammar should have TRACK_TOKEN=false; (this is the default value)
-->
2021-01-16 19:29:09 +01:00
<java fork= "true"
classname="jjtree"
2024-10-13 12:03:17 +02:00
classpath="${plugin-classpath}">
2021-01-16 19:29:09 +01:00
<sysproperty key= "file.encoding" value= "UTF-8" />
<arg value= "-OUTPUT_DIRECTORY:${target-package-dir}" />
<arg value= "-NODE_USES_PARSER:false" />
<arg value= "-NODE_PACKAGE:${lang-ast-package}" />
2023-08-10 11:27:53 +02:00
<arg value= "${grammar-file}" />
2021-01-16 19:29:09 +01:00
</java>
2020-01-10 21:54:37 +01:00
</target>
<target name= "jjtree-ersatz" if= "no-jjtree" unless= "javaccBuildNotRequired" >
<!-- If no jjtree is run, then we look for a .jj file to place
in the target dir for the javacc target to pick up on it -->
<copy file= "etc/grammar/${lang-name}.jj" todir= "${target-package-dir}" />
</target>
<target name= "javacc" depends= "jjtree" unless= "javaccBuildNotRequired" >
2021-01-16 19:29:09 +01:00
<java fork= "true"
classname="javacc"
2024-10-13 12:03:17 +02:00
classpath="${plugin-classpath}">
2021-01-16 19:29:09 +01:00
<sysproperty key= "file.encoding" value= "UTF-8" />
<arg value= "-STATIC:false" />
<arg value= "-USER_CHAR_STREAM:true" />
<arg value= "-UNICODE_INPUT:true" />
<arg value= "-OUTPUT_DIRECTORY:${target-package-dir}" />
<arg value= "${target-package-dir}/${lang-name}.jj" />
</java>
2020-01-10 21:54:37 +01:00
</target>
<target name= "adapt-generated" unless= "javaccBuildNotRequired" >
2020-01-11 02:39:24 +01:00
<delete file= "${target-package-dir}/Node.java" />
<delete file= "${target-package-dir}/SimpleNode.java" />
<delete file= "${target-package-dir}/JJT${parser-name}State.java" />
2020-01-10 21:54:37 +01:00
<delete file= "${target-package-dir}/CharStream.java" />
<delete file= "${target-package-dir}/ParseException.java" />
<delete file= "${target-package-dir}/Token.java" />
<delete file= "${target-package-dir}/TokenMgrError.java" />
<!-- Remove all duplicate files -->
<delete >
2020-01-10 23:23:39 +01:00
<fileset dir= "${javacc.outputDirectory}" >
<present present= "both" targetdir= "${project.build.sourceDirectory}" />
2020-01-10 21:54:37 +01:00
</fileset>
</delete>
2020-01-11 02:39:24 +01:00
<antcall target= "cleanup-token-manager" />
<antcall target= "cleanup-parser" />
<antcall target= "cleanup-nodes" />
<!-- Map Javacc names to our names -->
<replaceregexp flags= "g" >
<regexp pattern= "\bToken\b" />
<substitution expression= "${ast-impl-package}.JavaccToken" />
<fileset dir= "${target-package-dir}" />
</replaceregexp>
<replaceregexp flags= "g" >
<regexp pattern= "(?<!\.)\bCharStream\b" />
<substitution expression= "${charstream-itf}" />
<fileset dir= "${target-package-dir}" />
</replaceregexp>
<antcall target= "constants-files" />
2023-08-10 11:27:53 +02:00
<antcall target= "constants-files-token-manager-uses-parser" />
2020-01-11 02:39:24 +01:00
<!-- For compatibility -->
2020-01-11 05:22:29 +01:00
<replaceregexp flags= "g" >
2020-02-08 00:28:13 +01:00
<regexp pattern= "\.image\b(?! =)" />
2020-01-11 05:22:29 +01:00
<substitution expression= ".getImage()" />
<fileset dir= "${target-package-dir}" />
</replaceregexp>
2024-02-08 09:56:55 +01:00
<replace token= ".beginLine" value= ".getReportLocation().getStartLine()" >
2020-01-11 02:39:24 +01:00
<fileset dir= "${target-package-dir}" />
</replace>
2024-02-08 09:56:55 +01:00
<replace token= ".beginColumn" value= ".getReportLocation().getStartColumn()" >
2020-01-11 02:39:24 +01:00
<fileset dir= "${target-package-dir}" />
</replace>
<!-- Used by debug modes -->
<replace token= "TokenMgrError.addEscapes" value= "net.sourceforge.pmd.util.StringUtil.escapeJava" >
<fileset dir= "${target-package-dir}" />
</replace>
</target>
2024-03-07 12:01:57 +01:00
<target name= "cleanup-parser" unless= "jjtreeBuildNotRequired" >
2020-01-11 02:39:24 +01:00
2024-09-17 17:09:29 -03:00
<replace token= "class ${parser-name}" value= '@net.sourceforge.pmd.annotation.Generated("org.javacc.javacc")${line.separator}class ${parser-name}' >
2024-09-17 17:00:42 -03:00
<file name= "${parser-file}" />
</replace>
2020-01-11 02:39:24 +01:00
<replace token= "new Token()" value= "token_source.input_stream.getTokenDocument().open()" >
2024-03-07 12:01:57 +01:00
<file name= "${parser-file}" />
2020-01-11 02:39:24 +01:00
</replace>
<replaceregexp flags= "g" >
<regexp pattern= 'jjtree.openNodeScope\((jjtn.*?)\);' />
<substitution expression= 'jjtree.openNodeScope(\1, getToken(1));' />
<file name= "${parser-file}" />
</replaceregexp>
<replaceregexp flags= "g" >
<regexp pattern= 'jjtree.closeNodeScope\((jjtn.*?)\);' />
<substitution expression= 'jjtree.closeNodeScope(\1, getToken(0));' />
<file name= "${parser-file}" />
</replaceregexp>
<!-- The tree builder is generic now -->
<replaceregexp flags= "g" >
<regexp pattern= "\bJJT${parser-name}State\b" />
<substitution expression= "${ast-impl-package}.JjtreeBuilder<${base-class-name}>" />
2024-03-07 12:01:57 +01:00
<file name= "${parser-file}" />
2020-01-11 02:39:24 +01:00
</replaceregexp>
<replaceregexp flags= "g" >
<regexp pattern= "new ParseException\(token, exptokseq, tokenImage\);" />
<substitution expression= "new ParseException(token, exptokseq);" />
2024-03-07 12:01:57 +01:00
<file name= "${parser-file}" />
2020-01-11 02:39:24 +01:00
</replaceregexp>
2023-03-19 22:49:45 +01:00
<replaceregexp flags= "g" >
<regexp pattern= "throw new ParseException\(\);" />
<substitution expression= 'throw net.sourceforge.pmd.util.AssertionUtil.shouldNotReachHere("consumetoken(-1) should have thrown");' />
2024-03-07 12:01:57 +01:00
<file name= "${parser-file}" />
2023-03-19 22:49:45 +01:00
</replaceregexp>
2020-01-11 02:39:24 +01:00
<replaceregexp >
<regexp pattern= "public interface" />
2024-09-17 17:00:42 -03:00
<substitution expression= '@net.sourceforge.pmd.annotation.Generated("org.javacc.javacc")${line.separator}
interface'/>
2024-03-07 12:01:57 +01:00
<file name= "${target-package-dir}/${parser-name}TreeConstants.java" />
2020-01-11 02:39:24 +01:00
</replaceregexp>
</target>
<target name= "cleanup-token-manager" >
2020-01-11 05:22:29 +01:00
<replaceregexp >
<regexp pattern= '(public )?class ${tokenmgr-name}' />
2024-09-17 17:00:42 -03:00
<substitution expression= '@net.sourceforge.pmd.annotation.Generated("org.javacc.javacc")${line.separator}
class ${tokenmgr-name} extends ${base-tokenmgr}' />
2020-01-11 05:22:29 +01:00
<file name= "${tokenmgr-file}" />
</replaceregexp>
2020-01-11 02:39:24 +01:00
<!-- This is a programming error and should be caught in tests -->
<replaceregexp >
<regexp pattern= 'throw new TokenMgrError\("Error: Ignoring invalid lexical state.*?\);' />
<substitution expression= 'throw new IllegalArgumentException("Invalid lexical state " + lexState);' />
<file name= "${tokenmgr-file}" />
2024-01-11 15:49:21 +01:00
</replaceregexp>
<!-- Use own LexException instead of JavaCC's TokenMgrError -->
<replaceregexp >
<regexp pattern= 'throw new TokenMgrError\(EOFSeen' />
2024-02-10 10:05:34 +01:00
<substitution expression= 'throw net.sourceforge.pmd.lang.ast.InternalApiBridge.newLexException(EOFSeen' />
2024-01-11 15:49:21 +01:00
<file name= "${tokenmgr-file}" />
2020-01-11 02:39:24 +01:00
</replaceregexp>
2020-01-25 15:17:12 +01:00
<!-- Useless argument, also replace lex state ID with its name -->
2020-01-11 02:39:24 +01:00
<replaceregexp >
2020-01-25 15:17:12 +01:00
<regexp pattern= 'curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR\)' />
<substitution expression= 'lexStateNames[curLexState], error_line, error_column, error_after, curChar)' />
2020-01-11 02:39:24 +01:00
<file name= "${tokenmgr-file}" />
</replaceregexp>
2020-01-10 21:54:37 +01:00
<!-- Patch token creation routine, delegates to the token document. -->
<replaceregexp flags= "s" >
<file name= "${tokenmgr-file}" />
<regexp pattern= "protected Token jjFillToken.*?(?=int curLexState = )" />
<substitution expression= "protected Token jjFillToken() {return input_stream.getTokenDocument().createToken(jjmatchedKind, input_stream, jjstrLiteralImages[jjmatchedKind]);}" />
</replaceregexp>
2020-04-18 13:02:54 +02:00
<!-- Renamed CharStream methods -->
<replaceregexp flags= "g" >
<file name= "${tokenmgr-file}" />
<regexp pattern= "image.append\(input_stream.GetSuffix\(" />
<substitution expression= "input_stream.appendSuffix(image,(" />
</replaceregexp>
<replaceregexp flags= "g" >
<file name= "${tokenmgr-file}" />
<regexp pattern= "input_stream.GetImage" />
<substitution expression= "input_stream.getTokenImage" />
</replaceregexp>
<replaceregexp flags= "g" >
<file name= "${tokenmgr-file}" />
<regexp pattern= "input_stream.BeginToken" />
<substitution expression= "input_stream.markTokenStart" />
</replaceregexp>
2020-01-10 21:54:37 +01:00
<!-- This is used to allow for tokens to be immutable. The lexical actions
return the new token instead of mutating it. -->
<replaceregexp flags= "sg" >
<file name= "${tokenmgr-file}" />
2020-01-15 00:07:06 +01:00
<regexp pattern= "void ((Token|Skip)LexicalActions\(Token matchedToken\))\R\{(.*?)}\R(?=(private )?void)" />
2020-01-10 21:54:37 +01:00
<substitution expression= "Token \ 1 { \ 3
return matchedToken;
}" />
</replaceregexp>
<!-- Update call sites for the previous routines -->
<replaceregexp >
<file name= "${tokenmgr-file}" />
<regexp pattern= "(Token|Skip)LexicalActions\(matchedToken\);" />
<substitution expression= "matchedToken = \0" />
</replaceregexp>
<!-- Fix end column being now exclusive -->
<!-- JavaCC assumes it's inclusive, uses it for character positions of errors -->
<!-- This is also used in debug mode -->
<replaceregexp flags= "sg" >
<file name= "${tokenmgr-file}" />
<regexp pattern= "input_stream.getEndColumn\(\)" />
<substitution expression= "(input_stream.getEndColumn() - 1)" />
</replaceregexp>
2020-01-11 02:39:24 +01:00
</target>
2020-01-10 21:54:37 +01:00
2020-01-11 02:39:24 +01:00
<target name= "constants-files" >
2020-01-10 21:54:37 +01:00
2020-01-11 02:39:24 +01:00
<replaceregexp flags= "g" >
<regexp pattern= "implements ${constants-itf-name}," />
<substitution expression= "implements" />
<fileset dir= "${target-package-dir}" />
2020-01-10 21:54:37 +01:00
</replaceregexp>
2020-01-11 00:58:49 +01:00
<replaceregexp flags= "g" >
2020-01-11 02:39:24 +01:00
<regexp pattern= ", ${constants-itf-name}\b" />
<substitution expression= "" />
<fileset dir= "${target-package-dir}" />
2020-01-11 00:58:49 +01:00
</replaceregexp>
<replaceregexp flags= "g" >
2020-01-11 02:39:24 +01:00
<regexp pattern= "implements ${constants-itf-name}\b" />
<substitution expression= "" />
<fileset dir= "${target-package-dir}" />
2020-01-11 00:58:49 +01:00
</replaceregexp>
2020-01-11 02:39:24 +01:00
<replaceregexp >
<regexp pattern= "package ${lang-ast-package};" />
2023-08-10 11:27:53 +02:00
<substitution expression= "\0${line.separator}${line.separator}import static ${lang-ast-package}.${token-constants-name}.*;" />
2024-03-07 12:01:57 +01:00
<file name= "${tokenmgr-file}" />
<file name= "${parser-file}" />
2020-01-11 02:39:24 +01:00
</replaceregexp>
2020-01-11 00:58:49 +01:00
2020-01-11 02:39:24 +01:00
<!-- Create constants file -->
2020-01-10 21:54:37 +01:00
2020-01-11 02:39:24 +01:00
<move file= "${constants-itf-file}" tofile= "${token-constants-file}" />
<replaceregexp >
2020-03-19 20:33:17 +01:00
<regexp pattern= "(public )?interface ${constants-itf-name} \{" />
2024-09-17 17:00:42 -03:00
<substitution expression= '/** T o k e n k i n d s ( { @ l i n k $ { a s t - i m p l - p a c k a g e } . J a v a c c T o k e n # k i n d } ) f o r t h i s l a n g u a g e . * / $ { l i n e . s e p a r a t o r }
2022-07-27 11:49:14 +02:00
@net.sourceforge.pmd.annotation.InternalApi${line.separator}
2024-09-17 17:00:42 -03:00
@net.sourceforge.pmd.annotation.Generated("org.javacc.javacc")${line.separator}
2020-03-19 20:33:17 +01:00
public final class ${token-constants-name} \{${line.separator}
private ${token-constants-name}() { /* Utility class */ }${line.separator}
2024-09-17 17:00:42 -03:00
'/>
2024-03-07 12:01:57 +01:00
<file name= "${token-constants-file}" />
2020-01-10 21:54:37 +01:00
</replaceregexp>
<replaceregexp flags= "g" >
2020-01-15 00:07:06 +01:00
<regexp pattern= "/\*\* RegularExpression Id. \*/\R" />
2020-01-11 02:39:24 +01:00
<substitution expression= "public static final " />
2024-03-07 12:01:57 +01:00
<file name= "${token-constants-file}" />
2020-01-10 21:54:37 +01:00
</replaceregexp>
2020-01-11 02:39:24 +01:00
<replaceregexp flags= "s" >
2020-03-19 20:33:17 +01:00
<regexp pattern= "/\*\* End of File. \*/\R" />
<substitution expression= "public static final " />
2024-03-07 12:01:57 +01:00
<file name= "${token-constants-file}" />
2020-01-11 02:39:24 +01:00
</replaceregexp>
<!-- Lexical states are kept package - private -->
2020-01-10 21:54:37 +01:00
<replaceregexp flags= "g" >
2020-01-15 00:07:06 +01:00
<regexp pattern= "/\*\* Lexical state. \*/\R" />
2020-01-11 02:39:24 +01:00
<substitution expression= "static final " />
2024-03-07 12:01:57 +01:00
<file name= "${token-constants-file}" />
2020-01-10 21:54:37 +01:00
</replaceregexp>
2020-01-11 02:39:24 +01:00
<replace >
<replacetoken > /** Literal token values. */</replacetoken>
2020-03-20 16:32:09 +01:00
<replacevalue > < ![CDATA[
2020-01-11 02:39:24 +01:00
/** Returns a string describing the given token kind.
* Returns null if the kind is unknown.
*
* @param kind Kind of token
*
* @return A string describing the given kind
*/
public static @org.checkerframework.checker.nullness.qual.Nullable
String describe(int kind) {
2020-03-20 16:32:09 +01:00
return kind < 0 | | k i n d > = tokenImage.length
2020-01-11 02:39:24 +01:00
? null
: tokenImage[kind];
}
2020-03-20 17:07:48 +01:00
/** Returns a new token manager for this language. The CharStream
* should be configured with the correct language-specific escaping
* and token document. This is not a published API, it's intended to
* be used as a basis for a CPD Tokenizer.
*/
@net.sourceforge.pmd.annotation.InternalApi
2020-09-02 06:07:39 +02:00
public static net.sourceforge.pmd.lang.TokenManager< %%%API_PACK%%%.impl.javacc.JavaccToken> newTokenManager(%%%API_PACK%%%.impl.javacc.CharStream cs) {
2020-03-20 16:32:09 +01:00
return new %%%TOKEN_MGR_NAME%%%(cs);
}
2020-01-11 02:39:24 +01:00
private static final
2020-03-20 16:32:09 +01:00
]]> </replacevalue>
2024-03-07 12:01:57 +01:00
<file name= "${token-constants-file}" />
2020-01-11 02:39:24 +01:00
</replace>
2020-09-02 08:41:23 +02:00
<replace >
<replacetoken > };</replacetoken>
<replacevalue > < ![CDATA[
};
/** Nams of the tokens, each index corresponds to a kind. See also {@link #describe(int)}. */
public static final java.util.List<String > TOKEN_NAMES = java.util.Collections.unmodifiableList(java.util.Arrays.asList(tokenImage));
]]> </replacevalue>
2024-03-07 12:01:57 +01:00
<file name= "${token-constants-file}" />
2020-09-02 08:41:23 +02:00
</replace>
2020-03-20 16:32:09 +01:00
<replaceregexp >
<regexp pattern= "%%%TOKEN_MGR_NAME%%%" />
<substitution expression= "${tokenmgr-name}" />
2024-03-07 12:01:57 +01:00
<file name= "${token-constants-file}" />
2020-03-20 16:32:09 +01:00
</replaceregexp>
<replaceregexp flags= "g" >
<regexp pattern= "%%%API_PACK%%%" />
<substitution expression= "${ast-api-package}" />
2024-03-07 12:01:57 +01:00
<file name= "${token-constants-file}" />
2020-03-20 16:32:09 +01:00
</replaceregexp>
2020-01-11 02:39:24 +01:00
</target>
2023-08-10 11:27:53 +02:00
<target name= "constants-files-token-manager-uses-parser" if= "option-token-manager-uses-parser" >
<echo level= "info" > Option TOKEN_MANAGER_USES_PARSER is enabled</echo>
2024-04-28 20:10:22 +02:00
2023-08-10 11:27:53 +02:00
<replaceregexp flags= "g" >
<regexp pattern= "return new ${tokenmgr-name}\(cs\);" />
2024-04-28 20:10:22 +02:00
<!-- TODO this implementation does not work as the first token is skipped, since it is fetched by the parser itself. -->
2023-08-10 11:27:53 +02:00
<substitution expression= "return new ${parser-name}(cs).token_source;" />
2024-03-07 12:01:57 +01:00
<file name= "${token-constants-file}" />
2023-08-10 11:27:53 +02:00
</replaceregexp>
</target>
2020-01-11 02:39:24 +01:00
<target name= "cleanup-nodes" >
2020-01-10 21:54:37 +01:00
<replaceregexp flags= "g" >
<regexp pattern= "\bParseException\b" />
<substitution expression= "${ast-api-package}.ParseException" />
<fileset dir= "${target-package-dir}" />
</replaceregexp>
<replaceregexp flags= "g" >
<regexp pattern= "extends SimpleNode\b" />
<substitution expression= "extends ${base-class-name}" />
<fileset dir= "${target-package-dir}" />
</replaceregexp>
2020-01-11 02:39:24 +01:00
<!-- Remove constructor with parser -->
<replaceregexp flags= "s" >
<regexp pattern= "public \w+\(${parser-name}.*?}" />
<substitution expression= "" />
<fileset dir= "${target-package-dir}" >
<include name= "${ast-prefix}*" />
</fileset>
2020-01-10 21:54:37 +01:00
</replaceregexp>
2020-01-11 02:39:24 +01:00
<!-- Make constructor package - private -->
<replaceregexp >
<regexp pattern= "public (\w+\(int)" />
<substitution expression= "\1" />
<fileset dir= "${target-package-dir}" >
<include name= "${ast-prefix}*" />
</fileset>
</replaceregexp>
2020-01-10 21:54:37 +01:00
2020-01-11 02:39:24 +01:00
<!-- Make constructor package - private -->
<replaceregexp >
2020-02-15 00:48:57 +01:00
<regexp pattern= "(?<!public(\R| ))class" />
2020-01-11 02:39:24 +01:00
<substitution expression= "public class" />
<fileset dir= "${target-package-dir}" >
<include name= "${ast-prefix}*" />
</fileset>
</replaceregexp>
2020-01-10 21:54:37 +01:00
2020-01-11 02:39:24 +01:00
<replaceregexp flags= "g" >
<regexp pattern= "/\*\* Accept the visitor. \*\*/" />
<substitution expression= "" />
<fileset dir= "${target-package-dir}" >
<include name= "${ast-prefix}*" />
</fileset>
</replaceregexp>
2020-01-10 21:54:37 +01:00
</target>
<target name= "default-visitor" depends= "jjtree" unless= "jjtreeBuildNotRequired" >
2020-08-25 02:04:10 +02:00
<move file= "${target-package-dir}/${gen-visitor-name}.java" tofile= "${generic-visitor-interface-file}" />
<replace file= "${generic-visitor-interface-file}" >
2024-09-17 17:00:42 -03:00
<replacefilter token= "public interface ${gen-visitor-name}"
value='@net.sourceforge.pmd.annotation.Generated("org.javacc.javacc")${line.separator}
public interface ${generic-visitor-interface-name}< P, R> extends ${ast-api-package}.AstVisitor< P, R>' />
2020-01-10 21:54:37 +01:00
<replacefilter token= "SimpleNode" value= "${node-name}" />
2020-08-25 02:04:10 +02:00
<!-- Root method, eg visitJavaNode -->
2020-01-10 21:54:37 +01:00
<replacefilter
2020-08-25 02:04:10 +02:00
token="Object visit(${node-name} node, Object data);"
2020-08-26 19:25:21 +02:00
value="default R visit${lang-name-camelcase}Node(${node-name} node, P data) { return visitNode(node, data); }">
2020-01-10 21:54:37 +01:00
</replacefilter>
2020-04-28 08:38:10 +02:00
2020-08-25 02:04:10 +02:00
<replacefilter token= "public Object visit(" value= "default R visit(" />
2020-08-26 19:25:21 +02:00
<replacefilter token= "Object data);" value= "P data) { return visit${lang-name-camelcase}Node(node, data); }" />
2020-01-10 21:54:37 +01:00
</replace>
2020-08-07 03:15:33 +02:00
<replace >
2020-08-25 02:04:10 +02:00
<replacefilter token= "public Object jjtAccept(${gen-visitor-name} visitor, Object data)"
value="@Override protected < P, R> R accept${generic-visitor-interface-name}(${generic-visitor-interface-name}< ? super P, ? extends R> visitor, P data)" />
2020-08-07 03:15:33 +02:00
<fileset dir= "${target-package-dir}" >
<include name= "${ast-prefix}*" />
</fileset>
</replace>
2020-01-10 21:54:37 +01:00
</target>
</project>