A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Strumenta/antlr-kotlin below:

Strumenta/antlr-kotlin: Support for Kotlin as a target for ANTLR 4

This project contains everything needed to support Kotlin as a target for ANTLR.

This being a fully multiplatform project, the code written using the Kotlin target for ANTLR will run on the JVM (including Android), in the browser, in Node.js, and natively on Mac, Windows, and Linux.

Want to start experimenting immediately? See Gradle Setup.

The runtime and target's template are up-to-date with mainstream commit: master/e9df464

The Kotlin target is a plugin for the ANTLR generator.

It should be added to the classpath used to run the ANTLR Tool.

You will need to specify the target language to be Kotlin (-Dlanguage=Kotlin), or use the com.strumenta.antlr-kotlin plugin, which instructs ANTLR automatically.

The Kotlin runtime for the Kotlin target is derived from the Java runtime, and is built as a multiplatform project running on JVM, JS, WebAssembly (including WASI), and Native.

Warning

The Kotlin ANTLR runtime is not thread safe

The supported Native platforms are:

Tier 1 Tier 2 Tier 3 macosX64 linuxX64 androidNativeArm32 macosArm64 linuxArm64 androidNativeArm64 iosSimulatorArm64 watchosSimulatorArm64 androidNativeX86 iosX64 watchosX64 androidNativeX64 watchosArm32 watchosDeviceArm64 watchosArm64 mingwX64 tvosSimulatorArm64 linuxArm32Hfp tvosX64 tvosArm64 iosArm64

Note

The linuxArm32Hfp platform is deprecated

To start using ANTLR Kotlin:

  1. Add the mavenCentral repository to the list of repositories in your build script. This is required as artifacts are pushed to Maven Central.

    repositories {
      mavenCentral()
    }
  2. Add the ANTLR Gradle plugin for the Kotlin target to the list of plugins in your build script.

    plugins {
      id("com.strumenta.antlr-kotlin") version "$antlrKotlinVersion"
    }
  3. Add the ANTLR Kotlin Runtime to the list of dependencies. If you are working in a multiplatform project, add it to the common source set.

    kotlin {
      sourceSets {
        commonMain {
          dependencies {
            implementation("com.strumenta:antlr-kotlin-runtime:$antlrKotlinVersion")
          }
        }
      }
    }
  4. Register the ANTLR Kotlin grammar generation task.

    val generateKotlinGrammarSource = tasks.register<AntlrKotlinTask>("generateKotlinGrammarSource") {
      dependsOn("cleanGenerateKotlinGrammarSource")
    
      // ANTLR .g4 files are under {example-project}/antlr
      // Only include *.g4 files. This allows tools (e.g., IDE plugins)
      // to generate temporary files inside the base path
      source = fileTree(layout.projectDirectory.dir("antlr")) {
        include("**/*.g4")
      }
    
      // We want the generated source files to have this package name
      val pkgName = "com.strumenta.antlrkotlin.parsers.generated"
      packageName = pkgName
    
      // We want visitors alongside listeners.
      // The Kotlin target language is implicit, as is the file encoding (UTF-8)
      arguments = listOf("-visitor")
    
      // Generated files are outputted inside build/generatedAntlr/{package-name}
      val outDir = "generatedAntlr/${pkgName.replace(".", "/")}"
      outputDirectory = layout.buildDirectory.dir(outDir).get().asFile
    }

    Depending on cleanGenerateKotlinGrammarSource ensures the .tokens files are always fresh, and we do not end up with out-of-sync lexers and parsers.

  5. Specify that the output directory of the generateKotlinGrammarSource task should be included as a source directory in the commonMain source set. In Gradle, you can do that by simply reference the task itself, and Gradle will automatically infer the associated output directory and include such directory in the source set.

    kotlin {
      sourceSets {
        commonMain {
          kotlin {
            srcDir(generateKotlinGrammarSource)
          }
          ...
        }
      }
    }

The antlr-kotlin-benchmarks module contains benchmarking code for JVM, JS, WebAssembly and Native targets.

The benchmark scenario has been adapted from antlr4ng.
To run benchmarks, use:

./gradlew :antlr-kotlin-benchmarks:jvmBenchmark

or

./gradlew :antlr-kotlin-benchmarks:jsBenchmark

or

./gradlew :antlr-kotlin-benchmarks:wasmJsBenchmark

or

./gradlew :antlr-kotlin-benchmarks:mingwX64Benchmark
Maven Central Publication

Publication can be performed running:

./gradlew publishAllPublicationsToMavenCentralRepository --no-configuration-cache

However, it is recommended to use the releases plugin and run:

You can see the complete list on GitHub, but here we list those who contributed ten commits or more.

Consumers of this project may choose the most appropriate license: either the Apache License 2.0, or the 3-Clause BSD License.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4