public void Error(Message msg) { GrammarSyntaxMessage syntaxMessage = msg as GrammarSyntaxMessage; if (syntaxMessage != null) { IToken token = syntaxMessage.offendingToken; if (token == null) { return; } AntlrParserTokenStream stream = syntaxMessage.exception.Input as AntlrParserTokenStream; if (stream == null) { return; } var parser = stream.Parser; if (parser == null) { return; } Span span = Span.FromBounds(token.StartIndex, token.StopIndex + 1); ParseErrorEventArgs e = new ParseErrorEventArgs(syntaxMessage.ToString(), span); parser.OnParseError(e); return; } }
void target_ParseError(object sender, ParseErrorEventArgs e) { string payload = Encoding.Default.GetString((byte[])e.Payload); TestContext.WriteLine("Unable to parse Syslog message:\n{0}\n{1}", payload, e.ExceptionObject); logs_error += 1; }
/// <summary> /// Fires ParseError event /// </summary> /// <param name="e">Event arguments</param> protected void OnParseError(ParseErrorEventArgs e) { if (ParseError != null) { ParseError(this, e); } }
private static void OnProgramCommandParseResult(object sender, ParseErrorEventArgs e) { if (e.Error) { throw new ApplicationException("Unexpected error: " + e.ErrorMessage); } }
private void csv_ParseError(object sender, ParseErrorEventArgs e) { mCsvErrors++; if (mCsvErrors > CSV_ERRORS_TO_SHOW) { return; } string errorMessage; var dataIndex = e.Error.Message.IndexOf("Current raw data", StringComparison.OrdinalIgnoreCase); if (dataIndex > 0) { errorMessage = e.Error.Message.Substring(0, dataIndex); } else if (e.Error.Message.Length > 250) { errorMessage = e.Error.Message.Substring(0, 250); } else { errorMessage = e.Error.Message; } if (errorMessage.StartsWith("The CSV")) { MessageBox.Show("The data file" + errorMessage.Substring(7), "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show(errorMessage, "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void OnParseProgramCommandResult(object sender, ParseErrorEventArgs e) { ParseError = e.ErrorMessage; if (!e.Error) { currentTime = TimeSpan.FromMilliseconds(0); } }
private void csv_ParseError(object sender, ParseErrorEventArgs e) { mCsvErrors++; if (mCsvErrors < 5) { MessageBox.Show(e.Error.Message, "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
void csv_ParseError(object sender, ParseErrorEventArgs e) { // if the error is that a field is missing, then skip to next line if (e.Error is MissingFieldCsvException) { Log.Info("--MISSING FIELD ERROR OCCURRED"); e.Action = ParseErrorAction.AdvanceToNextLine; } }
protected virtual void OnParseError(ParseErrorEventArgs e) { var t = ParseError; if (t != null) { t(this, e); } }
private void QTxtConverter_ParseError(object sender, ParseErrorEventArgs e) { _parseError = e; PrepareUI(); lock (_sync) { Monitor.Wait(_sync); } }
/// <summary> /// Fires an error occurred event. /// </summary> /// <param name="code">The associated error code.</param> protected void RaiseErrorOccurred(ErrorCode code) { if (ErrorOccurred != null) { var pck = new ParseErrorEventArgs((int)code, Errors.GetError(code)); pck.Line = _src.Line; pck.Column = _src.Column; ErrorOccurred(this, pck); } }
private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args) { failLineNumber = args.UnexpectedToken.Location.LineNr; failColumnNumber = args.UnexpectedToken.Location.ColumnNr; failLength = args.UnexpectedToken.Text.Length; failCategory = "Syntax Error"; failMessage = "'" + args.UnexpectedToken.ToString() + "'" + Environment.NewLine + "Line " + (failLineNumber + 1) + ", Column " + (failColumnNumber + 1) + ", Length " + failLength + Environment.NewLine + "Expecting one of: '" + args.ExpectedTokens.ToString() + "'"; }
/// <summary> /// Fires an error occurred event. /// </summary> /// <param name="code">The associated error code.</param> void RaiseErrorOccurred(ErrorCode code) { if (ErrorOccurred != null) { var pck = new ParseErrorEventArgs((int)code, Errors.GetError(code)); pck.Line = tokenizer.Stream.Line; pck.Column = tokenizer.Stream.Column; ErrorOccurred(this, pck); } }
private void ParserLoop(object queue) { int queueId = (int)queue; try { while (true) { byte[] payload = _byteQueues[queueId].Dequeue(); try { SyslogMessage newMessage = SyslogMessage.Parse(payload); ForwardMessage(newMessage); } catch (FormatException ex) { ParseErrorEventArgs e = new ParseErrorEventArgs(payload, ex, false); OnParseError(e); } } } catch (ThreadInterruptedException) { } finally { byte[][] finalMessages = _byteQueues[queueId].FlushAndDispose(); if (finalMessages.GetLength(0) > 0) { Log.Notice("Inbound channel {0} still needs to process {0} pending messages. Delaying stop.", ToString(), finalMessages.GetLength(0)); } foreach (byte[] payload in finalMessages) { try { SyslogMessage newMessage = SyslogMessage.Parse(payload); ForwardMessage(newMessage); } catch (FormatException ex) { ParseErrorEventArgs e = new ParseErrorEventArgs(payload, ex, false); OnParseError(e); } } } }
void csv_ParseError(object sender, ParseErrorEventArgs e) { var exMissingField = e.Error as MissingFieldCsvException; var exMalrormed = e.Error as MalformedCsvException; long lineNumber = e.Error.CurrentRecordIndex + 1; if (exMissingField != null) { m_Errors.Add(new CsvError(exMissingField.CurrentRecordIndex, exMissingField.CurrentFieldIndex, exMissingField.CurrentPosition, "errMissingField", null, GetLine(e.Error.RawData, lineNumber), false)); } else if (exMalrormed != null) { m_Errors.Add(new CsvError(exMalrormed.CurrentRecordIndex, exMalrormed.CurrentFieldIndex, exMalrormed.CurrentPosition, "errMalFormedCvs", exMalrormed.CurrentPosition.ToString(CultureInfo.InvariantCulture), GetLine(e.Error.RawData, lineNumber))); } e.Action = ParseErrorAction.AdvanceToNextLine; }
private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args) { Context.ExpectedTokens = args.ExpectedTokens.ToString(); if (args.NextToken != null) { Context.NextToken = args.NextToken.ToString(); } if (args.UnexpectedToken != null) { Context.UnexpectedToken = args.UnexpectedToken.ToString(); } throw new ParseException(args); }
public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e) { string header = GetErrorHeader(e); string message = GetErrorMessage(e, tokenNames); Span span = new Span(); if (e.Token != null) { span = Span.FromBounds(e.Token.StartIndex, e.Token.StopIndex + 1); } ParseErrorEventArgs args = new ParseErrorEventArgs(message, span); OnParseError(args); base.DisplayRecognitionError(tokenNames, e); }
private static void csv_ParseError(object sender, ParseErrorEventArgs e) { // if the error is that a field is missing, then skip to next line if (e.Error is MissingFieldCsvException) { //Log.Write(e.Error, "--MISSING FIELD ERROR OCCURRED!" + Environment.NewLine); e.Action = ParseErrorAction.AdvanceToNextLine; } else if (e.Error is MalformedCsvException) { //Log.Write(e.Error, "--MALFORMED CSV ERROR OCCURRED!" + Environment.NewLine); e.Action = ParseErrorAction.AdvanceToNextLine; } else { //Log.Write(e.Error, "--UNKNOWN PARSE ERROR OCCURRED!" + Environment.NewLine); e.Action = ParseErrorAction.AdvanceToNextLine; } }
private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args) { AddViewItem("Parse error", null, "Expecting the following tokens:", args.ExpectedTokens.ToString(), "", 5); errors++; if (errors <= maxerrors) { args.Continue = ContinueMode.Skip; // example for inserting a new token /* * args.Continue = ContinueMode.Insert; * TerminalToken token = new TerminalToken((SymbolTerminal)parser.Symbols.Get(4), * "555", * new Location(0, 0, 0)); * args.NextToken = token; */ } }
private void csvReader_ParseError(object sender, ParseErrorEventArgs e) { // skip over incomplete data rows, but let all other exceptions bubble up if (e.Error is MissingFieldCsvException) { _logger.Warn(string.Format("Skipping recordIndex={0} because of missing expected field at index {1}", e.Error.CurrentRecordIndex, e.Error.CurrentFieldIndex)); e.Action = ParseErrorAction.AdvanceToNextLine; } else { string msg = string.Format("Unrecoverable parsing problem encountered at filePosition={0} (recordIndex={0}, fieldIndex={1})", e.Error.CurrentPosition, e.Error.CurrentRecordIndex, e.Error.CurrentFieldIndex); _logger.ErrorException(msg, e.Error); throw new CsvParsingException(msg, e.Error) { FilePosition = e.Error.CurrentPosition }; } }
public void AddError(ParseErrorEventArgs error) { _source.Add(new ParseErrorListItem(error)); var control = Control; if (control.InvokeRequired) { control.Invoke((MethodInvoker) delegate { Control.ResultBox.DataSource = _source; Control.ResultBox.DisplayMember = "Value"; control.Refresh(); }); } else { Control.ResultBox.DataSource = _source; Control.ResultBox.DisplayMember = "Value"; control.Refresh(); } }
public void AddError(ParseErrorEventArgs error) { _source.Add(new ParseErrorListItem(error)); var control = UserControl as SimpleListControl; Debug.Assert(control != null); if (control.InvokeRequired) { control.Invoke((MethodInvoker) delegate { control.ResultBox.DataSource = _source; control.ResultBox.DisplayMember = "Value"; control.Refresh(); }); } else { control.ResultBox.DataSource = _source; control.ResultBox.DisplayMember = "Value"; control.Refresh(); } }
public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e) { string header = GetErrorHeader(e); string message = GetErrorMessage(e, tokenNames); Span span = new Span(); object positionNode = null; IPositionTrackingStream positionTrackingStream = input as IPositionTrackingStream; if (positionTrackingStream != null) { positionNode = positionTrackingStream.GetKnownPositionElement(false); if (positionNode == null) { positionNode = positionTrackingStream.GetKnownPositionElement(true); } } if (positionNode != null) { IToken token = input.TreeAdaptor.GetToken(positionNode); if (token != null) { span = Span.FromBounds(token.StartIndex, token.StopIndex + 1); } } else if (e.Token != null) { span = Span.FromBounds(e.Token.StartIndex, e.Token.StopIndex + 1); } ParseErrorEventArgs args = new ParseErrorEventArgs(message, span); OnParseError(args); base.DisplayRecognitionError(tokenNames, e); }
static void csv_ParseError(object sender, ParseErrorEventArgs e) { MessageBox.Show(e.Error.Message, "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
/// <summary> /// Called once a helper class finds a parse error. /// </summary> /// <param name="sender">The helper that encountered the error.</param> /// <param name="e">The arguments passed from the helper instance.</param> void ParseErrorOccurred(object sender, ParseErrorEventArgs e) { Debug.WriteLine(e); }
public ParseErrorListItem(ParseErrorEventArgs error) { _error = error; }
/// <summary> /// Fires an error occurred event (usually originated by another tokenizer). /// </summary> /// <param name="sender">The original sender.</param> /// <param name="eventArgs">The arguments of the event.</param> protected void RaiseErrorOccurred(Object sender, ParseErrorEventArgs eventArgs) { if (ErrorOccurred != null) ErrorOccurred(sender, eventArgs); }
public void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args) { outputBox.AppendText("Parse error\n"); }
void _Parser_OnParseError(LALRParser parser, ParseErrorEventArgs args) { Errors.Add("Parse error: '" + args.UnexpectedToken.ToString() + "'"); args.Continue = ContinueMode.Stop; }
private void lalrParser_OnParseError(LALRParser parser, ParseErrorEventArgs e) { // Ignore global parse errors OnParseComplete(EventArgs.Empty); }
/// <summary> /// Constructor /// </summary> /// <param name="arg">Parse Error Event Aruguments</param> public ParseException(ParseErrorEventArgs arg) : base(SharedStrings.WARNING_COMMAND_SYNTAX_ERROR + "\r\r" + SharedStrings.UNEXPECTED_TOKEN, arg.UnexpectedToken.Text) { args = arg; }
/** * Listener to set the parse error so it can be surfaced to the caller. */ private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args) { this.error = "Parse error caused by token: '" + args.UnexpectedToken.ToString() + "'"; }
private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args) { throw new ParseException(args); }