2 Star 0 Fork 0

mirrors_javacc/javacc-gradle-plugin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

JavaCC Gradle Plugin

Note
Version 4 of this plugin will only work with Gradle 6 and JDK 8.

Summary

This plugin generates Java code from JavaCC and JJTree files. See Java Compiler Compiler tm (JavaCC tm) - The Java Parser Generator.

Usage

To apply the JavaCC Gradle Plugin to your projects, add the following in your build script:

Groovy
build.gradle
plugins {
    id 'com.intershop.gradle.javacc' version '4.0.0'
}

javacc {
    // configuration container for all javacc configurations
    configs {
        template {
            inputFile = file('jj/TemplateParser.jj')
            packageName = 'com.corporate.internal.parser'
            lookahead = '2'
        }
    }
}
Kotlin
build.gradle.kts
plugins {
    id("com.intershop.gradle.javacc") version "4.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 the version 4.2. It is possible to overwrite the project dependency configuration 'javacc', if you want use an other library for JavaCC code generation.

Tasks

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 code generation taks of a project. This tasks depends onl la

javacc<configuration name>

com.intershop.build.javacc.task.JavaCCTask

This task generates Java code for the specified configuration.

Project Extension 'javacc'

This plugin adds an extension javacc to the project.

Properties

Property

Type

Default value

Description

javaCCVersion

String

'4.2'

The version of JavaCC.

Methods

configs JavaCC This contains all Java code generation configurations.

Object 'javacc' (JavaCC)

Property Type Default value Description

outputDir

File

<project.buildDir>/generated/javacc/<config name>

Generated code will be written under this directory.

args

List<String>

Additional command line arguments passed to javaCC

sourceSetName

String

'main'

Generated source code will be added to the source set.

inputFile

File

The input jj-File for the code generation.

packageName

String

A special package name for the code generation. The output directory will be extended with this configuration.

The following variables are integer variables.

lookahead

int

LOOKAHEAD: The number of tokens to look ahead before making a decision at a choice point during parsing. The default value is 1.
The smaller this number, the faster the parser. This number may be overridden for specific productions within the grammar as described later.
See the description of the lookahead algorithm for complete details on how lookahead works.

choiceAmbiguityCheck

int

CHOICE_AMBIGUITY_CHECK: This is an integer option whose default value is 2.
This is the number of tokens considered in checking choices of the form "A | B | …​" for ambiguity.
For example, if there is a common two token prefix for both A and B, but no common three token prefix,
(assume this option is set to 3) then JavaCC can tell you to use a lookahead of 3 for disambiguation purposes.
And if A and B have a common three token prefix, then JavaCC only tell you that you need to have a lookahead of 3 or more.
Increasing this can give you more comprehensive ambiguity information at the cost of more processing time.
For large grammars such as the Java grammar, increasing this number any further causes the checking to take too much time.

otherAmbiguityCheck

int

OTHER_AMBIGUITY_CHECK: This is an integer option whose default value is 1.
This is the number of tokens considered in checking all other kinds of choices (i.e., of the forms "(A)*", "(A)+", and "(A)?")
for ambiguity. This takes more time to do than the choice checking, and hence the default value is set to 1 rather than 2.

The following variables will be interpreted as boolean.

staticParam

String

STATIC: This is a boolean option whose default value is true.
If true, all methods and class variables are specified as static in the generated parser and token manager.
This allows only one parser object to be present, but it improves the performance of the parser.
To perform multiple parses during one run of your Java program, you will have to call the ReInit()
method to reinitialize your parser if it is static. If the parser is non-static, you may use the "new" operator
to construct as many parsers as you wish. These can all be used simultaneously from different threads.

supportClassVisibilityPublic

String

SUPPORT_CLASS_VISIBILITY_PUBLIC: This is a boolean option whose default value is true.
The default action is to generate support classes (such as Token.java, ParseException.java etc) with Public visibility.
If set to false, the classes will be generated with package-private visibility.

debugParser

String

DEBUG_PARSER: This is a boolean option whose default value is false.
This option is used to obtain debugging information from the generated parser. Setting this option to true causes
the parser to generate a trace of its actions. Tracing may be disabled by calling the method disable_tracing()
in the generated parser class. Tracing may be subsequently enabled by calling the method enable_tracing() in the generated parser class.

debugLookahead

String

DEBUG_LOOKAHEAD: This is a boolean option whose default value is false.
Setting this option to true causes the parser to generate all the tracing information it does when the option
DEBUG_PARSER is true, and in addition, also causes it to generated a trace of actions performed during lookahead operation.

debugTokenManager

String

DEBUG_TOKEN_MANAGER: This is a boolean option whose default value is false.
This option is used to obtain debugging information from the generated token manager. Setting this option to true causes
the token manager to generate a trace of its actions. This trace is rather large and should only be used when you have a
lexical error that has been reported to you and you cannot understand why. Typically, in this situation, you can determine
the problem by looking at the last few lines of this trace.

errorReporting

String

ERROR_REPORTING: This is a boolean option whose default value is true.
Setting it to false causes errors due to parse errors to be reported in somewhat less detail. The only reason to set
this option to false is to improve performance.

javaUnicodeEscape

String

JAVA_UNICODE_ESCAPE: This is a boolean option whose default value is false.
When set to true, the generated parser uses an input stream object that processes Java Unicode escapes (\u…​) before
sending characters to the token manager. By default, Java Unicode escapes are not processed. This option is ignored if
either of options USER_TOKEN_MANAGER, USER_CHAR_STREAM is set to true.

unicodeInput

String

UNICODE_INPUT: This is a boolean option whose default value is false.
When set to true, the generated parser uses uses an input stream object that reads Unicode files. By default,
ASCII files are assumed. This option is ignored if either of options USER_TOKEN_MANAGER, USER_CHAR_STREAM is set to true.

ignoreCase

String

IGNORE_CASE: This is a boolean option whose default value is false.
Setting this option to true causes the generated token manager to ignore case in the token specifications and the input files.
This is useful for writing grammars for languages such as HTML. It is also possible to localize the effect of IGNORE_CASE
by using an alternate mechanism described later.

commonTokenAction

String

COMMON_TOKEN_ACTION: This is a boolean option whose default value is false.
When set to true, every call to the token manager’s method "getNextToken" (see the description of the Java Compiler Compiler API)
will cause a call to a used defined method "CommonTokenAction" after the token has been scanned in by the token manager.
The user must define this method within the TOKEN_MGR_DECLS section. The signature of this method is: void CommonTokenAction(Token t)

userTokenManager

String

USER_TOKEN_MANAGER: This is a boolean option whose default value is false.
The default action is to generate a token manager that works on the specified grammar tokens. If this option is set
to true, then the parser is generated to accept tokens from any token manager of type "TokenManager" - this interface
is generated into the generated parser directory.

userCharStream

String

USER_CHAR_STREAM: This is a boolean option whose default value is false.
The default action is to generate a character stream reader as specified by the options JAVA_UNICODE_ESCAPE and UNICODE_INPUT.
The generated token manager receives characters from this stream reader. If this option is set to true, then the token manager
is generated to read characters from any character stream reader of type "CharStream.java". This file is generated into the
generated parser directory. This option is ignored if USER_TOKEN_MANAGER is set to true.

buildParser

String

BUILD_PARSER: This is a boolean option whose default value is true.
The default action is to generate the parser file ("MyParser.java" in the above example). When set to false, the parser
file is not generated. Typically, this option is set to false when you wish to generate only the token manager and use
it without the associated parser.

buildTokenManager

String

BUILD_TOKEN_MANAGER: This is a boolean option whose default value is true.
The default action is to generate the token manager file ("MyParserTokenManager.java" in the above example).
When set to false the token manager file is not generated. The only reason to set this option to false is to save
some time during parser generation when you fix problems in the parser part of the grammar file and leave the lexical
specifications untouched.

tokenManagerUsesParser

String

TOKEN_MANAGER_USES_PARSER: This is a boolean option whose default value is false.
When set to true, the generated token manager will include a field called parser that references the instantiating parser
instance (of type MyParser in the above example). The main reason for having a parser in a token manager is using some of
its logic in lexical actions. This option has no effect if the STATIC option is set to true.

sanityCheck

String

SANITY_CHECK: This is a boolean option whose default value is true.
JavaCC performs many syntactic and semantic checks on the grammar file during parser generation. Some checks such as
detection of left recursion, detection of ambiguity, and bad usage of empty expansions may be suppressed for faster
parser generation by setting this option to false. Note that the presence of these errors (even if they are not detected
and reported by setting this option to false) can cause unexpected behavior from the generated parser.

forceLaCheck

String

FORCE_LA_CHECK: This is a boolean option whose default value is false.
This option setting controls lookahead ambiguity checking performed by JavaCC. By default (when this option is false),
lookahead ambiguity checking is performed for all choice points where the default lookahead of 1 is used. Lookahead
ambiguity checking is not performed at choice points where there is an explicit lookahead specification, or if the option
LOOKAHEAD is set to something other than 1. Setting this option to true performs lookahead ambiguity checking at all choice
points regardless of the lookahead specifications in the grammar file.

cacheTokens

String

CACHE_TOKENS: This is a boolean option whose default value is false.
Setting this option to true causes the generated parser to lookahead for extra tokens ahead of time. This facilitates
some performance improvements. However, in this case (when the option is true), interactive applications may not work
since the parser needs to work synchronously with the availability of tokens from the input stream. In such cases, it’s
best to leave this option at its default value.

keepLineColumn

String

KEEP_LINE_COLUMN: This is a boolean option whose default value is true.
If you set this option to false, the generated CharStream will not have any line/column tracking code. It will be your
responsibility to do it some other way. This is needed for systems which don’t care about giving error messages etc.

The following variables will be interpreted as string.

tokenExtends

String

TOKEN_EXTENDS: This is a string option whose default value is "", meaning that the generated Token class will extend java.lang.Object.
This option may be set to the name of a class that will be used as the base class for the generated Token class.

tokenFactory

String

TOKEN_FACTORY: This is a string option whose default value is "", meaning that Tokens will be created by calling Token.newToken().
If set the option names a Token factory class containing a public static Token newToken(int ofKind, String image) method.

jdkVersion

String

JDK_VERSION: This is a string option whose default value is "1.4"

Method

Parameter

Description

addArg

String

Add an additional command line argument passed to JavaCC

addArgs

List<String>

Add additional command line arguments passed to JavaCC

Closure Parameter Description

jjtree

JJTree

Add an additional configuration for JJTree

Object 'jjtree' (JJTree)

Property

Type

Default value

Description

The following variables will be interpreted as boolean.

multi

String

MULTI (default: false) Generate a multi mode parse tree. The default for this is false, generating a simple mode parse tree.

nodeDefaultVoid

String

NODE_DEFAULT_VOID (default: false) Instead of making each non-decorated production an indefinite node, make it void instead.

nodeScopeHook

String

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

String

NODE_USES_PARSER (default: false)JJTree will use an alternate form of the node construction routines where it passes the parser object in.
For example,
public static Node MyNode.jjtCreate(MyParser p, int id);
MyNode(MyParser p, int id);

buildNodeFiles

String

BUILD_NODE_FILES (default: true) Generate sample implementations for SimpleNode and any other nodes used in the grammar.

staticParam

String

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.
The value of this option is emitted in the JavaCC source.

trackTokens

String

TRACK_TOKENS (default: false) Insert jjtGetFirstToken(), jjtSetFirstToken(), getLastToken(), and jjtSetLastToken() methods in SimpleNode.
The FirstToken is automatically set up on entry to a node scope; the LastToken is automatically set up on exit from a node scope.

visitor

String

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

String

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

String

'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

String

NODE_PACKAGE (default: "") The package to generate the node classes into. The default for this is the parser package.

nodeExtends

String

NODE_EXTENDS (default: "") Deprecated
The superclass for the SimpleNode class. By providing a custom superclass you
may be able to avoid the need to edit the generated SimpleNode.java.

nodeFactory

String

NODE_FACTORY (default: "") Specify a class containing a factory method with following signature to construct nodes: public static Node jjtCreate(int id)
For backwards compatibility, the value false may also be specified, meaning that SimpleNode will be used as the factory class.

visitorDataType

String

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

String

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

String

VISITOR_EXCEPTION (default: "") If this option is set, it is used in the signature of the generated jjtAccept() methods and the visit() methods.

args

List<String>

Additional command line arguments passed to jjTree

Method

Parameter

Description

addArg

String

Add an additional command line argument passed to JavaCC

addArgs

List<String>

Add additional command line arguments passed to JavaCC

Add additional Java VM settings for process runner

tasks.withType(com.intershop.gradle.javacc.task.JavaCCTask) {
    forkOptions { JavaForkOptions options ->
        options.setMaxHeapSize('64m')
        options.jvmArgs += ['-Dhttp.proxyHost=10.0.0.100', '-Dhttp.proxyPort=8800']
    }
}

License

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.

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: a. You must give any other recipients of the Work or Derivative Works a copy of this License; and b. You must cause any modified files to carry prominent notices stating that You changed the files; and c. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and d. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS

简介

暂无描述 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_javacc/javacc-gradle-plugin.git
git@gitee.com:mirrors_javacc/javacc-gradle-plugin.git
mirrors_javacc
javacc-gradle-plugin
javacc-gradle-plugin
master

搜索帮助