1
我一直在試圖獲取所有由SLF4J處理的ANTLR錯誤消息,以便它們以正確的順序出現在其他消息中,但我沒有任何運氣。如何重新定向「不可行的替代」信息?
下面我試圖重寫emitErrorMessage
,displayRecognitionError
上Error Reporting and Recovery的例子,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'
爲詞法分析器重載'emitErrorMessage'處理它。猜猜我只是假設詞法分析器錯誤會通過解析器冒出來。 –