[antlr-interest] Token type as string

Adrian Herscu bmf1972 at fastmail.fm
Thu May 3 06:22:06 PDT 2007


Hi all,

I would like to write an XSL template to transform my AST.
I tried to serialize the AST as XML and I am getting something like:

<antlr.CommonAST text="compilation-unit" type="4">
   <antlr.CommonAST text="package" type="15">
     ...
   </antlr.CommonAST>
</antlr.CommonAST>

In order to apply an XSL transformation using matching templates, I am 
transforming the above into:

<compilation-unit>
   <package>
     ...
   </package>
</compilation-unit>

then I can bind XSL templates such as match="/compilation-unit", 
match="package", etc.

The problem is with AST nodes that have text content which cannot 
function as XML tags - for example:

<CommonAST text="123" type="14" />

In this case <123 /> is an illegal XML tag.
type="14" means that there is some token assigned the identifier 14.

If there would be some easy way to change the token type identifiers to 
strings or to add a string field associated with the token type then it 
would solve my problem really quick.

Is there such a thing? A better approach?

Adrian.



More information about the antlr-interest mailing list