[antlr-interest] tree grammar and tokens

Ben Corne ben.corne at gmail.com
Mon Sep 5 12:25:51 PDT 2011


OK I'm clueless here.

I have a tree grammar ATDocWalker.g
and a parser grammar AmbientTalk.g generating the AST for ATDocWalker.

When I feed the parser this input:
//@"test"
deftype y;
deftype z;
deftype x <: y, z;

it outputs the following pretty printed AST:

PARSE TREE-----------
(AGBEGIN
(AGSTATEMENT
(AGTYPEDEFINITION
(AGSYMBOL y))
 (AGDOCUMENTATION //@"test"
))
(AGSTATEMENT
(AGTYPEDEFINITION
 (AGSYMBOL z)))
(AGSTATEMENT
(AGTYPEDEFINITION
 (AGSYMBOL x)
(AGSYMBOL y)
(AGSYMBOL z))))
END OF TREE----------

Everything looks normal (the newline after "test" is normal, since it's
included in the SINGLE_LINE_ANNOTATION lexer token).

When passing this AST to my tree grammar consisting of only a few rules so
far, just enough to parse this, I get the following exception:
/home/bcorne/ATDOC/Documenter/grammar/ATDocWalker.g: node from line 1:0
mismatched tree node: //@"test"
 expecting SINGLE_LINE_ANNOTATION

This is the tree rule causing the mismatched node:
documentation[ATDocGeneral doc]
  : ^( AGDOCUMENTATION
       ( d=SINGLE_LINE_ANNOTATION
       )
     ) {
      System.out.println("processing: "+$d.text);
      AnnotationProcessor.process($d.text,$doc);
    }
  ;

In this tree grammar I use almost exactly the same rules to obtain the type
definition names x, y and z. I have no clue what goes wrong with the
annotation.
Replacing the SINGLE_LINE_ANNOTATION token with the token definition from my
AmbientTalk.g file ('//@' ~( '\n' | '\r' )* '\r'? '\n') also has no effect.
It
then says that it expects '//@'.

Any ideas on what goes wrong here?
Thanks!
Ben


More information about the antlr-interest mailing list