public CaretReachedException(RuleContext finalContext, ICaretToken caretToken, IDictionary<ATNConfig, IList<Transition>> transitions, RecognitionException innerException) : base(innerException != null ? innerException.Message : "The caret was reached.", innerException) { _finalContext = finalContext; _caretToken = caretToken; _transitions = transitions; }
/// <summary> /// <inheritDoc/> /// <p>The default implementation resynchronizes the parser by consuming tokens /// until we find one in the resynchronization set--loosely the set of tokens /// that can follow the current rule.</p> /// </summary> public virtual void Recover(Parser recognizer, RecognitionException e) { // System.out.println("recover in "+recognizer.getRuleInvocationStack()+ // " index="+recognizer.getInputStream().index()+ // ", lastErrorIndex="+ // lastErrorIndex+ // ", states="+lastErrorStates); if (lastErrorIndex == ((ITokenStream)recognizer.InputStream).Index && lastErrorStates != null && lastErrorStates.Contains(recognizer.State)) { // uh oh, another error at same token index and previously-visited // state in ATN; must be a case where LT(1) is in the recovery // token set so nothing got consumed. Consume a single token // at least to prevent an infinite loop; this is a failsafe. // System.err.println("seen error condition before index="+ // lastErrorIndex+", states="+lastErrorStates); // System.err.println("FAILSAFE consumes "+recognizer.getTokenNames()[recognizer.getInputStream().LA(1)]); recognizer.Consume(); } lastErrorIndex = ((ITokenStream)recognizer.InputStream).Index; if (lastErrorStates == null) { lastErrorStates = new IntervalSet(); } lastErrorStates.Add(recognizer.State); IntervalSet followSet = GetErrorRecoverySet(recognizer); ConsumeUntil(recognizer, followSet); }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { NotificationManager.AddNotification( new ParseError ( string.Format("line {0} : {1} at {2} : {3}", line, charPositionInLine, offendingSymbol, msg) )); }
/// <summary> /// When the parser encounters an invalid token before the end of the rule : /// consume all tokens until a PeriodSeparator, the end of the line, or the next compiler directive / statement starting keyword. /// </summary> public override void Recover(Antlr4.Runtime.Parser recognizer, RecognitionException e) { if (lastErrorIndex == ((ITokenStream)recognizer.InputStream).Index && lastErrorStates != null && lastErrorStates.Contains(recognizer.State)) { // uh oh, another error at same token index and previously-visited // state in ATN; must be a case where LT(1) is in the recovery // token set so nothing got consumed. Consume a single token // at least to prevent an infinite loop; this is a failsafe. recognizer.Consume(); } lastErrorIndex = ((ITokenStream)recognizer.InputStream).Index; if (lastErrorStates == null) { lastErrorStates = new IntervalSet(); } lastErrorStates.Add(recognizer.State); // Consume until next compiler directive / statement starting keyword (excluded), PeriodSeparator (included), or the end of line Token lastConsumedToken = (Token)((ITokenStream)recognizer.InputStream).Lt(-1); Token currentInvalidToken = (Token)((ITokenStream)recognizer.InputStream).Lt(1); while ((lastConsumedToken == null || currentInvalidToken.TokensLine == lastConsumedToken.TokensLine) && currentInvalidToken.Type != TokenConstants.Eof) { if (((Token)currentInvalidToken).TokenFamily == TokenFamily.CompilerDirectiveStartingKeyword || ((Token)currentInvalidToken).TokenFamily == TokenFamily.StatementStartingKeyword || ((Token)currentInvalidToken).TokenFamily == TokenFamily.StatementEndingKeyword || ((Token)currentInvalidToken).TokenFamily == TokenFamily.CodeElementStartingKeyword) { break; } recognizer.Consume(); if (currentInvalidToken.Type == (int)TokenType.PeriodSeparator) { break; } currentInvalidToken = (Token)((ITokenStream)recognizer.InputStream).Lt(1); } }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { Console.Error.WriteLine("line " + line + ":" + charPositionInLine + " " + msg); underlineError(recognizer, (IToken)offendingSymbol, line, charPositionInLine); }
public SyntaxErrorException(string message, RecognitionException innerException, IToken offendingSymbol, int line, int position) : base(message, innerException) { _token = offendingSymbol; _line = line; _position = position; }
public override void ReportError(Parser recognizer, RecognitionException e) { if (e != null && e.OffendingToken != null && e.OffendingToken.Type == CaretToken.CaretTokenType) return; base.ReportError(recognizer, e); }
public virtual void NotifyErrorListeners(string msg, RecognitionException e) { int line = TokenStartLine; int charPositionInLine = TokenStartColumn; var antlrErrorListener = ErrorListenerDispatch; antlrErrorListener.SyntaxError(this, Type, line, charPositionInLine, msg, e); }
/// <summary> /// Instead of recovering from exception /// <paramref name="e"/> /// , re-throw it wrapped /// in a /// <see cref="ParseCanceledException"/> /// so it is not caught by the /// rule function catches. Use /// <see cref="System.Exception.InnerException()"/> /// to get the /// original /// <see cref="RecognitionException"/> /// . /// </summary> public override void Recover(Parser recognizer, RecognitionException e) { for (ParserRuleContext context = recognizer.Context; context != null; context = ((ParserRuleContext)context.Parent)) { context.exception = e; } throw new ParseCanceledException(e); }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { base.SyntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e); var error = SyntaxErrorFactory.CreateDiagnostic(offendingSymbol, line, charPositionInLine, msg, _filePath); _diagnostics.Add(error); }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { MainForm f = (MainForm)Application.OpenForms[0]; TextBox tx = f.resultBox; tx.Text += Environment.NewLine + Environment.NewLine + "> line " + line.ToString() + ":" + charPositionInLine.ToString() + " at " + offendingSymbol.ToString() + ": " + msg; }
public ORegexSyntaxException(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) : base(msg, e) { Recognizer = recognizer; OffendingSymbol = offendingSymbol; Line = line; CharPositionInLine = charPositionInLine; }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { base.SyntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e); InvokeErrorEvent(new LiquidError { TokenSource = offendingSymbol.TokenSource.SourceName, //Context = offendingSymbol..SourceName, Message = msg, Line = line, CharPositionInLine = charPositionInLine, OffendingSymbol = offendingSymbol.Text }); }
/// <summary> /// Register a ParserDiagnostic for each syntax error encountered by the parser /// </summary> public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { // Build a string representing the current grammar rules being recognized StringBuilder ruleStack = new StringBuilder(); IList<String> stack = ((Antlr4.Runtime.Parser)recognizer).GetRuleInvocationStack(); bool isFirst = true; foreach (string ruleInvocation in stack.Reverse()) { if(isFirst) { isFirst = false; } else { ruleStack.Append('>'); } ruleStack.Append(ruleInvocation); } // Register a new diagnostic ParserDiagnostic diagnostic = new ParserDiagnostic(msg, offendingSymbol, ruleStack.ToString()); Diagnostics.Add(diagnostic); }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { List<String> stack = new List<string>(((Parser)recognizer).GetRuleInvocationStack()); stack.Reverse(); if (!foundErrors) { myErrorTB.Text = "Parsing Errors:" + Environment.NewLine; foundErrors = true; } string theError = ""; theError += "rule stack: " + stack.ToString() + Environment.NewLine; theError += "line: " + line + ":" + charPositionInLine + " at " + offendingSymbol + ": " + msg + Environment.NewLine; if (theError.Length > 0) myErrorTB.Text += Environment.NewLine + theError; }
public override void Recover(Parser recognizer, RecognitionException e) { if (recognizer is ICodeCompletionParser && ((ICodeCompletionParser)recognizer).Interpreter.CaretTransitions != null) { // int stateNumber = recognizer.getContext().s; // ATNState state = recognizer.getATN().states.get(stateNumber); // if (state instanceof DecisionState && recognizer.getInputStream() instanceof ObjectStream) { // int decision = ((DecisionState)state).decision; // ParserATNSimulator simulator = recognizer.getInterpreter(); // int prediction = simulator.adaptivePredict((ObjectStream)recognizer.getInputStream(), decision, recognizer.getContext()); // } ICodeCompletionParser parser = (ICodeCompletionParser)recognizer; ICaretToken token = parser.Interpreter.CaretToken; CompletionParserATNSimulator interpreter = parser.Interpreter; throw new CaretReachedException(parser.Context, token, interpreter.CaretTransitions, e); } // TODO: incorporate error recovery as a fallback option if no trees match correctly throw e; //super.recover(recognizer, e); }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { string message = string.Format("Invalid token '{0}' found on line '{1}' at position '{2}'", offendingSymbol.Text.ToString(), line, charPositionInLine); throw new HScriptException(message, e); }
protected internal virtual void NotifyErrorListeners(Parser recognizer, string message , RecognitionException e) { recognizer.NotifyErrorListeners(e.OffendingToken, message, e); }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { if (receiveMessage != null) receiveMessage(new SqlCompileMessage(CompileMessageLevel.Error, msg, new SourceLocation(line, charPositionInLine))); }
public virtual void SyntaxError(TextWriter output, IRecognizer recognizer, Symbol offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { foreach (IAntlrErrorListener <Symbol> listener in delegates) { listener.SyntaxError(output, recognizer, offendingSymbol, line, charPositionInLine, msg, e); } }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { throw new Exception("Unable to complete script execution: " + msg + " on line at :" + line.ToString()); }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { CompileStatus.AddError(new CompilerError(FileName, line, charPositionInLine, msg)); }
/// <summary> /// Rely on the error handler for this parser but, if no tokens are consumed /// to recover, add an error node. /// </summary> /// <remarks> /// Rely on the error handler for this parser but, if no tokens are consumed /// to recover, add an error node. Otherwise, nothing is seen in the parse /// tree. /// </remarks> protected internal virtual void Recover(RecognitionException e) { int i = _input.Index; ErrorHandler.Recover(this, e); if (_input.Index == i) { // no input consumed, better add an error node if (e is InputMismatchException) { InputMismatchException ime = (InputMismatchException)e; IToken tok = e.OffendingToken; int expectedTokenType = ime.GetExpectedTokens().MinElement; // get any element IToken errToken = TokenFactory.Create(Tuple.Create(tok.TokenSource, tok.TokenSource.InputStream), expectedTokenType, tok.Text, TokenConstants.DefaultChannel, -1, -1, tok.Line, tok.Column); // invalid start/stop _ctx.AddErrorNode(errToken); } else { // NoViableAlt IToken tok = e.OffendingToken; IToken errToken = TokenFactory.Create(Tuple.Create(tok.TokenSource, tok.TokenSource.InputStream), TokenConstants.InvalidType, tok.Text, TokenConstants.DefaultChannel, -1, -1, tok.Line, tok.Column); // invalid start/stop _ctx.AddErrorNode(errToken); } } }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { throw new ORegexSyntaxException(recognizer, offendingSymbol, line, charPositionInLine, msg, e); }
protected internal virtual void NotifyErrorListeners(Parser recognizer, string message, RecognitionException e) { recognizer.NotifyErrorListeners(e.OffendingToken, message, e); }
public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { Span span = new Span(); if (offendingSymbol != null) span = Span.FromBounds(offendingSymbol.StartIndex, offendingSymbol.StopIndex + 1); _errors.Add(new ParseErrorEventArgs(msg, span)); if (_outputWindow != null) { if (msg.Length > 100) msg = msg.Substring(0, 100) + " ..."; _outputWindow.WriteLine(string.Format("{0}({1},{2}): {3}", _fileName ?? recognizer.InputStream.SourceName, line, charPositionInLine + 1, msg)); } if (_errors.Count > 100) throw new OperationCanceledException(); }
/// <summary> /// process the SyntaxError /// </summary> /// <param name="recognizer"></param> /// <param name="offendingSymbol"></param> /// <param name="line"></param> /// <param name="charPositionInLine"></param> /// <param name="msg"></param> /// <param name="e"></param> public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { // publish the message string text = String.Empty; if (e is FailedPredicateException) text = String.Format(Messages.RCM_11, offendingSymbol.Text ); else text = msg; Message message = new Message(type: MessageType.Error, line: line, pos: charPositionInLine, message: text); if (OnMessageAdded != null) OnMessageAdded(this, new EventArgs(message)); _errors.Add(message); if (charPositionInLine != 00) Console.Out.WriteLine(String.Format("ERROR <{0},{1:D2}>:{2}", line, charPositionInLine, text)); else Console.Out.WriteLine(String.Format("ERROR <line {0}>:{1}", line, text)); }
public virtual void SyntaxError(IRecognizer recognizer, IToken offendingSymbol , int line, int charPositionInLine, string msg, RecognitionException e) { }
public override void SyntaxError(System.IO.TextWriter output, Antlr4.Runtime.IRecognizer recognizer, Antlr4.Runtime.IToken offendingSymbol, int line, int charPositionInLine, string msg, Antlr4.Runtime.RecognitionException e) { this.vm.set_runable(false); //Console.WriteLine(e.GetType().Name); Console.WriteLine("SiBty error ({0}:{1}) -> {2}", line, charPositionInLine, msg); this.under_line(line, charPositionInLine); }
/// <summary> /// <inheritDoc/> /// <p>The default implementation returns immediately if the handler is already /// in error recovery mode. Otherwise, it calls /// <see cref="BeginErrorCondition(Parser)"/> /// and dispatches the reporting task based on the runtime type of /// <paramref name="e"/> /// according to the following table.</p> /// <ul> /// <li> /// <see cref="NoViableAltException"/> /// : Dispatches the call to /// <see cref="ReportNoViableAlternative(Parser, NoViableAltException)"/> /// </li> /// <li> /// <see cref="InputMismatchException"/> /// : Dispatches the call to /// <see cref="ReportInputMismatch(Parser, InputMismatchException)"/> /// </li> /// <li> /// <see cref="FailedPredicateException"/> /// : Dispatches the call to /// <see cref="ReportFailedPredicate(Parser, FailedPredicateException)"/> /// </li> /// <li>All other types: calls /// <see cref="Parser.NotifyErrorListeners(string)"/> /// to report /// the exception</li> /// </ul> /// </summary> public virtual void ReportError(Parser recognizer, RecognitionException e) { // if we've already reported an error and have not matched a token // yet successfully, don't report any errors. if (InErrorRecoveryMode(recognizer)) { // System.err.print("[SPURIOUS] "); return; } // don't report spurious errors BeginErrorCondition(recognizer); if (e is NoViableAltException) { ReportNoViableAlternative(recognizer, (NoViableAltException)e); } else { if (e is InputMismatchException) { ReportInputMismatch(recognizer, (InputMismatchException)e); } else { if (e is FailedPredicateException) { ReportFailedPredicate(recognizer, (FailedPredicateException)e); } else { #if !PORTABLE System.Console.Error.WriteLine("unknown recognition error type: " + e.GetType().FullName); #endif NotifyErrorListeners(recognizer, e.Message, e); } } } }
public override void Recover(Parser recognizer, RecognitionException e) { int errIndex = recognizer.InputStream.Index; if (firstErrorTokenIndex == -1) { firstErrorTokenIndex = errIndex; // latch } // System.err.println("recover: error at " + errIndex); IIntStream input = recognizer.InputStream; if (input.Index < input.Size - 1) { // don't consume() eof recognizer.Consume(); // just kill this bad token and let it continue. } }
/// <summary> /// Emits a syntax error. /// </summary> /// <param name="recognizer">The recognizer.</param> /// <param name="offendingSymbol">The offending symbol.</param> /// <param name="line">The line number.</param> /// <param name="charPositionInLine">The character position in the line.</param> /// <param name="msg">The error message.</param> /// <param name="e">The exception.</param> public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { Log.Warn(string.Format("Syntax error at line {0}:{1} - {2}", line, charPositionInLine, msg)); }
public virtual void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { }