Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 353075

Summary: LexerErrorContext should not implement IParserErrorContext
Product: [Modeling] TMF Reporter: Holger Schill <Holger.Schill>
Component: Xtext BacklogAssignee: Project Inbox <tmf.xtext-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: btickets, christian.dietrich.opensource, mail, oliver, sebastian.zarnekow
Version: 2.0.0Keywords: helpwanted
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Holger Schill CLA 2011-07-26 03:00:57 EDT
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.
Comment 1 Oliver Libutzki CLA 2013-05-03 07:04:43 EDT
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)
Comment 2 Sebastian Zarnekow CLA 2013-05-03 08:00:18 EDT
A patch is most welcome :-)