Ejemplo n.º 1
0
        public void SyntaxError(
            TextWriter output,
            IRecognizer recognizer,
            S offendingSymbol,
            int line,
            int col,
            string msg,
            RecognitionException recognitionException)
        {
            if (this.firstTime)
            {
                try
                {
                    this.firstTime = false;
                    LASets        la_sets = new LASets();
                    IntervalSet   set     = la_sets.Compute(this.parser, this.tokenStream, line, col);
                    List <string> result  = new List <string>();

                    foreach (int r in set.ToList())
                    {
                        string rule_name = this.parser.Vocabulary.GetSymbolicName(r);
                        result.Add(rule_name);
                    }

                    string message;
                    if (result.Any())
                    {
                        message = $"Parse error line:{line}, col:{col}, expecting: {string.Join(", ", result)}";
                    }
                    else
                    {
                        message = $"Parse error: message:{msg} offendingSymbol: {offendingSymbol}, line:{line}, col:{col}";
                    }

                    this.parseException = new ParseException(message, recognitionException);
                }
                catch (Exception ex)
                {
                    this.parseException = new ParseException($"Unknown parse exception", ex);
                }
            }
        }
        public override void SyntaxError(TextWriter output, IRecognizer recognizer, S offendingSymbol, int line,
                                         int col, string msg, RecognitionException e)
        {
            this.hadError = true;
            if (this.firstTime)
            {
                try
                {
                    this.firstTime = false;
                    LASets        la_sets = new LASets();
                    IntervalSet   set     = la_sets.Compute(this.parser, this.tokenStream, line, col);
                    List <string> result  = new List <string>();
                    foreach (int r in set.ToList())
                    {
                        string rule_name = this.parser.Vocabulary.GetSymbolicName(r);
                        result.Add(rule_name);
                    }
                    if (result.Any())
                    {
                        System.Console.Error.WriteLine("Parse error line/col " + line + "/" + col
                                                       + ", expecting "
                                                       + string.Join(", ", result));
                    }
                    else
                    {
                        base.SyntaxError(output, recognizer, offendingSymbol, line, col, msg, e);
                    }

                    return;
                }
                catch (Exception)
                {
                }
            }
            base.SyntaxError(output, recognizer, offendingSymbol, line, col, msg, e);
        }