I am trying to accumulate lexer errors when Lexing in run time. I have followed the exact way of achieving this for parser errors as in this answer. But when I try to do this to the Lexer.
class Class2 : IAntlrErrorListener<IToken>
{
public void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e)
{
Console.WriteLine("Error in lexer at line " + ":" + e.OffendingToken.Column + e.OffendingToken.Line + e.Message);
}
}
and register this listener as below.
Class2 z = new Class2();
lexer.AddErrorListener(z);
But this gives a error which is unexpected.
Argument 1: cannot convert from 'CSSParserAntlr.Class2' to 'Antlr4.Runtime.IAntlrErrorListener<int>'
and
The best overloaded method match for 'Antlr4.Runtime.Recognizer<int,Antlr4.Runtime.Atn.LexerATNSimulator>.AddErrorListener(Antlr4.Runtime.IAntlrErrorListener<int>)' has some invalid arguments
Please give me some reason why this is happening.