[antlr-interest] ast rewrite

Bernardo Elayda belayda at gmail.com
Thu Jul 10 13:44:00 PDT 2008


importDeclaration
    :   'import' qualifiedName ('.' '*')? ';'
    -> ^('import' qualifiedName ('.' '*')? ';')
    ;

Hi!

Did you find a solution to your problem?  I suspect that one possible
solution may reside in the qualifiedName rule.
Make sure that it doesn't return a tree.  Another solution might
involve redoing the importDeclaration rule in your original
grammar that makes the AST.

In your grammar that defines importDeclaration as two rules:

tempRule : '.' '*' ;

importDeclaratrion : ('import' qualifiedName '.')=> 'import'
qualifiedName tempRule+ ';'
                     -> ^('import' qualifiedName tempRule+ ';')
                     | 'import' qualifiedName ';' -> ^('import'
qualifiedName ';')

You can then follow each branch with the tree you want.

hth,
Bernardo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080710/7621b257/attachment.html 


More information about the antlr-interest mailing list