[antlr-interest] ids+=ID question
Johannes Luber
jaluber at gmx.de
Wed Jul 25 08:00:50 PDT 2007
jrc at skylon.demon.co.uk wrote:
> I am using the lexer to split lines into fields using PIPE, SPACE and
> EQUALS. After identifying the fields at the start of the line, I want
> to reassemble the remaining text at the end of the line. The 'jText'
> rule recognizes the fields to be reassembled (see below).
>
> However, I am having a problem figuring out how to obtain the '.text'
> token attributes from the '$ids'.
>
> Please can someone show me the way?
> ======================================================================
> jText returns [String text]
> : (ids+=STRING | ids+=EQUALS | ids+=PIPE | ids+=SPACE)*
> {
> $text = "";
> for (int i=0; i<$ids.size(); i++)
> $text += $ids.get(i).text;
> }
> ;
> EQUALS : '=' ;
> PIPE : '|' ;
> SPACE : ' ' ;
> // STRING is printable ASCII excluding SPACE, EQUALS, PIPE, CR and NL
> STRING : (~(SPACE | EQUALS | PIPE | '\r' | '\n'))+ ;
> ======================================================================
> --
> John Connett
I'm not sure which language you are using. In C# you would use the
"Text" property, in Java (and probably C) the "GetText()" function.
Best regards,
Johannes Luber
More information about the antlr-interest
mailing list