Giter Club home page Giter Club logo

gradle-grammar-kit-plugin's Introduction

official JetBrains project Twitter Follow Build Slack

gradle-grammarkit-plugin

Important: This project requires Gradle 6.6 or newer, however it is recommended to use the latest Gradle available. Update it with:

./gradlew wrapper --gradle-version=VERSION

This Gradle plugin automates generating lexers and parsers to support custom language development in IntelliJ plugins when using Grammar-Kit.

NB: The plugin does not support two-pass generation. Therefore, it does not support method mixins.

Usage

Loading and applying the plugin

Groovybuild.gradle

plugins {
    id "org.jetbrains.grammarkit" version "..."
}

Kotlin DSLbuild.gradle.kts

plugins {
    id("org.jetbrains.grammarkit") version "..."
}

Note: The latest version is: Gradle Plugin Portal

Configuration

Global configuration allows you to select necessary JFlex and Grammar-Kit versions.

Groovybuild.gradle

grammarKit {
  // Version of IntelliJ patched JFlex (see the link below), Default is 1.7.0-1 
  jflexRelease = "1.7.0-1"

  // Release version, tag, or short commit hash of Grammar-Kit to use (see link below). By default, the latest available is used.
  grammarKitRelease = "2021.1.1"
  
  // Optionally provide an IntelliJ version to build the classpath for GenerateParser/GenerateLexer tasks
  intellijRelease = "203.7717.81"
}

Kotlin DSLbuild.gradle.kts

grammarKit {
  // Version of IntelliJ patched JFlex (see the link below), Default is 1.7.0-1 
  jflexRelease.set("1.7.0-1")

  // Release version, tag, or short commit hash of Grammar-Kit to use (see link below). Default is 2021.1.2
  grammarKitRelease.set("2021.1.2")

  // Optionally provide an IntelliJ version to build the classpath for GenerateParser/GenerateLexer tasks
  intellijRelease.set("203.7717.81")
}

Tasks

Generating lexer

Groovybuild.gradle

generateLexer {
    // source flex file
    source = "grammar/Perl.flex"
    
    // target directory for lexer
    targetDir = "gen/com/perl5/lang/perl/lexer/"
    
    // target classname, target file will be targetDir/targetClass.java
    targetClass = "PerlLexer"
    
    // optional, path to the task-specific skeleton file. Default: none
    skeleton = "/some/specific/skeleton"
    
    // if set, plugin will remove a lexer output file before generating new one. Default: false
    purgeOldFiles = true
}

Kotlin DSLbuild.gradle.kts

generateLexer {
    // source flex file
    source.set("grammar/Perl.flex")
    
    // target directory for lexer
    targetDir.set("gen/com/perl5/lang/perl/lexer/")
    
    // target classname, target file will be targetDir/targetClass.java
    targetClass.set("PerlLexer")
    
    // optional, path to the task-specific skeleton file. Default: none
    skeleton.set("/some/specific/skeleton")
    
    // if set, plugin will remove a lexer output file before generating new one. Default: false
    purgeOldFiles.set(true)
}

Generating parser

Groovybuild.gradle

generateParser {
    // source bnf file
    source = "grammar/Perl5.bnf"

    // optional, task-specific root for the generated files. Default: none
    targetRoot = "gen"

    // path to a parser file, relative to the targetRoot  
    pathToParser = "/com/perl5/lang/perl/parser/PerlParserGenerated.java"

    // path to a directory with generated psi files, relative to the targetRoot 
    pathToPsiRoot = "/com/perl5/lang/perl/psi"

    // if set, the plugin will remove a parser output file and psi output directory before generating new ones. Default: false
    purgeOldFiles = true
}

Kotlin DSLbuild.gradle.kts

generateParser {
    // source bnf file
    source.set("grammar/Perl5.bnf")

    // optional, task-specific root for the generated files. Default: none
    targetRoot.set("gen")

    // path to a parser file, relative to the targetRoot  
    pathToParser.set("/com/perl5/lang/perl/parser/PerlParserGenerated.java")

    // path to a directory with generated psi files, relative to the targetRoot 
    pathToPsiRoot.set("/com/perl5/lang/perl/psi")

    // if set, the plugin will remove a parser output file and psi output directory before generating new ones. Default: false
    purgeOldFiles.set(true)
}

Links

Usage examples

gradle-grammar-kit-plugin's People

Contributors

3flex avatar chris-laplante avatar dependabot[bot] avatar exidex avatar garyttierney avatar hsz avatar hurricup avatar matklad avatar mfilippov avatar trubitsyn avatar undin avatar yanncebron avatar yorlov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.