I changed these files to make it happen:
tool/src/main/resources/org/antlr/codegen/templates/Java/ST.stg
runtime/Java/src/main/java/org/antlr/runtime/tree/DOTTreeGenerator.java
You can ignore the following files that I had to change because they are part of my test suite:
tool/src/test/java/org/antlr/test/BaseTest.java
tool/src/test/java/org/antlr/test/TestRewriteTemplates.java
tool/src/test/java/org/antlr/test/TestTemplates.java
tool/src/test/java/org/antlr/test/TestTreeParsing.java
In general, these are the changes I had to make:
((TokenRewriteStream)input).replace( ((Token)retval.start).getTokenIndex(), input.LT(-1).getTokenIndex(), retval.st.render()); <--------------- was just retval.st |
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:
protected StringTemplateGroup templateLib = new StringTemplateGroup("<name>Templates", AngleBracketTemplateLexer.class); |
protected STGroup templateLib = new STGroup(); |
rewriteExternalTemplate(name,args) ::= << templateLib.getInstanceOf("<name>"<if(args)>, new STAttrMap()<args:{a | .put("<a.name>", <a.value>)}> <endif>) >> |
rewriteExternalTemplate(name,args) ::= << templateLib.getInstanceOf("<name>") <if(args)><args:{a | .add("<a.name>", <a.value>)}><endif> >> |
If you look at an ST.stg difference, there's not much to do.