Bug 353075 - LexerErrorContext should not implement IParserErrorContext
Summary: LexerErrorContext should not implement IParserErrorContext
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext Backlog (show other bugs)
Version: 2.0.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2011-07-26 03:00 EDT by Holger Schill CLA
Modified: 2013-05-06 06:32 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 :-)