Skip to content

Commit

Permalink
javacc-wrapper: Avoid replace for non existent parser files
Browse files Browse the repository at this point in the history
This avoids errors like
[ERROR] [replaceregexp] The following file is missing: '.../pmd/pmd-javascript/target/generated-sources/javacc/net/sourceforge/pmd/lang/ecmascript5/ast/Ecmascript5ParserImpl.java'
  • Loading branch information
adangel committed Mar 7, 2024
1 parent a69068d commit e9a004e
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions javacc-wrapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
- lang-id: The language id, used in the conventional package names
- 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).
It also uses the following maven properties:
- javacc.outputDirectory: Directory in which to root the generated package tree
Expand Down Expand Up @@ -219,11 +222,11 @@

</target>

<target name="cleanup-parser">
<target name="cleanup-parser" unless="jjtreeBuildNotRequired">


<replace token="new Token()" value="token_source.input_stream.getTokenDocument().open()">
<fileset file="${parser-file}" />
<file name="${parser-file}" />
</replace>

<replaceregexp flags="g">
Expand All @@ -242,25 +245,25 @@
<replaceregexp flags="g">
<regexp pattern="\bJJT${parser-name}State\b" />
<substitution expression="${ast-impl-package}.JjtreeBuilder&lt;${base-class-name}&gt;" />
<fileset file="${parser-file}" />
<file name="${parser-file}" />
</replaceregexp>

<replaceregexp flags="g">
<regexp pattern="new ParseException\(token, exptokseq, tokenImage\);" />
<substitution expression="new ParseException(token, exptokseq);" />
<fileset file="${parser-file}" />
<file name="${parser-file}" />
</replaceregexp>

<replaceregexp flags="g">
<regexp pattern="throw new ParseException\(\);" />
<substitution expression='throw net.sourceforge.pmd.util.AssertionUtil.shouldNotReachHere("consumetoken(-1) should have thrown");' />
<fileset file="${parser-file}" />
<file name="${parser-file}" />
</replaceregexp>

<replaceregexp>
<regexp pattern="public interface"/>
<substitution expression="interface"/>
<fileset file="${target-package-dir}/${parser-name}TreeConstants.java" />
<file name="${target-package-dir}/${parser-name}TreeConstants.java" />
</replaceregexp>

</target>
Expand Down Expand Up @@ -372,8 +375,8 @@
<replaceregexp>
<regexp pattern="package ${lang-ast-package};" />
<substitution expression="\0${line.separator}${line.separator}import static ${lang-ast-package}.${token-constants-name}.*;" />
<fileset file="${tokenmgr-file}" />
<fileset file="${parser-file}" />
<file name="${tokenmgr-file}" />
<file name="${parser-file}" />
</replaceregexp>

<!-- Create constants file -->
Expand All @@ -387,26 +390,26 @@
public final class ${token-constants-name} \{${line.separator}
private ${token-constants-name}() { /* Utility class */ }${line.separator}
"/>
<fileset file="${token-constants-file}" />
<file name="${token-constants-file}" />
</replaceregexp>

<replaceregexp flags="g">
<regexp pattern="/\*\* RegularExpression Id. \*/\R" />
<substitution expression="public static final " />
<fileset file="${token-constants-file}" />
<file name="${token-constants-file}" />
</replaceregexp>

<replaceregexp flags="s">
<regexp pattern="/\*\* End of File. \*/\R" />
<substitution expression="public static final " />
<fileset file="${token-constants-file}" />
<file name="${token-constants-file}" />
</replaceregexp>

<!-- Lexical states are kept package-private -->
<replaceregexp flags="g">
<regexp pattern="/\*\* Lexical state. \*/\R" />
<substitution expression="static final " />
<fileset file="${token-constants-file}" />
<file name="${token-constants-file}" />
</replaceregexp>

<replace>
Expand Down Expand Up @@ -438,7 +441,7 @@ public final class ${token-constants-name} \{${line.separator}
private static final
]]> </replacevalue>
<fileset file="${token-constants-file}" />
<file name="${token-constants-file}" />
</replace>

<replace>
Expand All @@ -449,19 +452,19 @@ public final class ${token-constants-name} \{${line.separator}
/** 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>
<fileset file="${token-constants-file}" />
<file name="${token-constants-file}" />
</replace>

<replaceregexp>
<regexp pattern="%%%TOKEN_MGR_NAME%%%" />
<substitution expression="${tokenmgr-name}" />
<fileset file="${token-constants-file}" />
<file name="${token-constants-file}" />
</replaceregexp>

<replaceregexp flags="g">
<regexp pattern="%%%API_PACK%%%" />
<substitution expression="${ast-api-package}" />
<fileset file="${token-constants-file}" />
<file name="${token-constants-file}" />
</replaceregexp>

</target>
Expand All @@ -471,7 +474,7 @@ public final class ${token-constants-name} \{${line.separator}
<replaceregexp flags="g">
<regexp pattern="return new ${tokenmgr-name}\(cs\);" />
<substitution expression="return new ${parser-name}(cs).token_source;" />
<fileset file="${token-constants-file}"/>
<file name="${token-constants-file}" />
</replaceregexp>
</target>

Expand Down

0 comments on commit e9a004e

Please sign in to comment.