Note
|
Version 5 of this plugin will only work with Gradle 8.5 and JDK 17. |
This plugin generates Java code from JavaCC and JJTree files. See Java Compiler Compiler tm (JavaCC tm) - The Java Parser Generator.
To apply the JavaCC Gradle Plugin to your projects, add the following in your build script:
Groovy
plugins {
id 'com.intershop.gradle.javacc' version '5.0.0'
}
javacc {
// configuration container for all javacc configurations
configs {
template {
inputFile = file('jj/TemplateParser.jj')
packageName = 'com.corporate.internal.parser'
lookahead = '2'
}
}
}
Kotlin
plugins {
id("com.intershop.gradle.javacc") version "5.0.0"
}
javacc {
// configuration container for all javacc configurations
configs {
register("template") {
inputFile = file("jj/TemplateParser.jj")
packageName = "com.corporate.internal.parser"
lookahead = "2"
}
}
}
This plugin applies code generation to a project. If the JavaBasePlugin is applied to the project, generated java sources will be added to the specified source set. Per default the main source set is used.
Important
|
This plugin uses net.java.dev.javacc:javacc:7.0.13 . It is possible to overwrite the project dependency configuration 'javacc', if you want to use another library for JavaCC code generation.
|
The JavaCC Gradle plugin adds one task javacc
to the project. This task depends on all other plugin task. It is a task added for each configuration.
Task name |
Type |
Description |
javacc |
Task |
Overall |
javacc<configuration name> |
com.intershop.build.javacc.task.JavaCCTask |
This task generates Java code for the specified configuration. |
This plugin adds an extension javacc
to the project.
Property |
Type |
Default value |
Description |
javaCCVersion |
|
'4.2' |
The version of JavaCC. |
Method | Type | Description |
---|---|---|
configs |
This contains all Java code generation configurations. |
Property | Type | Default value | Description |
---|---|---|---|
outputDir |
|
|
Generated code will be written under this directory. |
args |
|
Additional command line arguments passed to javaCC |
|
sourceSetName |
|
|
Generated source code will be added to the source set. |
inputFile |
|
The input jj-File for the code generation. |
|
packageName |
|
A special package name for the code generation. The output directory will be extended with this configuration. |
|
The following variables are integer variables. |
|||
lookahead |
|
LOOKAHEAD: The number of tokens to look ahead before making a decision at a choice point during parsing. The default value is 1. |
|
choiceAmbiguityCheck |
|
CHOICE_AMBIGUITY_CHECK: This is an integer option whose default value is 2. |
|
otherAmbiguityCheck |
|
OTHER_AMBIGUITY_CHECK: This is an integer option whose default value is 1. |
|
The following variables will be interpreted as boolean. |
|||
staticParam |
|
STATIC: This is a boolean option whose default value is true. |
|
supportClassVisibilityPublic |
|
SUPPORT_CLASS_VISIBILITY_PUBLIC: This is a boolean option whose default value is true. |
|
debugParser |
|
DEBUG_PARSER: This is a boolean option whose default value is false. |
|
debugLookahead |
|
DEBUG_LOOKAHEAD: This is a boolean option whose default value is false. |
|
debugTokenManager |
|
DEBUG_TOKEN_MANAGER: This is a boolean option whose default value is false. |
|
errorReporting |
|
ERROR_REPORTING: This is a boolean option whose default value is true. |
|
javaUnicodeEscape |
|
JAVA_UNICODE_ESCAPE: This is a boolean option whose default value is false. |
|
unicodeInput |
|
UNICODE_INPUT: This is a boolean option whose default value is false. |
|
ignoreCase |
|
IGNORE_CASE: This is a boolean option whose default value is false. |
|
commonTokenAction |
|
COMMON_TOKEN_ACTION: This is a boolean option whose default value is false. |
|
userTokenManager |
|
USER_TOKEN_MANAGER: This is a boolean option whose default value is false. |
|
userCharStream |
|
USER_CHAR_STREAM: This is a boolean option whose default value is false. |
|
buildParser |
|
BUILD_PARSER: This is a boolean option whose default value is true. |
|
buildTokenManager |
|
BUILD_TOKEN_MANAGER: This is a boolean option whose default value is true. |
|
tokenManagerUsesParser |
|
TOKEN_MANAGER_USES_PARSER: This is a boolean option whose default value is false. |
|
sanityCheck |
|
SANITY_CHECK: This is a boolean option whose default value is true. |
|
forceLaCheck |
|
FORCE_LA_CHECK: This is a boolean option whose default value is false. |
|
cacheTokens |
|
CACHE_TOKENS: This is a boolean option whose default value is false. |
|
keepLineColumn |
|
KEEP_LINE_COLUMN: This is a boolean option whose default value is true. |
|
The following variables will be interpreted as string. |
|||
tokenExtends |
|
TOKEN_EXTENDS: This is a string option whose default value is "", meaning that the generated Token class will extend java.lang.Object. |
|
tokenFactory |
|
TOKEN_FACTORY: This is a string option whose default value is "", meaning that Tokens will be created by calling Token.newToken(). |
|
jdkVersion |
|
JDK_VERSION: This is a string option whose default value is "1.4" |
Method |
Parameter |
Description |
addArg |
|
Add an additional command line argument passed to JavaCC |
addArgs |
|
Add additional command line arguments passed to JavaCC |
Closure | Parameter | Description |
---|---|---|
jjtree |
Add an additional configuration for JJTree |
Property |
Type |
Default value |
Description |
The following variables will be interpreted as boolean. |
|||
multi |
|
MULTI (default: false) Generate a multi mode parse tree. The default for this is false, generating a simple mode parse tree. |
|
nodeDefaultVoid |
|
NODE_DEFAULT_VOID (default: false) Instead of making each non-decorated production an indefinite node, make it void instead. |
|
nodeScopeHook |
|
NODE_SCOPE_HOOK (default: false) Insert calls to user-defined parser methods on entry and exit of every node scope. See Node Scope Hooks. |
|
nodeUsesParser |
|
NODE_USES_PARSER (default: false)JJTree will use an alternate form of the node construction routines where it passes the parser object in. |
|
buildNodeFiles |
|
BUILD_NODE_FILES (default: true) Generate sample implementations for SimpleNode and any other nodes used in the grammar. |
|
staticParam |
|
STATIC (default: true) Generate code for a static parser. The default for this is true. This must be used consistently with the equivalent JavaCC options. |
|
trackTokens |
|
TRACK_TOKENS (default: false) Insert jjtGetFirstToken(), jjtSetFirstToken(), getLastToken(), and jjtSetLastToken() methods in SimpleNode. |
|
visitor |
|
VISITOR (default: false) Insert a jjtAccept() method in the node classes, and generate a visitor implementation with an entry for every node type used in the grammar. |
|
The following variables will be interpreted as string. |
|||
nodeClass |
|
NODE_CLASS (default: "") If set defines the name of a user-supplied class that will extend SimpleNode. Any tree nodes created will then be subclasses of NODE_CLASS. |
|
nodePrefix |
|
'AST' |
NODE_PREFIX (default: "AST") The prefix used to construct node class names from node identifiers in multi mode. The default for this is AST. |
nodePackage |
|
NODE_PACKAGE (default: "") The package to generate the node classes into. The default for this is the parser package. |
|
nodeExtends |
|
NODE_EXTENDS (default: "") Deprecated |
|
nodeFactory |
|
NODE_FACTORY (default: "") Specify a class containing a factory method with following signature to construct nodes: public static Node jjtCreate(int id) |
|
visitorDataType |
|
VISITOR_DATA_TYPE (default: "Object") If this option is set, it is used in the signature of the generated jjtAccept() methods and the visit() methods as the type of the data argument. |
|
visitorReturnType |
|
VISITOR_RETURN_TYPE (default: "Object") If this option is set, it is used in the signature of the generated jjtAccept() methods and the visit() methods as the return type of the method. |
|
visitorException |
|
VISITOR_EXCEPTION (default: "") If this option is set, it is used in the signature of the generated jjtAccept() methods and the visit() methods. |
|
args |
|
Additional command line arguments passed to jjTree |
Method |
Parameter |
Description |
addArg |
|
Add an additional command line argument passed to JavaCC |
addArgs |
|
Add additional command line arguments passed to JavaCC |
See here for details.
Copyright 2014-2019 Intershop Communications.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.