[antlr-interest] error return code

robermann robermann at gmail.com
Mon Jun 18 02:07:07 PDT 2007


I got the point. If I override the default error handling mechanism, I 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, as you teach :)

//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


Thanks
Roberto


On 6/18/07, Terence Parr <parrt at cs.usfca.edu> wrote:
>
>
> On Jun 18, 2007, at 5:59 PM, robermann wrote:
>
> > Hi all,
> > a question: let this command (and error):
> >
> > java Test < myInput.txt
> > line 0:-1 mismatched input '<EOF>' expecting '}'
> >
> > After getting a such parser error, I would expect that either "echo
> > %errorlevel%" (on a DOS shell) or "echo $?" (on a Bash shell) would
> > return a code not equal to 0. Instead, I get always a return code =
> > 0. Is there any particular reason? When automating /scripting, it
> > could be useful distinguish whether the parser exit with an
> > exception or not.
> >
>
> Hi. That's your tool invoking the parser. ANTLR parsers don't exit.
> Catch the exception and send out an error code. :)
>
> Ter
>
>


-- 
Are you tired to make software? Sound it! (http://www.codesounding.org)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070618/4ba77e34/attachment-0001.html 


More information about the antlr-interest mailing list