All you need do is accumulate the text in a stringbuffer:

 

( s=TOK { sbuf.append($s.text); }) +

 

Then use the string you have accumulated to set the text of an imaginary or 
even the last TOK (which will be in s).

 

->IMAGINARY[sbuf.toString()]

 

Should work fine.

 

Jim

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of Jeffrey Cameron
Sent: Monday, October 19, 2009 2:32 AM
To: [email protected]
Subject: [antlr-interest] Combining multiple tokens

 

I have two parser rules in my grammar where I am trying to wrap the complete, 
concatenated text of a series of tokens into a single token for a tree grammar. 
 The rules look like this:

 

#1:

 

cell : (~(VBAR|EOL))* ;

 

in this case I would like to write something like this:

 

cell : (~(VBAR|EOL))* -> TABLECELL[$cell.text] ;

 

but when I put that syntax in I get an exception. 

 

#2:

 

line_to_eol : ( options {greedy=false;} : . )* EOL ;

 

I would like to do something like the same as above but ignore the EOL token, 
so something like this:

 

line_to_eol : stuff+=( options {greedy=false;} : . )* EOL -> TEXT[$stuff.text] ;

 

Can someone tell me when I am doing wrong in here and how to correct it? I'm a 
bit stuck here and every other part of my grammar is working as expected.

 

Thanks in advance




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to