[antlr-interest] Question on aborting rule based on pattern

Stanimir Stamenkov stanio at myrealbox.com
Sat Jul 22 04:14:57 PDT 2006


/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


More information about the antlr-interest mailing list