[antlr-interest] How to add logic for StringTemplate selection?

Thomas Brandon tbrandonau at gmail.com
Mon Jul 23 11:21:18 PDT 2007

On 7/24/07, Ted Villalba <ted.villalba at gmail.com> wrote:
> Awesome , thanks.
> 1. How do I reference the value $a from the other rule? Not sure I can
> reference it like my example below.
As your value rule is called directly by your field rule you could
just use a rule parameter. But for flexibility you're probably best
using scopes. This will work even if your value rule isn't directly
called by field (without passing all the way down the chain). No wiki
docs on scopes yet so check out the dynamic-scope example.
> 2. Is it a boolean conditional, or can I have multiple alternatives?
It's a boolean conditional, multiple alternatives are allowed.

So you'd have something like:
scope {
    String tagName;
    :   ^(  '='
            tag { $field::tagName = $tag.text; }
        ) -> template1(tag={$tag.text},value={$value.st})

    :   ^(operator terms value)
          -> {$field::tagName == "Tag1"}? template1
          -> {$field::tagName == "Tag2"}? template2
          -> defaultTemplate

> Thanks again,
>  Ted

More information about the antlr-interest mailing list