//Funcion que sobreescribe la funcion SyntaxError de la clase BaseErrorListener, identifica el tipo de excepcion que se presenta y añade a la variable msjError el respectivo mensaje //de errror public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { if (e != null) { msjError += ("Error en la linea: " + e.OffendingToken.Line + " columna: " + e.OffendingToken.Column + " "); if (e.GetType() == typeof(NoViableAltException)) { msjError += ("Error de tipo: No viable\n\n"); } else if (e.GetType() == typeof(NotSupportedException)) { msjError += ("Error de tipo: No soportado\n\n"); } else if (e.GetType() == typeof(NotImplementedException)) { msjError += ("Error de tipo: No implementado\n\n"); } else if (e.GetType() == typeof(NotFiniteNumberException)) { msjError += ("Error de tipo: Numero no finito\n\n"); } else if (e.GetType() == typeof(InputMismatchException)) { msjError += ("Error de tipo: Desajuste de entrada\n\n"); } else { msjError += "Error de tipo desconocido\n\n"; } } }
public override void SyntaxError(TextWriter output, IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { Error error = new Error(); if (recognizer.GetType() == typeof(BosParser)) { error.Stack = (recognizer as BosParser).GetRuleInvocationStackAsString(); } error.File = Path.GetFileName(e.InputStream.SourceName); error.Msg = $"{error.File}: {msg} at {line}:{charPositionInLine}"; if (offendingSymbol != null) { error.Symbol = offendingSymbol.Text; } if (e != null) { error.Exception = e.GetType().ToString(); } this.Errors.Add(error); }
public override void RecognitionException(RecognitionException e) { StringBuilder buf = new StringBuilder(50); buf.Append("exception\t"); buf.Append(e.GetType().Name); // dump only the data common to all exceptions for now buf.Append("\t"); buf.Append(e.Index); buf.Append("\t"); buf.Append(e.Line); buf.Append("\t"); buf.Append(e.CharPositionInLine); Transmit(buf.ToString()); }
public override void SyntaxError(TextWriter output, IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { if (e is NoViableAltException noViableAlt) { throw new AGPxException($"Unexpected token '{noViableAlt.OffendingToken.Text}' found after '{noViableAlt.StartToken.Text}'.", line, stylesheetSourceName); } #warning TODO: Customize message if (e is InputMismatchException inputMismatch) { throw new AGPxException(msg, line, stylesheetSourceName); // TODO: Customize error message } else { throw new NotImplementedException(e?.GetType()?.Name ?? msg); } }
public override 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); //Error.Write("{b:Red}{f:White}SYNTAX ERROR: {$0}{r}", e.OffendingToken.Line, 999, e.GetType().FullName); //NotifyErrorListeners(recognizer, e.Message, e); } else { if (e is InputMismatchException) { //ReportInputMismatch(recognizer, (InputMismatchException)e); } else { if (e is FailedPredicateException) { //ReportFailedPredicate(recognizer, (FailedPredicateException)e); Error.Write("{b:Red}{f:White}SYNTAX ERROR: {$0}{r}", e.OffendingToken.Line, 999, e.GetType().FullName); NotifyErrorListeners(recognizer, e.Message, e); } else { Error.Write("{b:Red}{f:White}SYNTAX ERROR: {$0}{r}", e.OffendingToken.Line, 999, e.GetType().FullName); NotifyErrorListeners(recognizer, e.Message, e); } } } }