[antlr-interest] Need quick ANTLR/ST3 hack
Sam Harwell
sharwell at pixelminegames.com
Wed Sep 14 12:09:47 PDT 2011
I believe <if(rest(args))> will evaluate to true if args has more than one
item.
Sam
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Bill Andersen
Sent: Wednesday, September 14, 2011 1:26 PM
To: antlr-interest
Subject: [antlr-interest] Need quick ANTLR/ST3 hack
Folks
I want to write a template containing a conditional expansion for a
multi-valued attribute that does one thing if the attribute is singleton and
another if there are more than 1 element
For example, in an ANTLR grammar with ST output
rule
: FOO (bars+=bar)+ -> foo(args={$bars})
;
where the template looks like
foo(args) ::= <<
<if(???)>
something
<else>
something else
<endif>
>>
I want some expression for ??? to test for args being singleton.
Is this possible in ST3? Else I imagine I could write:
rule
: FOO (bars+=bar)+ -> foo(args={$bars},singleton={$bars.size() == 1})
;
and
foo(args,singleton) ::= <<
<if(singleton)>
something with args
<else>
something else with args
<endif>
>>
... but I would really rather not.
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