Beispiel #1
0
        public override void SyntaxError(TextWriter output, IRecognizer recognizer, S offendingSymbol, int line,
                                         int col, string msg, RecognitionException e)
        {
            had_error = true;
            if (_first_time)
            {
                try
                {
                    _first_time = false;
                    LASets        la_sets = new LASets();
                    IntervalSet   set     = la_sets.Compute(_parser, _token_stream, line, col);
                    List <string> result  = new List <string>();
                    foreach (int r in set.ToList())
                    {
                        string rule_name = _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);
        }
Beispiel #2
0
        public virtual List <string> Candidates(int char_index)
        {
            Workspaces.Document item = Item;
            string ffn             = item.FullPath;
            IGrammarDescription gd = GrammarDescriptionFactory.Create(ffn);

            if (gd == null)
            {
                throw new Exception();
            }

            string code = Code.Substring(0, char_index);

            gd.Parse(code, out CommonTokenStream tok_stream, out Parser parser, out Lexer lexer, out IParseTree pt);
            LASets        la_sets = new LASets();
            IntervalSet   int_set = la_sets.Compute(parser, tok_stream);
            List <string> result  = new List <string>();

            foreach (int r in int_set.ToList())
            {
                string rule_name = Lexer.RuleNames[r];
                result.Add(rule_name);
            }
            return(result);
        }
        public void TestToList()
        {
            IntervalSet s = IntervalSet.Of(20, 25);

            s.Add(50, 55);
            s.Add(5, 5);
            int[]       expecting = { 5, 20, 21, 22, 23, 24, 25, 50, 51, 52, 53, 54, 55 };
            IList <int> result    = s.ToList();

            CollectionAssert.AreEquivalent(expecting, result.ToArray());
        }
Beispiel #4
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);
                }
            }
        }