[antlr-interest] Printing rule token range
Christian Andersson
dt05ca4 at student.lth.se
Wed Nov 28 01:29:42 PST 2007
Hi all!
I have a problem when printing the token range of the following constructs:
enum {
a_var,
b_var = 10
}a,b;
My parser will generate 2 copies of the "enum" one for 'a'
respective 'b'.
Later in my tree grammar I want to print the corresponding tokens whenever
the constant_expression rule is invoked.(I will get 10 in the example
above).
It works fine printing the 'a', but I only get -1 values
for the copy, and the expression end upp being null.
I use the following code to print the token interval for the expression rule:
int start = input.getTreeAdaptor().getTokenStartIndex($start);
int stop = input.getTreeAdaptor().getTokenStopIndex($start);
String text = input.getTokenStream().toString(start, stop);
So is there a way to solve this issue, it seems that there are some token
information missing when making copies like that?
I appreciate all help
BR Christian
More information about the antlr-interest
mailing list