[antlr-interest] ids+=ID question
Gerald B. Rosenberg
gbr at newtechlaw.com
Wed Jul 25 14:48:11 PDT 2007
At 02:09 PM 7/25/2007, Jim Idle wrote:
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of John Connett
> >
> > Many thanks. I am using Java (but I'm not an experienced Java
> > programmer).
>
>How about... (and note that I changed that to + rather than * as I don't
>like rules that match nothing, you should use jText? instead :-)
>
>jText returns [String text]
>@init {$text = ""}
> :
> ( id=(STRING | EQUALS | PIPE | SPACE)
> {
> $text = $text + $id.text;
> }
> )+
> ;
>
>Jim
If the interest is to simply reconstruct whatever matched the rule,
how about this:
jText returns [String text] : (STRING | EQUALS | PIPE |
SPACE)+ { $text=$jText.text } ;
The return value will include hidden tokens, but since the rule
includes SPACE, that may be acceptable.
More information about the antlr-interest
mailing list