Combining Antlr 3.5.2 with StringTemplate 4 for co

2019-08-14 21:08发布

问题:

Current project I'm working on is limited to using antlr 3.5.2, but I would like to use the featureset of StringTemplate 4 for our code generation. Can antlr 3.5.2 generate a java treewalker that uses StringTemplate 4? (e.g. a tree grammer with output=template that results in a java file with ST* references instead of StringTemplate*)

回答1:

The output=template option only supports StringTemplate 3. You can still support StringTemplate 4, but it would require using embedded actions or a hand-written walker similar to the ones ANTLR 4 generates automatically.

The ANTLR 4 tool itself uses the second option.