[antlr-interest] Validating predicates in @after
Felix Dorner
felix_do at web.de
Wed Apr 30 00:27:18 PDT 2008
Hey again..
In expression rules you often have alternatives that consist of
subexpressions, like:
expression :
| ^(binop expression expression)
| ^(unaryop expression)
...
my current validation grammar looks like this:
| ..
^(binop e1=expression e2=expression)
{$e1.start.evalsTo != null}?
{$e2.start.evalsTo != null}?
| ^(unaryop e1=expression)
{$e1.start.evalsTo != null}?
so there's a lot of repetitive code here. Rather than doing that, I'd
like to verify right befor expression returns that its "evalTo" isn't
null (i.e. it's a valid expression). Is this the only way to do this:?
@after {
if ($start.evalType() == null){
throw new FailedPredicateException(input, expression,
"$start.evalType != null");
}
}
Thanks again,
Felix
More information about the antlr-interest
mailing list