[antlr-interest] Tree construction

Gavin Lambert antlr at mirality.co.nz
Mon Jul 2 05:16:27 PDT 2007

At 23:04 2/07/2007, Ruth Karl wrote:
 >One of those rules looks like this:
 >    htmltag  :  OPENTAG (SLASH)? ((text | bracketexpr |
 >                quoted | scriptlet)+ (PERCENT)* )* CLOSETAG ;
 >No if I add the following tree construction rule:
 >    ->^(HTMLTAG text* bracketexpr* quoted* scriptlet*)
 >and parse something like
 >    <meta http-equiv="Content-Type" content="text/html">
 >I get a result that sorts texts and quotes, like:
 >    <HTMLTAG meta http-equiv=  content= <QUOTE Content-Type>
 >    <QUOTE text/html>>
 >This does not really surprise me, but I would like to find out 
 >I should put the tree construction rule in order to get the 
 >nodes in the order of their appearance in the parsed text.
 >Is there a way to do it without touching/splitting the parser

Well, there might be, but probably the easiest thing to do would 
be to split it a little bit:

htmlcontent : text | bracketexpr | quoted | scriptlet;

htmltag : OPENTAG SLASH? (htmlcontent+ PERCENT*)* CLOSETAG
       -> ^(HTMLTAG htmlcontent*);

Or something along those lines, anyway ;)

More information about the antlr-interest mailing list