[antlr-interest] ids+=ID question
jrc at skylon.demon.co.uk
jrc at skylon.demon.co.uk
Wed Jul 25 07:54:35 PDT 2007
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
More information about the antlr-interest
mailing list