ihji / sbt-antlr4 Goto Github PK
View Code? Open in Web Editor NEWAntlr4 plugin for sbt 1.1+ and 0.13.x
Antlr4 plugin for sbt 1.1+ and 0.13.x
disregard im dumb
README.md specifies
resolvers += "simplytyped" at "http://simplytyped.github.io/repo/releases"
however, this returns a 404
I noticed that ANTLR 4.5.1 is out now.
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?
The latest version of ANTLR is 4.8, released January 16, 2020.
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
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?
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.
Are there any plans to release an sbt 1.0.0 compatible plugin?
This plugin is used by the Apache Spark build.
I'd like to test the generated parser using grun aka org.antlr.v4.gui.TestRig
. Amongst other things it provides a simple 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?
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
I've installed sbt-antlr4 in sbt, when I executed sbt compile
, antlr4 parser java code didn't get generated
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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.