[antlr-interest] Combining multiple tokens

Jim Idle jimi at temporal-wave.com
Tue Oct 20 00:55:12 PDT 2009


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: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jeffrey Cameron
Sent: Monday, October 19, 2009 2:32 AM
To: antlr-interest at antlr.org
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



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091020/24c97f3c/attachment.html 


More information about the antlr-interest mailing list