[antlr-interest] Concatenation in Tree Rewriting
Daniels, Troy (US SSA)
troy.daniels at baesystems.com
Tue Aug 12 08:45:20 PDT 2008
I would think something like this would work
adjective
:
{ String name = ""; }
(ADJECTIVE_PREFIX
{ name += $prefix.text; } )?
(NAME
{name += $NAME.text}) ->
{new CommonTree(new CommonToken(ADJECTIVE, name)))}
;
Basically, you build up name as you go.
I haven't tested this, but it seems like it should work and be clearer.
Troy
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Louis Rose
> Sent: Tuesday, August 12, 2008 8:58 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Concatenation in Tree Rewriting
>
> Hi all,
>
> I was wondering if there's a more elegant way to write the
> intentions of the following grammar rule:
>
> adjective
> : ADJECTIVE_PREFIX? NAME -> {new CommonTree(new
> CommonToken(ADJECTIVE, ($ADJECTIVE_PREFIX.text == null ? $NAME.text :
> $prefix.text + $NAME.text)))}
> ;
>
> The ADJECTIVE token type is an imaginary token, and has been
> defined in the tokens {} block.
>
> Cheers,
> Louis.
>
More information about the antlr-interest
mailing list