[antlr-interest] Getting the exceptions caught in nextToken()
Guntis Ozols
guntiso at latnet.lv
Tue Dec 4 12:03:09 PST 2007
Not sure if it fits you, I use something like this:
// Error handling (do not recover).
// This part sucks, I'd prefer to call stopOnError(true) from API
// NOTE: Throwing in lexer also means: disable antlrworks debugger and lexer
syntactic predicates, Oh my dear...
@lexer::members {
public void reportError(RecognitionException e) {
// API does not allow to throw e from here, throwing RuntimeException
instead
throw new RuntimeException("Lexing recognition problem", e);
}
}
@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;
}
}
@rulecatch {
catch (RecognitionException e) {
throw e;
}
}
> Currently it seems the nextToken() method in the base lexer class can
> not be forced to throw exceptions on to the parser (or anything else)
> -- instead the lexer is catching them and printing error messages to
> stderr. How can these exceptions be thrown back to the parser so they
> can be used?
>
> Thanks,
> Andreas
More information about the antlr-interest
mailing list