开发者

Using SBT 0.10.0 to generate source code with ANTLR3

开发者 https://www.devze.com 2023-03-12 13:54 出处:网络
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?

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

精彩评论

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

关注公众号