[antlr-interest] Proper way to catch parse errors
Martin Olsson
mnemo at minimum.se
Tue Jul 26 02:07:54 PDT 2005
Hi,
I'm developing an Eclipse plugin and I'm using ANTLR for refactoring etc.
Currently parse errors are correctly propagated into the Eclipse problems
view, but I would like to clean up the code a little bit.
In particular I don't understand why start() throws RecognitionException
but at the same time my method override reportError() is also called? Why
is there two different ways to catch the same error? Currently, I ignore
all exceptions thrown by start() which I feel is a little bit ugly.
Sincerly,
Martin
(below is the first part of my parser .g code)
------------------------------------------------------------------
class DUPParser extends Parser;
options {
k = 4; // The lookahead depth
}
{
protected MyEditor editor = null;
public MyParser(TokenStream lexer, MyEditor editor) {
this(lexer, 4);
this.editor = editor;
}
public void reportError(RecognitionException e) {
editor.reportError(e.getMessage(),
e.getLine(),
e.getColumn());
}
public final void parseIntoModule(MyModule module) {
try {
start(module);
} catch (Exception e) {
/* not used?! */
}
}
}
More information about the antlr-interest
mailing list