[antlr-interest] Question on aborting rule based on pattern
Rajeev Bharadhwaj
rajeevb2 at yahoo.com
Sat Jul 22 16:04:03 PDT 2006
I tried inserting the semantic predicate, it fires
alright but it throws a SemanticException. This looks
more like a mechanism to find syntax errors and abort
the parsing. In my case, I want to catch the exception
and stop matching ddd and continue parsing.
Rajeev
--- Stanimir Stamenkov <stanio at myrealbox.com> wrote:
> /Rajeev Bharadhwaj/:
>
> > How do I stop matching so it can reduce the rule?
> >
> > aaa : "AAAA" SPACE bbb ccc ;
> >
> > bbb : ( ddd )+ ;
> >
> > ddd : ha:ATOM ":" SPACE eee SPACE ; // Rule 1
> >
> > eee : hva:ATOM (":" hvap:ATOM)* ;
> >
> > ccc : "XXX" ":" SPACE ((cccentry)+ ; // Rule 2
> >
> > I would like Rule 1 to stop matching when
> > ha.getText()==XXX, so aaa can shift to Rule 2
> (ccc).
> >
> > ATOM matches alphabets and numbers to create
> strings.
>
> Do semantic predicates [1] work for you?
>
> ddd : ha:ATOM { !"XXX".equals(ha.getText()) }? ...
>
> [1]
>
http://www.antlr.org/doc/metalang.html#SemanticPredicates
>
> --
> Stanimir
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the antlr-interest
mailing list