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;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Fires ParseError event
 /// </summary>
 /// <param name="e">Event arguments</param>
 protected void OnParseError(ParseErrorEventArgs e)
 {
     if (ParseError != null)
     {
         ParseError(this, e);
     }
 }
Ejemplo n.º 4
0
 private static void OnProgramCommandParseResult(object sender, ParseErrorEventArgs e)
 {
     if (e.Error)
     {
         throw new ApplicationException("Unexpected error: " + e.ErrorMessage);
     }
 }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
 private void OnParseProgramCommandResult(object sender, ParseErrorEventArgs e)
 {
     ParseError = e.ErrorMessage;
     if (!e.Error)
     {
         currentTime = TimeSpan.FromMilliseconds(0);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 9
0
        protected virtual void OnParseError(ParseErrorEventArgs e)
        {
            var t = ParseError;

            if (t != null)
            {
                t(this, e);
            }
        }
Ejemplo n.º 10
0
        private void QTxtConverter_ParseError(object sender, ParseErrorEventArgs e)
        {
            _parseError = e;
            PrepareUI();

            lock (_sync)
            {
                Monitor.Wait(_sync);
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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() + "'";
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
                    }
                }
            }
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 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;
                 */
            }
        }
Ejemplo n.º 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
                      };
            }
        }
Ejemplo n.º 21
0
        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();
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 24
0
 static void csv_ParseError(object sender, ParseErrorEventArgs e)
 {
     MessageBox.Show(e.Error.Message, "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 27
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);
     }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 29
0
 public void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
 {
     outputBox.AppendText("Parse error\n");
 }
Ejemplo n.º 30
0
 void _Parser_OnParseError(LALRParser parser, ParseErrorEventArgs args)
 {
     Errors.Add("Parse error: '" + args.UnexpectedToken.ToString() + "'");
     args.Continue = ContinueMode.Stop;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
 }