[antlr-interest] Exit Status from ANTLR

robermann robermann at gmail.com
Mon Jun 25 11:04:00 PDT 2007


Hi Randall
>From a previous email, this is my workaround, hope this help:

if you override the default error handling mechanism,  you can rethrow the
exception, rather than catch it. So the calling (testing) class get an
unhandled exception and the Java VM exits with an error code != 0.

In the grammar I'll therefore add the following stuff:

//START OVERRIDE ERROR
@members {
protected void mismatch(IntStream input, int ttype, BitSet follow)
    throws RecognitionException
{
    throw new MismatchedTokenException(ttype, input);
}
public void recoverFromMismatchedSet(IntStream input,
                                     RecognitionException e,
                                     BitSet follow)
    throws RecognitionException
{
    throw e;
}
}

// Alter code generation so catch-clauses get replace with
// this action.
@rulecatch {
catch (RecognitionException e) {
    throw e;
}
}
//END OVERRIDE ERROR

Regards
Roberto Mannai

On 6/25/07, Randall R Schulz <rschulz at sonic.net> wrote:
>
> On Sunday 19 November 2006 16:13, Kay Roepke wrote:
> > On 19. Nov 2006, at 23:12 , Randall R Schulz wrote:
> > > It would be nice if the ANTLR command (as in {@link
> > > org.antlr.Tool#main(String[])} would call System.exit
> > > (somethingNonZero)
> > > if it detected and error in the submitted grammar specification.
> >
> > Right you are! http://www.antlr.org:8888/browse/ANTLR-43
>
> I'm disappointed to see this has not been fixed in the final release of
> ANTLR 3.0.
>
> It really makes it hard to script automated builds when you cannot tell
> if there was an error detected during generation of the parser code.
>
>
> > cheers,
> > -k
>
>
> Randall Schulz
>



-- 
Are you tired of making software? Play it! (http://www.codesounding.org)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070625/ba3bdf1c/attachment.html 


More information about the antlr-interest mailing list