sbt 和 antlr,有简单的例子吗? [英] sbt and antlr, got simple example?

查看:61
本文介绍了sbt 和 antlr,有简单的例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有一个例子来说明如何设置 sbt 来构建一个 ANTLR 文件(到 scala),然后编译生成的代码.

Does anyone have an example of how to set up sbt to build an ANTLR file (to scala) and then compile the resulting code.

我的文件布局

 src/main/scala/Test.scala     // scala test rig
 src/main/scala/Test.g         // antlr grammar

 build/antlr/TestParser.scala  // antlr output files
 build/antlr/TestLexer.scala

我的 sbt 应该包含什么?我知道有一个插件可以为 ANTLR 引入规则,但我一直无法让它发挥作用.(还是这个世界的新手)

What should my sbt contain? I know there's a plugin out there for pulling in the rules for ANTLR, but I haven't been able to make it work. (Still newbie to this world)

推荐答案

我编写了一个 sbt 插件来从提供的 antlr 语法文件生成解析器和词法分析器代码.你可以在我的 github 页面下载代码 http://github.com/stefri/sbt-antlr.它也列在 sbt 插件列表 https://github.com/harrah/xsbt/wiki/sbt-0.10-plugins-list.最新的快照使用 ANTLR 3.3,可通过我的 github maven 存储库获取 sbt 0.11.x 系列.如果您需要另一个 ANTLR 版本,更改和重建很容易,我仍在研究配置选项.

I've written a sbt plugin to generate the parser and lexer code from a provided antlr grammer file. You can download the code on my github page http://github.com/stefri/sbt-antlr. It's also listed in the sbt plugin list https://github.com/harrah/xsbt/wiki/sbt-0.10-plugins-list. The latest snapshot uses ANTLR 3.3 and is available via my github maven repository for the sbt 0.11.x series. If you need another ANTLR version it's easy to change and rebuild, I'm still working on the configuration options.

用法很简单,只需在./project/plugins/build.sbt

resolvers += "stefri" at "http://stefri.github.com/repo/snapshots"

addSbtPlugin("com.github.stefri" % "sbt-antlr" % "0.2-SNAPSHOT")

然后将您的 ANTLR3 语法文件放在 src/main/antlr3 中.他们会包含在您的下一个构建中.

then place your ANTLR3 grammar files in src/main/antlr3. They will be included in your next build.

确保您的项目设置中还包含插件设置 sbtantlr.SbtAntlrPlugin.antlrSettings,例如,如果您使用的是简单配置方法,请添加以下行

Make sure you also include the plugins settings sbtantlr.SbtAntlrPlugin.antlrSettings in your project settings, e.g if you are using the simple configuration approach add the following line

seq(sbtantlr.SbtAntlrPlugin.antlrSettings: _*)

到您的 build.sbt 文件.注意,sbt-antlr 只生成一次源代码,只要你的语法文件没有改变它就不会重新生成java源文件.

to your build.sbt file. Note, sbt-antlr generates the source code only once as long as your grammar file didn't change it does not re-generate the java source files.

生成的 java 文件会输出到 target/scala-2.9.1/src_managed/main/antlr3,因此请确保在 IDE 的构建路径中包含该路径.该插件仍在开发中,但它已经非常适合我的语法.

The generated java files are spit out to target/scala-2.9.1/src_managed/main/antlr3, so make sure you inlcude that path in your IDE's build path. The plugin is still work in progress, but it already works quite nice with my grammars.

这篇关于sbt 和 antlr,有简单的例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆