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);
     }
 }
Beispiel #4
0
 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);
            }
        }
Beispiel #6
0
 private void OnParseProgramCommandResult(object sender, ParseErrorEventArgs e)
 {
     ParseError = e.ErrorMessage;
     if (!e.Error)
     {
         currentTime = TimeSpan.FromMilliseconds(0);
     }
 }
Beispiel #7
0
        private void csv_ParseError(object sender, ParseErrorEventArgs e)
        {
            mCsvErrors++;

            if (mCsvErrors < 5)
            {
                MessageBox.Show(e.Error.Message, "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Beispiel #8
0
 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;
     }
 }
Beispiel #9
0
        protected virtual void OnParseError(ParseErrorEventArgs e)
        {
            var t = ParseError;

            if (t != null)
            {
                t(this, e);
            }
        }
Beispiel #10
0
        private void QTxtConverter_ParseError(object sender, ParseErrorEventArgs e)
        {
            _parseError = e;
            PrepareUI();

            lock (_sync)
            {
                Monitor.Wait(_sync);
            }
        }
Beispiel #11
0
 /// <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);
     }
 }
Beispiel #12
0
 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() + "'";
 }
Beispiel #13
0
 /// <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);
     }
 }
Beispiel #14
0
        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);
                    }
                }
            }
        }
Beispiel #15
0
        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;
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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);
        }
Beispiel #18
0
 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;
     }
 }
Beispiel #19
0
        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;
                 */
            }
        }
Beispiel #20
0
        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();
            }
        }
Beispiel #22
0
        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();
            }
        }
Beispiel #23
0
        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);
        }
Beispiel #24
0
 static void csv_ParseError(object sender, ParseErrorEventArgs e)
 {
     MessageBox.Show(e.Error.Message, "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
 }
Beispiel #25
0
 /// <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.
 /// </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);
     }
 }
Beispiel #28
0
 /// <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);
 }
Beispiel #29
0
 public void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
 {
     outputBox.AppendText("Parse error\n");
 }
Beispiel #30
0
 void _Parser_OnParseError(LALRParser parser, ParseErrorEventArgs args)
 {
     Errors.Add("Parse error: '" + args.UnexpectedToken.ToString() + "'");
     args.Continue = ContinueMode.Stop;
 }
Beispiel #31
0
 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;
 }
Beispiel #33
0
 /**
  * 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);
 }