[antlr-interest] How can I get the string contents of a Kleene Closure?

Jim Idle jimi at temporal-wave.com
Thu Sep 8 08:32:09 PDT 2011


Well, you are asking for the contents of a parse construct, not a lexer
rule you understand? This says ANY token 0 or more times, then a ';'. For
a start, that is about as ambiguous as you can get of course. IF you are
looking for any token (not character) sequence followed by ';' then you
likely want:

s_t_s : ~';'* ';' ;


Then to get the text of the tokens:

s_t_s : (a=~';' {System.out.println($a.text); } )* ';' ;

But instead of println, accumulate in a StringBuilder or similar.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Douglas Godfrey
> Sent: Wednesday, September 07, 2011 9:24 PM
> To: Dejas Ninethousand; Antlr-Interest Antlr.Org
> Subject: Re: [antlr-interest] How can I get the string contents of a
> Kleene Closure?
>
> rich_newick_string : semicolon_terminated_string {
> stack.pushRichNewickString($semicolon_terminated_string.text); };
>
> semicolon_terminated_string
>
> : (.*';') ;
>
>
>
>
> On 9/6/11 5:44 PM, "Dejas Ninethousand" <dejas9000 at gmail.com> wrote:
>
> >I have the following production in my ANTLR grammar:
> >
> >rich_newick_string
> >: str=(.*';') { stack.pushRichNewickString($str.text); };
> >
> >I expected some string match to be passed to my pushRichNewickString
> >method, but instead I'm getting null. What am I doing wrong?
> >
> >Thanks.
> >
> >List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >Unsubscribe:
> >http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list