But use a StringBuilder if there are lots. Jim
> -----Original Message----- > From: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of John B. Brodie > Sent: Monday, July 18, 2011 1:53 PM > To: Dejas Ninethousand > Cc: [email protected] > Subject: Re: [antlr-interest] Concatenating variable number of tokens > into a single string in an action? > > Greetings! > > On Mon, 2011-07-18 at 15:35 -0500, Dejas Ninethousand wrote: > > Hello, > > > > If I have the rule: > > > > text : t=(UNQUOTED_ALPHA_TEXT | DECIMAL_NUMBER)+ { > > stack.pushUnquotedText(...); }; > > > > Is there any way for me to gather the text of all the ALPHA_TEXT and > > DECIMAL_NUMBER tokens in this production into a single string and > > shove that string as an argument in my action? > > > > Basically accumulate the text into a variable using an action inside > the (...)+ loop and then push the accumulation. Something like > (UNTESTED): > > text > @init{ String str = ""; } : > ( t=(UNQUOTED_ALPHA_TEXT | DECIMAL_NUMBER) { str+=$t.text; } )+ > { stack.pushUnquotedText(str); } > ; > > Note that the t=(...) only works because all of the stuff inside the > (...) are Tokens (i think). > > Note that any tokens that were put on the HIDDEN channel (or skip();d) > by the Lexer will not be accumulated/pushed. > > Hope this helps... > -jbb > > > > 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 -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
