[antlr-interest] Strangeness when parsing strings and spaces
Bart Kiers
bkiers at gmail.com
Mon Jan 17 23:35:11 PST 2011
On Tue, Jan 18, 2011 at 8:28 AM, Kevin Jackson <foamdino at gmail.com> wrote:
> Hi,
>
> > pair
> > : LEFT_SQUARE IDENTIFIER QUOTED_TEXT RIGHT_SQUARE
> > ;
> >
> > LEFT_SQUARE : '[';
> > RIGHT_SQUARE : ']';
> > IDENTIFIER : ('a'..'z'|'A'..'Z')+;
> > QUOTED_TEXT : '"' ('a'..'z' | 'A'..'Z' | ' ' | ',' | '-')+ '"';
> > SPACES : (' ' | '\t')+ {skip();};
>
> Thanks for the reply. This nearly works! However I don't want to
> retain the '"' (quotes) in the rewrite rule, so although the
> IDENTIFIER has fixed the first problem, I now have a problem with the
> QUOTED_TEXT.
>
> I should have mentioned that I suppose.
>
> Thanks,
> Kev
>
Try something like this:
QUOTED_TEXT
: '"' ('a'..'z' | 'A'..'Z' | ' ' | ',' | '-')+ '"'
{setText(getText().substring(0, getText().length()-1));}
;
to strip the quotes in the lexing-stage.
Regards,
Bart.
More information about the antlr-interest
mailing list