[antlr-interest] Rewrite with predicate -> default?
Terence Parr
parrt at cs.usfca.edu
Sat Jul 23 13:39:45 PDT 2011
i think "-> ..." works with 3 dots.
T
On Jul 23, 2011, at 1:05 PM, Tobias Diez wrote:
> Hi,
>
> It is possible to rewrite something based on a predicate but not always?
> What I want to do is the following (pseudo code)
>
> ^(TOMATCH)
> -> ^(RESULT1) if TOMATCH.Text = 1
> -> ^(RESULT2) if TOMATCH.Text = 2
> LEAVE IT UNCHANGED otherwise
>
> The closest thing I could archive is the following code, which works in the
> sense that the output-AST is correct. But this solution has the flaw that
> ANTLR apparently thinks something has changed and reruns the rule (and
> because nothing changed so far it match again) and so ACTION would be called
> two times!
>
> command_single_argument
> : ^(COMMAND c=CONTROL_WORD ^(BLOCK b=.)) {ACTION}
> -> {$c.Text == @"\begin"}? ^(ENVIRONMENT_BEGIN $b)
> -> {$c.Text == @"\end"}? ^(ENVIRONMENT_END $b)
> -> ^(COMMAND $c ^(BLOCK $b))
> ;
>
> Is there a better solution?
>
> Thanks!
>
>
> 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