6.3 KiB
The Gradle Grammar-Kit Plugin automates generating lexers and parsers to support building custom language plugins for IntelliJ-based IDEs when using Grammar-Kit.
{style="note"}
The plugin does not support two-pass generation. Therefore, it does not support method mixins.
Usage
To enable this plugin in your Gradle-based project, register the plugin in the Gradle build script's plugins
section:
plugins {
id("org.jetbrains.grammarkit") version "..."
}
plugins {
id "org.jetbrains.grammarkit" version "..."
}
This project requires
Gradle 6.8
or newer, however it is recommended to use the latest Gradle available. Update it with:./gradlew wrapper --gradle-version=VERSION
See also: Gradle Installation guide.
Please see CONTRIBUTING on how to submit feedback and contribute to this project.
Before visiting the Issue Tracker, update both plugin and Gradle to the latest versions.
Configuration
Grammar-Kit Extension
After the Gradle Grammar-Kit Plugin is applied, the grammarKit
extension can be used to configure the plugin and common settings of the provided tasks.
Example:
grammarKit {
jflexRelease.set("1.7.0-1")
grammarKitRelease.set("2021.1.2")
intellijRelease.set("203.7717.81")
}
grammarKit {
jflexRelease = "1.7.0-1"
grammarKitRelease = "2021.1.2"
intellijRelease = "203.7717.81"
}
grammarKitRelease
{id="grammar-kit-extension-grammarkitrelease"}
The release version of the Grammar-Kit to use.
- {style="narrow"}
- Type
String
- Default value
2021.1.2
jflexRelease
{id="grammar-kit-extension-jflexrelease"}
The version of the IntelliJ-patched JFlex, a fork of JFlex lexer generator for IntelliJ Platform API.
- {style="narrow"}
- Type
String
- Default value
1.7.0-1
intellijRelease
{id="grammar-kit-extension-intellijrelease"}
An optional IntelliJ version to build the classpath for GenerateParser
and GenerateLexer
tasks.
If provided, grammarKitRelease
and jflexRelease
properties are ignored as both dependencies will be provided from the given IntelliJ IDEA release.
- {style="narrow"}
- Type
String
- Default value
null
Tasks
generateLexer
{id="generatelexer-task"}
The generateLexer
task generates a lexer for the given grammar.
The task is configured using common grammarKit
extension.
source
{id="tasks-generatelexer-source"}
The source Flex file to generate the lexer from.
- {style="narrow"}
- Required
true
- Type
String
targetDir
{id="tasks-generatelexer-targetdir"}
The path to the target directory for the generated lexer.
- {style="narrow"}
- Required
true
- Type
String
targetClass
{id="tasks-generatelexer-targetclass"}
The Java file name where the generated lexer will be written.
- {style="narrow"}
- Required
true
- Type
String
skeleton
{id="tasks-generatelexer-skeleton"}
An optional path to the skeleton file to use for the generated lexer.
The path will be provided as --skel
option.
By default, it uses the idea-flex.skeleton skeleton file.
- {style="narrow"}
- Type
String
- Default
null
purgeOldFiles
{id="tasks-generatelexer-purgeoldfiles"}
Purge old files from the target directory before generating the lexer.
- {style="narrow"}
- Type
Boolean
- Default
false
generateParser
{id="generateparser-task"}
The generateParser
task generates a parser for the given grammar.
The task is configured using common grammarKit
extension.
source
{id="tasks-generateparser-source"}
The source BNF file to generate the parser from.
- {style="narrow"}
- Required
true
- Type
String
targetRoot
{id="tasks-generateparser-targetroot"}
The path to the target directory for the generated parser.
- {style="narrow"}
- Type
String
- Default
null
pathToParser
{id="tasks-generateparser-pathtoparser"}
The location of the generated parser class, relative to the targetRoot
.
- {style="narrow"}
- Required
true
- Type
String
pathToPsiRoot
{id="tasks-generateparser-pathtopsiroot"}
The location of the generated PSI files, relative to the targetRoot
.
- {style="narrow"}
- Required
true
- Type
String
purgeOldFiles
{id="tasks-generateparser-purgeoldfiles"}
Purge old files from the target directory before generating the parser.
- {style="narrow"}
- Type
Boolean
- Default
false