我一直试图让SLF4J处理所有ANTLR错误消息,以便它们以正确的顺序显示在其他消息中,但我没有运气。
关于Error Reporting and Recovery上的示例,我尝试覆盖emitErrorMessage
,displayRecognitionError
和recoverFromMismatchedToken
:
@members {
private Logger logger = LoggerFactory.getLogger(getClass().getName());
@Override
public void displayRecognitionError(String[] token_names, RecognitionException e) {
logger.error("error at " + TextUtil.join(" ", token_names), e);
}
@Override
public void emitErrorMessage(String msg) {
logger.error(msg);
}
@Override
protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) throws RecognitionException {
throw new MismatchedTokenException(ttype, input);
}
}
但是,我仍在STDERR上收到消息:
line 1:10 no viable alternative at character 'y' line 1:12 no viable alternative at character 'y'
答案 0 :(得分:1)
@members
是@parser::members
的缩写,您发布的错误消息看起来是词法错误。尝试添加@lexer::members
来处理它们。