Giter Site home page Giter Site logo

sbt-antlr4's Introduction

sbt-antlr4

Build Status

This plugin provides an ability to run antlr4 when compiling in sbt 1.1.x and 0.13.x.

How to use

Put your .g4 files in src/main/antlr4 directory and make project/sbt-antlr4.sbt file with the following contents:

// sbt 1.1.x
addSbtPlugin("com.simplytyped" % "sbt-antlr4" % "0.8.3")

// sbt 0.13.x
addSbtPlugin("com.simplytyped" % "sbt-antlr4" % "0.7.13")

And, enable the plugin in your build.sbt file.

// sbt 1.1.x
enablePlugins(Antlr4Plugin)

// sbt 0.13.x
antlr4Settings

Now, whenever you invoke sbt compile the ANTLR artifacts will be written to ./target/scala-XX.YY/sources_managed/main/antlr4 (depending on your Scala version).

Settings

You can select an antl4 version with:

antlr4Version in Antlr4 := "4.8-1" // default: 4.8-1

-package option can be defined by the following setting:

antlr4PackageName in Antlr4 := Some("com.simplytyped")

You can also adjust -listener, -no-listener, -visitor, -no-visitor, -Werror options:

antlr4GenListener in Antlr4 := true // default: true

antlr4GenVisitor in Antlr4 := false // default: false

antlr4TreatWarningsAsErrors in Antlr4 := true // default: false

License

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

http://www.apache.org/licenses/LICENSE-2.0

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.

sbt-antlr4's People

Contributors

dilipbiswal avatar dispalt avatar ihji avatar jaa127 avatar jooyunghan avatar marconilanna avatar rbergm avatar thetristan avatar xuwei-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sbt-antlr4's Issues

Invalid instructions

I set up your plugin, But I got

/Users/arunavs/Modulo12/build.sbt:15: error: type mismatch;
 found   : sbt.internal.DslEntry
 required: sbt.Def.SettingsDefinition
    enablePlugins(Antlr4Plugin),

Please provide proper instructions for setting up and preferably a sample project actually setting this up.

Infer package name from file location

Instead of specify package name parameter, infer the package name from the file path, as src/main/antlr4/org/sample/grammar.g4 generates package name org.sample

sbt 1.0.0 compatible plugin

Are there any plans to release an sbt 1.0.0 compatible plugin?
This plugin is used by the Apache Spark build.

incompatibility with sbt 1.1.0: A named attribute key must start with a lowercase letter

full stacktrace:

java.lang.IllegalArgumentException: requirement failed: A named attribute key must start with a lowercase letter: Build dependency required for parsing grammars, scoped to plugin
[error]         at scala.Predef$.require(Predef.scala:277)
[error]         at sbt.internal.util.AttributeKey$$anon$1.<init>(Attributes.scala:102)
[error]         at sbt.internal.util.AttributeKey$.make(Attributes.scala:98)
[error]         at sbt.internal.util.AttributeKey$.apply(Attributes.scala:87)
[error]         at sbt.internal.util.AttributeKey$.apply(Attributes.scala:76)
[error]         at sbt.SettingKey$.apply(Structure.scala:673)
[error]         at com.simplytyped.Antlr4Plugin$.<init>(Antlr4Plugin.scala:22)
[error]         at com.simplytyped.Antlr4Plugin$.<clinit>(Antlr4Plugin.scala)

The error doesn't quite make sense to me, since the SettingKey antlr4BuildDependency does start with a lowercase letter. Any ideas?

bintray is deprecated, plugin is not (always) downloadable

First, thanks for useful plugin!

It's not downloadable from bintray right now (Apr 12).

See
https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/

April 12th, 26th, 2021 - We will have some short service brown-outs to remind users about the services that are going away on May 1st. (Specific hours will be advertised in the Bintray status page.)

This is an error I am getting:

download error: Caught java.io.IOException: Server returned HTTP response code: 502 for URL: https://dl.bintray.com/sbt/sbt-plugin-releases/com.simplytyped/sbt-antlr4/scala_2.12/sbt_1.0/0.8.3/ivys/ivy.xml (Server returned HTTP response code: 502 for URL: https://dl.bintray.com/sbt/sbt-plugin-releases/com.simplytyped/sbt-antlr4/scala_2.12/sbt_1.0/0.8.3/ivys/ivy.xml) while downloading https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.simplytyped/sbt-antlr4/scala_2.12/sbt_1.0/0.8.3/ivys/ivy.xml

Not all the command line options are exposed through the plugin.

Here are the lists of command line options.

$ antlr4
ANTLR Parser Generator Version 4.0b3
-o <arg>                specify output directory where all output is generated
-lib <arg>              specify location of grammars, tokens files
-atn                    generate rule augmented transition network diagrams
-encoding <arg>         specify grammar file encoding; e.g., euc-jp
-message-format <arg>   specify output style for messages in antlr, gnu, vs2005
-listener               generate parse tree listener (default)
-no-listener            don't generate parse tree listener
-visitor                generate parse tree visitor
-no-visitor             don't generate parse tree visitor (default)
-package <arg>          specify a package/namespace for the generated code
-depend                 generate file dependencies
-D<option>=value        set/override a grammar-level option
-Werror                 treat warnings as errors
-Xsave-lexer            save temp lexer file created for combined grammars
-XdbgST                 launch StringTemplate visualizer on generated code
-Xforce-atn             use the ATN simulator for all predictions
-Xlog                   dump lots of logging info to antlr-timestamp.log
-XdbgSTWait             wait for STViz to close before continuing

I want to be able to turn warnings to errors while generating parser. But that option is not exposed through the plugin ? The maven plugin for antlr4 allows us to do that.

cc @ihji

consider not adding antlr4 generated files to `managedSourceDirectories`

It looks to me like adding the antlr specific sources to sbt's managedSourceDirectories (https://github.com/ihji/sbt-antlr4/blob/3d36e6c/src/main/scala/com/simplytyped/Antlr4Plugin.scala#L80) isn't a good idea, since sbt already has the root directory src_managed in the classpath (tested only with sbt 1.0.3). The resulting classpath contains the antlr generated sources twice then: src_managed and src_managed/antlr4.

While sbt deals with that fine, Intellij compiles the classes twice and fails, complaining about "duplicate classes".

Changing this might be a can of worms though, and I haven't tested the zoo of different sbt versions and IDEs. Maybe it's best to just add a note in the readme? You probably know this topic better than me - what's your thoughts?

Am I missing something because it does not generate anything?

I have setup my sbt file as described in the readme. However, when I do sbt clean compile I get the following output. Please note that I don't see anywhere it logging anything about "antlr". Understandingly enough, my code in src/main/antlr directory isn't getting generated. Almost looks like it doesn't know where the file is..?

[info] Loading global plugins from /Users/mm00180/.sbt/1.0/plugins
[info] Loading project definition from /Users/mm00180/Documents/projects/streaming-team/streaming-platform/project/project
[info] Loading settings from plugins.sbt ...
[info] Loading project definition from /Users/mm00180/Documents/projects/streaming-team/streaming-platform/project
[info] Loading settings from sonatype.sbt,build.sbt ...
[info] Set current project to root (in build file:/Users/mm00180/Documents/projects/streaming-team/streaming-platform/)
[info] Executing in batch mode. For better performance use sbt's shell
[success] Total time: 0 s, completed Dec 3, 2020, 12:33:42 PM
[info] Updating ...
[info] Updating schemaManager...
[info] Done updating.
[info] Done updating.
[warn] Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
[warn]  * org.json4s:json4s-native_2.12:3.6.10 is selected over 3.2.11
[warn]      +- com.sksamuel.avro4s:avro4s-core_2.12:4.0.1         (depends on 3.6.10)
[warn]      +- com.github.massmutual.streaming:schemamanager_2.12:0.1.0-SNAPSHOT (depends on 3.2.11)
[warn]  * com.google.guava:guava:28.1-android is selected over {20.0, 27.0.1-android}
[warn]      +- com.google.protobuf:protobuf-java-util:3.11.4      (depends on 28.1-android)
[warn]      +- io.swagger:swagger-core:1.6.0                      (depends on 27.0.1-android)
[warn]      +- com.fasterxml.jackson.datatype:jackson-datatype-guava:2.10.2 (depends on 20.0)
[warn]      +- com.squareup.wire:wire-schema:3.2.2                (depends on 20.0)
[warn] Run 'evicted' to see detailed eviction warnings
[info] Compiling 4 protobuf files to /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/scala-2.12/src_managed/main
[info] Compiling schema /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/main/protobuf/myRecord.proto
[info] Compiling schema /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/main/protobuf/myRecord_v3.proto
[info] Compiling schema /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/main/protobuf/myRecord_v2.proto
[info] Compiling schema /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/main/protobuf/myRecord_v4.proto
protoc-jar: protoc version: 3.7.1, detected platform: osx-x86_64 (mac os x/x86_64)
[info] Considering source directories /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/test/avro
[info] Compiling AVSC /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/test/avro/orderEventSchema_v5.avsc to /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/scala-2.12/src_managed/test/compiled_avro
protoc-jar: embedded: bin/3.7.1/protoc-3.7.1-osx-x86_64.exe
protoc-jar: executing: [/var/folders/n2/typ8xbq15yxf0gvrn5q756w80000gp/T/protocjar15936569676654868411/bin/protoc.exe, --java_out=:/Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/scala-2.12/src_managed/main, -I/Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/main/protobuf, -I/Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/protobuf_external, -I/Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/main/protobuf, -I/Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/protobuf_external, /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/main/protobuf/myRecord.proto, /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/main/protobuf/myRecord_v3.proto, /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/main/protobuf/myRecord_v2.proto, /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/main/protobuf/myRecord_v4.proto]
/Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/protobuf_external: warning: directory does not exist.
/Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/protobuf_external: warning: directory does not exist.
[info] Compiling protobuf
[info] Protoc target directory: /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/scala-2.12/src_managed/main
[info] Compiling AVSC /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/test/avro/orderEventSchema_v4.avsc to /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/scala-2.12/src_managed/test/compiled_avro
[info] Compiling AVSC /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/test/avro/orderEventSchema_v3.avsc to /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/scala-2.12/src_managed/test/compiled_avro
[info] Compiling AVSC /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/test/avro/orderEventSchema_v2.avsc to /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/scala-2.12/src_managed/test/compiled_avro
[info] Compiling AVSC /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/src/test/avro/orderEventSchema.avsc to /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/scala-2.12/src_managed/test/compiled_avro
[info] Compiling 11 Scala sources and 11 Java sources to /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/scala-2.12/classes ...
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by sbt.internal.inc.javac.DiagnosticsReporter$PositionImpl$ (file:/Users/mm00180/.sbt/boot/scala-2.12.6/org.scala-sbt/sbt/1.1.6/zinc-compile-core_2.12-1.1.7.jar) to field com.sun.tools.javac.api.ClientCodeWrapper$DiagnosticSourceUnwrapper.d
WARNING: Please consider reporting this to the maintainers of sbt.internal.inc.javac.DiagnosticsReporter$PositionImpl$
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[info] /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/scala-2.12/src_managed/main/com/github/massmutual/streaming/schemamanager/MyRecord.java: Some input files use or override a deprecated API.
[info] /Users/mm00180/Documents/projects/streaming-team/streaming-platform/modules/SchemaManager/target/scala-2.12/src_managed/main/com/github/massmutual/streaming/schemamanager/MyRecord.java: Recompile with -Xlint:deprecation for details.
[info] Done compiling.
[success] Total time: 12 s, completed Dec 3, 2020, 12:33:55 PM

My build.sbt looks like this. Am I missing something?

lazy val schemaManager = (project in file("modules/SchemaManager"))
  .settings(
    settings,
    name := "SchemaManager",
    libraryDependencies ++= {
      commonDependencies ++ schemaManagerDeps
    },
    PB.targets in Compile := Seq(
      PB.gens.java -> (sourceManaged in Compile).value
    ),
   // PB.protoSources in Compile := Seq(sourceDirectory.value / "protobuf"),
    sourceGenerators in Compile += (avroScalaGenerateSpecific in Compile).taskValue,
    sourceGenerators in Compile += (avroScalaGenerateSpecific in Test).taskValue,
    antlr4PackageName in Antlr4 := Some("com.github.massmutual.streaming.schemamanager.integration"),
    antlr4Version in Antlr4 := "4.8-1",
    //    unmanagedResourceDirectories in Compile += (sourceDirectory in ProtobufConfig).value

  )
//finally just aggregate all the child modules into root
lazy val root = (project in file("."))
  .enablePlugins(JavaAppPackaging)
  .enablePlugins(DockerPlugin)
  .enablePlugins(ClasspathJarPlugin)
  .enablePlugins(ProtobufPlugin)
  .enablePlugins(Antlr4Plugin)
  .aggregate(schemaManager)
  .settings(settings)

sbt.version = 1.1.6

Support for grun

I'd like to test the generated parser using grun aka org.antlr.v4.gui.TestRig. Amongst other things it provides a simple GUI:

Grun GUI

This is probably trivial to do if the example on the ANTLR website is anything to go by:

$ antlr4 Expr.g4
$ javac Expr*.java
$ grun Expr prog -gui
100+2*34
^D

How about adding a task "grun" or perhaps run in Antlr4 or test in Antlr4 that starts grun? Thoughts?

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.