I changed these files to make it happen:
You can ignore the following files that I had to change because they are part of my test suite:
In general, these are the changes I had to make:
- StringTemplate -> ST
- StringTemplateGroup -> STGroup
- setAttribute() -> add()
- import org.antlr.stringtemplate.StringTemplate; ->
- anST.getInstanceOf() -> new ST(anST); the only difference here is that the v4 version copies all of the attributes from anST to the new one.
- references to $...$ become \<...>
- kill import org.antlr.stringtemplate.language.*;
- convert references to toString() to render(); note that there are a number of places that get toString() called implicitly. For example, in the ST.stg files, I converted replaceTextInLine() template to call render() explicitly:
- new StringTemplateGroup("<name>Templates", AngleBracketTemplateLexer.class) creates a named group; we don't name them in v4 so that becomes new STGroup().
So, in a nutshell, there are a few changes in one runtime support file for generating DOT from trees. All of the magic happens in the ST.stg file, if your target supports
output=template option. Here is a play-by-play:
- change the imports to the new package for ST
- change the members of a rules return scope to use ST not StringTemplate. Also change toString() method to call render.
- we need a blank library of templates to avoid a null pointer if someone forgets to set the library. change: to
- get rid of the definition of STAttrMap altogether; we don't need it anymore because ST.add() it allows us to chain calls to add multiple attributes as part of a single expression.
- the previous item lets us convert: to There are three methods like that.
If you look at an ST.stg difference, there's not much to do.