Community
Participate
Working Groups
The protected class LexerErrorContext implements IParserErrorContext. The protected class ParserErrorContext does the same. The only different is that a LexerErrorContext returns null in case that someone calls getRecognitionException(). In the usecase that someone whats to do something in a custom instance of ISyntaxErrorMessageProvider, it is necessary to decide what kind of Context you have. Because of that it would be necessary to have different Interfaces for LexerErrorContext and ParserErrorContext. The other thing is that the LexerErrorContext has no information about the Exception that leaded to the error. For now the only place to find out what happened is the Lexer itself in the method getErrorMessage(). For now the hook ISyntaxErrorMessageProvider is not useable for someone who wants to translate errors for ParserErrors and LexerErrors.
I encountered the same problem, but I wonder why LexerErrorContext doesn't supply the RecognitionException. In the nextToken() method of org.eclipse.xtext.parser.antlr.Lexer you have a RecognitionException (line 80 in Xtext 2.4.1): tokenErrorMap.put(t, getErrorMessage(re, this.getTokenNames())); Unfortunately this one is consumed by the getErrorMessage method. If you held the exception in the tokenErrorMap, it would be possible to pass it to the LexerErrorContext in org.eclipse.xtext.parser.antlr.AbstractInternalAntlrParser: String lexerErrorMessage = ((XtextTokenStream) input).getLexerErrorMessage(token); LexerErrorContext errorContext = new LexerErrorContext(lexerErrorMessage); (line 257)
A patch is most welcome :-)