Esempio n. 1
0
 protected void run(Antlr4.Runtime.ICharStream stream)
 {
     try
     {
         langLexer    lexer         = new langLexer(stream);
         ErrorHandler dream_catcher = new ErrorHandler(lexer, this);
         lexer.RemoveErrorListeners();
         lexer.AddErrorListener(dream_catcher);
         CommonTokenStream tokens = new CommonTokenStream(lexer);
         langParser        parser = new langParser(tokens);
         parser.RemoveErrorListeners();
         parser.AddErrorListener(dream_catcher);
         Antlr4.Runtime.Tree.IParseTree root = parser.prog();
         if (this.can_run)
         {
             //foreach (var ins in root_space.instructions)
             //	Console.WriteLine(ins.GetType().Name);
             ParseTreeWalker walker = new ParseTreeWalker();
             walker.Walk(new SiBtyInterpreter(this.root_space), root);
             this.root_space.exec();
         }
     }
     catch (Errors.IdentifierError e)
     {
         Console.Write("An IdentifierError has been raised :{0}", e.message());
     }
     catch (Errors.NilClassException)
     {
         Console.Write("A NilClassError has been raised");
     }
     catch (Errors.OperatorError)
     {
         Console.Write("An OperatorError has been raised");
     }
     catch (Errors.ParameterError)
     {
         Console.Write("An ParameterError has been raised");
     }
     catch (Errors.VariableError e)
     {
         Console.Write("An VariableError has been raise :{0}", e.message());
     }
     catch (Errors.TypeCastingError)
     {
         Console.Write("An TypeCastingError has been raised");
     }
     catch (System.Collections.Generic.KeyNotFoundException e)
     {
         var stackTrace = new StackTrace(e);
         Console.Write("An ObjectMemberNotImplementedError has been raised: {0}",
                       stackTrace.GetFrame(1).GetMethod().Name
                       );
     }
     catch (Errors.HashMemberNotFoundError e)
     {
         Console.Write("An HashMemberNotFoundError has been raised: {0}",
                       e.message()
                       );
     }
 }
Esempio n. 2
0
 protected SyneryInterpretationException(Antlr4.Runtime.ParserRuleContext tree,
                                         System.Runtime.Serialization.SerializationInfo info,
                                         System.Runtime.Serialization.StreamingContext context)
     : base(info, context)
 {
     ParseTree = tree;
 }
Esempio n. 3
0
        public int GetTag(int index, Document doc)
        {
            ParsingResults pd        = ParsingResultsFactory.Create(doc);
            var            workspace = doc.Workspace;

            if (pd.ParseTree == null)
            {
                Compile(workspace);
            }

            Antlr4.Runtime.Tree.IParseTree pt = LanguageServer.Util.Find(index, doc);
            var gd = ParserDescriptionFactory.Create(doc);

            if (pt == null)
            {
                return(-1);
            }

            Antlr4.Runtime.Tree.IParseTree p = pt;
            TerminalNodeImpl q     = p as Antlr4.Runtime.Tree.TerminalNodeImpl;
            bool             found = pd.PopupList.TryGetValue(q, out int tag_type);

            if (found)
            {
                return(tag_type);
            }

            if (q.Symbol == null)
            {
                return(-1);
            }

            bool found2 = pd.Comments.TryGetValue(q.Symbol, out int tag2);

            if (found2)
            {
                return(tag2);
            }

            return(-1);
        }
Esempio n. 4
0
        public static int GetTag(int index, Document doc)
        {
            ParserDetails pd = ParserDetailsFactory.Create(doc);

            if (pd.ParseTree == null)
            {
                LanguageServer.Module.Compile();
            }

            Antlr4.Runtime.Tree.IParseTree pt = LanguageServer.Util.Find(index, doc);
            IGrammarDescription            gd = GrammarDescriptionFactory.Create(doc.FullPath);

            if (pt == null)
            {
                return(-1);
            }

            Antlr4.Runtime.Tree.IParseTree p = pt;
            TerminalNodeImpl q     = p as Antlr4.Runtime.Tree.TerminalNodeImpl;
            bool             found = pd.Tags.TryGetValue(q, out int tag_type);

            if (found)
            {
                return(tag_type);
            }

            if (q.Symbol == null)
            {
                return(-1);
            }

            bool found2 = pd.Comments.TryGetValue(q.Symbol, out int tag2);

            if (found2)
            {
                return(tag2);
            }

            return(-1);
        }
Esempio n. 5
0
        public DocumentSymbol GetDocumentSymbol(int index, Document doc)
        {
            ParsingResults pd        = ParsingResultsFactory.Create(doc);
            var            workspace = doc.Workspace;

            if (pd.ParseTree == null)
            {
                Compile(workspace);
            }

            Antlr4.Runtime.Tree.IParseTree pt = LanguageServer.Util.Find(index, doc);
            var gd = ParserDescriptionFactory.Create(doc);

            if (pt == null)
            {
                return(default(DocumentSymbol));
            }

            Antlr4.Runtime.Tree.IParseTree p = pt;
            TerminalNodeImpl q     = p as Antlr4.Runtime.Tree.TerminalNodeImpl;
            bool             found = pd.PopupList.TryGetValue(q, out int tag_type);

            if (!found)
            {
                return(null);
            }

            if (q.Symbol == null)
            {
                return(null);
            }

            return(new DocumentSymbol()
            {
                name = q.Symbol.Text,
                range = new Workspaces.Range(q.Symbol.StartIndex, q.Symbol.StopIndex),
                kind = tag_type
            });
        }
Esempio n. 6
0
        //выполнить запрос
        private void requestBtn_Click(object sender, EventArgs e)
        {
            resultBox.Text = "";
            resultBox.Text = "";

            requestList.AddStr(requestBox.Text);

            Antlr4.Runtime.ICharStream input = new Antlr4.Runtime.AntlrInputStream(requestBox.Text);
            PreSQLLexer lexer = new PreSQLLexer(input);

            Antlr4.Runtime.CommonTokenStream tokens = new Antlr4.Runtime.CommonTokenStream(lexer);
            PreSQLParser parser = new PreSQLParser(tokens);

            parser.RemoveErrorListeners();                // remove ConsoleErrorListener
            parser.AddErrorListener(new ErrorListener()); // добавит листенер, который будет сообщать об ошибках распарсивания
            //parser.AddParseListener(new Listener()); // add ours
            parser.BuildParseTree = true;
            Antlr4.Runtime.Tree.IParseTree tree = parser.parse();                                    // получить дерево

            resultBox.Text += tree.ToStringTree(parser) + Environment.NewLine + Environment.NewLine; // print LISP-style tree

            // Анализируем результаты разбора. Если были синтаксические ошибки, выдадим лог анализа
            if (parser.NumberOfSyntaxErrors != 0)
            {
                resultBox.Text += "> Parsing Error!" + Environment.NewLine;
            }
            else
            {//строим дерево
                treeView.Nodes.Clear();
                th.LoadNode(null, tree);

                resultBox.Text += "> Parsing Ok!" + Environment.NewLine;
                Visitor visitor = new Visitor(this);
                //запускаем Визитор
                // он проходит по дереву, определяет SQL-оператор и выполняет действие в зависимости(см. файлVisitor)
                visitor.Visit(tree);
            }
        }
Esempio n. 7
0
        public static DocumentSymbol GetDocumentSymbol(int index, Document doc)
        {
            ParserDetails pd = ParserDetailsFactory.Create(doc);

            if (pd.ParseTree == null)
            {
                LanguageServer.Module.Compile();
            }

            Antlr4.Runtime.Tree.IParseTree pt = LanguageServer.Util.Find(index, doc);
            IGrammarDescription            gd = GrammarDescriptionFactory.Create(doc.FullPath);

            if (pt == null)
            {
                return(default(DocumentSymbol));
            }

            Antlr4.Runtime.Tree.IParseTree p = pt;
            TerminalNodeImpl q     = p as Antlr4.Runtime.Tree.TerminalNodeImpl;
            bool             found = pd.Tags.TryGetValue(q, out int tag_type);

            if (!found)
            {
                return(null);
            }

            if (q.Symbol == null)
            {
                return(null);
            }

            return(new DocumentSymbol()
            {
                name = q.Symbol.Text,
                range = new Workspaces.Range(q.Symbol.StartIndex, q.Symbol.StopIndex),
                kind = tag_type
            });
        }
Esempio n. 8
0
        public static QuickInfo GetQuickInfo(int index, Document doc)
        {
            ParserDetails pd = ParserDetailsFactory.Create(doc);

            if (pd.ParseTree == null)
            {
                LanguageServer.Module.Compile();
            }

            Antlr4.Runtime.Tree.IParseTree pt = LanguageServer.Util.Find(index, doc);
            IGrammarDescription            gd = GrammarDescriptionFactory.Create(doc.FullPath);

            if (pt == null)
            {
                return(null);
            }

            Antlr4.Runtime.Tree.IParseTree p = pt;
            pd.Attributes.TryGetValue(p, out IList <CombinedScopeSymbol> list_value);
            if (list_value == null)
            {
                return(null);
            }

            TerminalNodeImpl q     = p as Antlr4.Runtime.Tree.TerminalNodeImpl;
            Range            range = new Workspaces.Range(new Workspaces.Index(q.Symbol.StartIndex), new Workspaces.Index(q.Symbol.StopIndex + 1));
            bool             found = pd.Tags.TryGetValue(q, out int tag_type);

            if (!found)
            {
                return(null);
            }

            if (list_value == null || list_value.Count == 0)
            {
                return(new QuickInfo()
                {
                    Display = gd.Map[tag_type], Range = range
                });
            }
            if (list_value.Count == 1)
            {
                CombinedScopeSymbol value = list_value.First();
                ISymbol             name  = value as Symtab.ISymbol;
                string show = name?.Name;
                if (value is Symtab.Literal)
                {
                    show = ((Symtab.Literal)value).Cleaned;
                }
                if (gd.PopUpDefinition[tag_type] != null)
                {
                    Func <ParserDetails, IParseTree, string> fun = gd.PopUpDefinition[tag_type];
                    string mess = fun(pd, p);
                    if (mess != null)
                    {
                        return(new QuickInfo()
                        {
                            Display = mess, Range = range
                        });
                    }
                }
                string display = gd.Map[tag_type]
                                 + "\n"
                                 + show;
                return(new QuickInfo()
                {
                    Display = display, Range = range
                });
            }
            {
                string display = "Ambiguous -- ";
                foreach (CombinedScopeSymbol value in list_value)
                {
                    ISymbol name = value as Symtab.ISymbol;
                    string  show = name?.Name;
                    if (value is Symtab.Literal)
                    {
                        show = ((Symtab.Literal)value).Cleaned;
                    }
                    if (gd.PopUpDefinition[tag_type] != null)
                    {
                        Func <ParserDetails, IParseTree, string> fun = gd.PopUpDefinition[tag_type];
                        string mess = fun(pd, p);
                        if (mess != null)
                        {
                            display = display + mess;
                        }
                    }
                    else
                    {
                        display = display + gd.Map[tag_type]
                                  + "\n"
                                  + show;
                    }
                }
                return(new QuickInfo()
                {
                    Display = display, Range = range
                });
            }
        }
        private static ExpressionTree ApplyToParseTree(CompilationContext compilationContext, ICodeHierarchyNode expressionParent, Antlr4.Runtime.Tree.IParseTree antlrContext)
        {
            compilationContext.PushParsingContext();

            var visitor = new ExpressionCreationVisitor(compilationContext);

            visitor.Visit(antlrContext);

            compilationContext.SetParsingAntlrContext(null);

            var result = new ExpressionBuilder().Build(compilationContext, expressionParent, visitor.Sequence, visitor.WholeExpressonAntlrContext);

            compilationContext.PopParsingContext();

            return(result);
        }
Esempio n. 10
0
 public object Visit(Antlr4.Runtime.Tree.IParseTree tree)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 11
0
 public SyneryInterpretationException(Antlr4.Runtime.ParserRuleContext tree, string message, Exception inner)
     : base(message, inner)
 {
     ParseTree = tree;
 }