[antlr-interest] gUnit test for tree grammar

Kunal Sawlani kunalsawlani at gmail.com
Tue Nov 9 07:11:32 PST 2010


Hi All,

I am trying to use ANTLR for checking the return values from my Tree
grammar.
I have a simple rule which just returns the text found.

start_tree_parser walks start_parser:
"this is text" returns ["this is text"]


However, the Answer returned from this rule is the actual AST built up by
the parser,

i.e. (TEXT this is text) is the actual value returned.

The options I have in my Tree grammar are.

options {
  language     = Java;
  output       = AST;
  tokenVocab   = text_parser;
  ASTLabelType = CommonTree;
}

And my tree grammar is as follows:

start_tree_parser returns [String result = " "] :
    ^(TEXT text) {$result = $text.result;}

text returns [String result = ""; ]:
    (TEXTTOKEN)  {$result = $text;}

The tree being formed from the parser is correct, however, I want to test
the output of walking the tree and checking the string returned.

I am not sure if I am using the correct syntax for checking the return
values. If anyone could point me in the right direction, that would be
great!

Thanks,
Kunal


More information about the antlr-interest mailing list