[antlr-interest] ANTLR Error Messages and getErrorMessage --- not being routed

Andreas Stefik stefika at gmail.com
Mon Feb 15 12:35:19 PST 2010


Hello all,

I have a grammar that I use for a custom virtual machine. In this machine,
we have our own custom syntax error reporting mechanism, which is tied
through the NetBeans platform using ANTLR. Recently, one of the members on
our development team noticed that "some" of the errors that ANTLR is dumping
to the command line are not properly being routed through our syntax error
reporting mechanism.


The thing is, though, we aren't doing anything special with our reporting.
As a test to see which errors are being routed and which are not, we
modified our mechanism to do the simplest possible thing:

@Override
    public String getErrorMessage(RecognitionException re, String[]
tokenNames) {
        return super.getErrorMessage(re, tokenNames);
    }

    public String getTokenErrorDisplay(Token t) {
        return t.toString();
    }

(this goes in @parser:members).

Next, we generate the grammar and set breakpoints at the appropriate points.
As expected, if we add in errors into our DSL, the breakpoints hit and the
errors are caught. However, if we add certain kinds of errors (e.g., an
extra semicolon at the end of a line when there shouldn't be one), ANTLR
seems to dump the error to the command line but not report it through
getErrorMessage (the breakpoint is not hit). For example, ANTLR might
output: line 15:24 no viable alternative at character ';' but not actually
route this through getErrorMessage, which means we don't detect it
programmatically.

So, what exactly is going on here? Are there certain classifications of
errors that ANTLR dumps to the command line but does not route through
getErrorMessage? For these classes of errors, how can we force ANTLR to send
us these as well, so that we can route them correctly through the rest of
our architecture?

I tried using @rulecatch and a few other methods in BaseRecognizer (e.g.,
emit, reportError), according to the docs, but I can't seem to get ANTLR to
route these particular errors through there either.

Any thoughts?

Stefik


More information about the antlr-interest mailing list