Question

I've been trying to get all ANTLR error messages handled by SLF4J so that they show up in their proper sequence among other messages, but I'm not having any luck.

Following the examples on Error Reporting and Recovery I've tried overriding emitErrorMessage, displayRecognitionError, and 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);
    }
}

However, I'm still getting messages on STDERR:

line 1:10 no viable alternative at character 'y'
line 1:12 no viable alternative at character 'y'
Was it helpful?

Solution

@members is short for @parser::members and those error message you posted look to be lexer errors. Try to add @lexer::members to handle them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top