コード例 #1
0
 public override void EnterId([NotNull] ANTLRv4Parser.IdContext context)
 {
     if (context.Parent is ANTLRv4Parser.ModeSpecContext)
     {
         TerminalNodeImpl term = context.GetChild(0) as TerminalNodeImpl;
         string           id   = term.GetText();
         ISymbol          sym  = new ModeSymbol(id, term.Symbol);
         _pd.RootScope.define(ref sym);
         CombinedScopeSymbol s = (CombinedScopeSymbol)sym;
         _pd.Attributes[context] = new List <CombinedScopeSymbol>()
         {
             s
         };
         _pd.Attributes[context.GetChild(0)] = new List <CombinedScopeSymbol>()
         {
             s
         };
     }
     else if (context.Parent is ANTLRv4Parser.IdListContext && context.Parent?.Parent is ANTLRv4Parser.ChannelsSpecContext)
     {
         TerminalNodeImpl term = context.GetChild(0) as TerminalNodeImpl;
         string           id   = term.GetText();
         ISymbol          sym  = new ChannelSymbol(id, term.Symbol);
         _pd.RootScope.define(ref sym);
         CombinedScopeSymbol s = (CombinedScopeSymbol)sym;
         _pd.Attributes[context] = new List <CombinedScopeSymbol>()
         {
             s
         };
         _pd.Attributes[term] = new List <CombinedScopeSymbol>()
         {
             s
         };
     }
 }
コード例 #2
0
            public override void EnterCat([NotNull] lbnfParser.CatContext context)
            {
                if (context.Identifier() == null)
                {
                    return;
                }
                var id = context.Identifier().GetText();

                if (context.Parent is lbnfParser.DefContext ||
                    context.Parent is lbnfParser.CatContext)
                {
                    var     frontier = TreeEdits.Frontier(context);
                    var     list     = frontier.Select(t => t.Symbol).ToList();
                    ISymbol sym      = new NonterminalSymbol(id, list);
                    _pd.RootScope.define(ref sym);
                    CombinedScopeSymbol s = (CombinedScopeSymbol)sym;
                    _pd.Attributes[context] = new List <CombinedScopeSymbol>()
                    {
                        s
                    };
                    foreach (var tr in frontier)
                    {
                        _pd.Attributes[tr] = new List <CombinedScopeSymbol>()
                        {
                            s
                        }
                    }
                    ;
                }
            }
        }
コード例 #3
0
        public override void EnterLexerRuleSpec([NotNull] ANTLRv4Parser.LexerRuleSpecContext context)
        {
            int i;

            for (i = 0; i < context.ChildCount; ++i)
            {
                if (!(context.GetChild(i) is TerminalNodeImpl))
                {
                    continue;
                }

                TerminalNodeImpl c = context.GetChild(i) as TerminalNodeImpl;
                if (c.Symbol.Type == ANTLRv4Lexer.TOKEN_REF)
                {
                    break;
                }
            }
            if (i == context.ChildCount)
            {
                return;
            }

            TerminalNodeImpl token_ref = context.GetChild(i) as TerminalNodeImpl;
            string           id        = token_ref.GetText();
            ISymbol          sym       = new TerminalSymbol(id, token_ref.Symbol);

            _pd.RootScope.define(ref sym);
            CombinedScopeSymbol s = (CombinedScopeSymbol)sym;

            _pd.Attributes[context] = new List <CombinedScopeSymbol>()
            {
                s
            };
            _pd.Attributes[context.GetChild(i)] = new List <CombinedScopeSymbol>()
            {
                s
            };
        }
コード例 #4
0
            public override void EnterSymbol([NotNull] W3CebnfParser.SymbolContext context)
            {
                var token_ref = context.SYMBOL();

                if (token_ref != null && context.Parent is W3CebnfParser.LhsContext)
                {
                    string  id  = token_ref.GetText();
                    ISymbol sym = new NonterminalSymbol(id, new List <IToken>()
                    {
                        token_ref.Symbol
                    });
                    _pd.RootScope.define(ref sym);
                    CombinedScopeSymbol s = (CombinedScopeSymbol)sym;
                    _pd.Attributes[context] = new List <CombinedScopeSymbol>()
                    {
                        s
                    };
                    _pd.Attributes[token_ref] = new List <CombinedScopeSymbol>()
                    {
                        s
                    };
                }
            }
コード例 #5
0
ファイル: Module.cs プロジェクト: tnsr1/AntlrVSIX
        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
                });
            }
        }