IntelliJ Platform Plugin SDK Help

Gradle Grammar-Kit Plugin

The Gradle Grammar-Kit Plugin automates generating lexers and parsers to support building custom language plugins for IntelliJ-based IDEs when using Grammar-Kit.

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 "2022.3.2.2" }
plugins { id "org.jetbrains.grammarkit" version "2022.3.2.2" }

Configuration

See also Usage Examples below.

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. In most cases, explicit configuration can be omitted.

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

The release version of the Grammar-Kit to use.

Type

String

Default value

2022.3.2

jflexRelease

The version of the IntelliJ-patched JFlex, a fork of JFlex lexer generator for IntelliJ Platform API.

Type

String

Default value

1.9.2

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.

Type

String

Default value

null

Tasks

generateLexer

The generateLexer task generates a lexer for the given grammar. The task is configured using common the grammarKit extension.

sourceFile

The source .*flex file to generate the lexer from.

Required

true

Type

String

targetDir

The path to the target directory for the generated lexer.

Required

true

Type

String

targetClass

The Java file name where the generated lexer will be written.

Required

true

Type

String

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.

Type

String

Default

null

purgeOldFiles

Purge old files from the target directory before generating the lexer.

Type

Boolean

Default

false

generateParser

The generateParser task generates a parser for the given grammar. The task is configured using the common grammarKit extension.

sourceFile

The source .bnf file to generate the parser from.

Required

true

Type

String

targetRoot

The path to the target directory for the generated parser.

Type

String

Default

null

pathToParser

The location of the generated parser class, relative to the targetRoot.

Required

true

Type

String

pathToPsiRoot

The location of the generated PSI files, relative to the targetRoot.

Required

true

Type

String

purgeOldFiles

Purge old files from the target directory before generating the parser.

Type

Boolean

Default

false

Usage Examples

Last modified: 09 January 2024