开发者

Using SBT 0.10.0 to generate source code with ANTLR3

How would I use the simple build tool (sbt) 0.10.0 to gener开发者_如何学Pythonate any kind of source code based on an ANTLR3 grammar?

I guess I have to use a plugin for something like this, if I want to use the generated code within the same project or a subproject of the same parent project. Are there any existing plugins for SBT 0.10? ...or maybe another solution without using a plugin?


You won't need to use a plugin.

First you will need to define antlr as a dependency. Then you will need to define your source generation task according to this page:

https://github.com/harrah/xsbt/wiki/Common-Tasks

Your task definition is going to look something like this:

sourceGenerators in Compile <+= sourceManaged in Compile map { dir =>
  <code to generate source from grammar files>
}

Where the code to generate your source will create a new org.antlr.Tool object with your files as an argument to the constructor. Once you have created a Tool object, then invoke the process method, and your source should be generated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜