Antlr4.Tool.Ast.GrammarAST.GetNodesWithType C# (CSharp) Метод

GetNodesWithType() публичный Метод

public GetNodesWithType ( Antlr4.Runtime.Misc.IntervalSet types ) : IList
types Antlr4.Runtime.Misc.IntervalSet
Результат IList
        public virtual IList<GrammarAST> GetNodesWithType(IntervalSet types)
        {
            IList<GrammarAST> nodes = new List<GrammarAST>();
            LinkedList<GrammarAST> work = new LinkedList<GrammarAST>();
            work.AddLast(this);
            GrammarAST t;
            while (work.Count > 0)
            {
                t = work.First.Value;
                work.RemoveFirst();
                if (types == null || types.Contains(t.Type))
                    nodes.Add(t);
                if (t.Children != null)
                {
                    foreach (var child in t.GetChildrenAsArray())
                        work.AddLast(child);
                }
            }
            return nodes;
        }

Same methods

GrammarAST::GetNodesWithType ( int ttype ) : IList

Usage Example

Пример #1
0
        public static void AugmentTokensWithOriginalPosition(Grammar g, GrammarAST tree)
        {
            if (tree == null)
                return;

            IList<GrammarAST> optionsSubTrees = tree.GetNodesWithType(ANTLRParser.ELEMENT_OPTIONS);
            for (int i = 0; i < optionsSubTrees.Count; i++)
            {
                GrammarAST t = optionsSubTrees[i];
                CommonTree elWithOpt = (CommonTree)t.Parent;
                if (elWithOpt is GrammarASTWithOptions)
                {
                    IDictionary<string, GrammarAST> options = ((GrammarASTWithOptions)elWithOpt).GetOptions();
                    if (options.ContainsKey(LeftRecursiveRuleTransformer.TOKENINDEX_OPTION_NAME))
                    {
                        GrammarToken newTok = new GrammarToken(g, elWithOpt.Token);
                        newTok.originalTokenIndex = int.Parse(options[LeftRecursiveRuleTransformer.TOKENINDEX_OPTION_NAME].Text);
                        elWithOpt.Token = newTok;

                        GrammarAST originalNode = g.ast.GetNodeWithTokenIndex(newTok.TokenIndex);
                        if (originalNode != null)
                        {
                            // update the AST node start/stop index to match the values
                            // of the corresponding node in the original parse tree.
                            elWithOpt.TokenStartIndex = originalNode.TokenStartIndex;
                            elWithOpt.TokenStopIndex = originalNode.TokenStopIndex;
                        }
                        else
                        {
                            // the original AST node could not be located by index;
                            // make sure to assign valid values for the start/stop
                            // index so toTokenString will not throw exceptions.
                            elWithOpt.TokenStartIndex = newTok.TokenIndex;
                            elWithOpt.TokenStopIndex = newTok.TokenIndex;
                        }
                    }
                }
            }
        }
All Usage Examples Of Antlr4.Tool.Ast.GrammarAST::GetNodesWithType