public override void Recover(LexerNoViableAltException e) { //Lexer recover strategy - ignore all till next space, tab or EOL var next = _input.La(1); while (next != -1 && next != ' ' && next != '\n' && next != '\r' && next != '\t' && next != ',' && next != ')') { Interpreter.Consume(_input); next = _input.La(1); } }
private static string GetMessage(RecognitionException re) { return(re switch { FailedPredicateException fpe => fpe.Message, InputMismatchException ime => ime.Message, LexerNoViableAltException nve1 => $"No Viable Alternative - '{nve1.OffendingToken.Text}' not recognized.", NoViableAltException nve2 => $"No Viable Alternative - '{nve2.OffendingToken.Text}' was unexpected.", _ => throw new ArgumentOutOfRangeException(nameof(re)) });
public override void NotifyListeners(LexerNoViableAltException e) { Console.WriteLine("测试位置"); //string text = _input.GetText(Interval.Of(_tokenStartCharIndex, _input.Index)); ICharStream _input = (ICharStream)InputStream; string text = _input.GetText(Interval.Of(TokenStartCharIndex, _input.Index)); Console.WriteLine(text); string msg = "无法识别的字符: '" + GetErrorDisplay(text) + "'"; IAntlrErrorListener <int> listener = ErrorListenerDispatch; listener.SyntaxError(ErrorOutput, this, 0, Line, Column, msg, e); }
public override void Recover(LexerNoViableAltException e) { throw e; }
public override void Recover(LexerNoViableAltException e) { Console.WriteLine("调用我了!"); base.Recover(e); }
public override void Recover(LexerNoViableAltException e) { throw new ParseCanceledException(e); }
public override void Recover(LexerNoViableAltException e) { NotifyListeners(e); base.Recover(e); }