[antlr-interest] How to add logic for StringTemplate selection?
Ted Villalba
ted.villalba at gmail.com
Mon Jul 23 10:07:31 PDT 2007
Awesome , thanks.
1. How do I reference the value $a from the other rule? Not sure I can
reference it like my example below.
2. Is it a boolean conditional, or can I have multiple alternatives?
z: ^(a b) -> template1
a: ^(d e) -> {if $a ==1}? blort
-> {if $a ==2}? blech
-> bleep
Thanks again,
Ted
On 7/23/07, Terence Parr <parrt at cs.usfca.edu> wrote:
>
> a : ... -> {...}? blort
> -> blech
> ;
>
> Ter
> On Jul 23, 2007, at 9:31 AM, Ted Villalba wrote:
>
> > Hi,
> >
> > I'm wondering if this is possible, or if I should be trying to
> > approach it differently. Any help would be appreciated.
> > I want to be able to select the proper string template, based on
> > the results of some function calls, passing values from other rules.
> > For instance, I have these tree grammar rules( reduced here for
> > simplicity):
> >
> > field : ^('=' tag value) -> template1(tag={$tag.text},value=
> > {$value.st})
> > ;
> >
> > value : ^(operator terms value) -> template2(op={checkNotOperator
> > ($operator.st)},terms={$terms.st}, values={$value.st})
> > ;
> >
> > I want to be able to select the template for value, depending on a
> > property of "tag" in the field rule.
> > I need to somehow pass the value of $tag from the value rule, and
> > depending on the output of that call, select the correct template.
> > The pseudocode being something like:
> >
> > value : ^(operator terms value) if (getDataProp($tag.text) == X) -
> > > templateX
> > else if getDataProp
> > ($tag.text) == Y -> templateY
> >
> >
> > What is the best way to handle this?
> >
> > Thanks a lot for any help.
> > Ted
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070723/60e136d5/attachment.html
More information about the antlr-interest
mailing list