[antlr-interest] Parser Generation: How to catch an exception within an rule?

luciano mantuaneli mantu_lists at yahoo.com.br
Fri Mar 9 12:29:06 PST 2007

I have a rule called identifierStar, which throws an MyOwnCheckedException exception.
I have another rule called importDefinition, which invokes relu x. My question is how can I catch the MyOwnCheckedException exception?

    options {defaultErrorHandler = true;}
    { boolean isStatic = false; String imp = "";}
    :    i:"import"^ {#i.setType(IMPORT);} ( "static"! {#i.setType(STATIC_IMPORT);} )? imp=identifierStar SEMI!

identifierStar returns[String result = ""] throws StarImportException{
    StringBuilder sb = new StringBuilder("");
    :    i:IDENT{sb.append(i.getText());}
        ( DOT^ i2:IDENT {sb.append("." + i2.getText());})*
        ( DOT^ STAR {throw new StarImportException();})?
            result = sb.toString();

Thank you very much!

Luciano Mantuaneli
Fale com seus amigos  de graça com o novo Yahoo! Messenger 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070309/a0b2673e/attachment.html 

More information about the antlr-interest mailing list