Antlr4.Runtime.Tree.Xpath.XPath.Evaluate C# (CSharp) Method

Evaluate() public method

Return a list of all nodes starting at t as root that satisfy the path. The root / is relative to the node passed to Evaluate(Antlr4.Runtime.Tree.IParseTree) .
public Evaluate ( IParseTree t ) : ICollection
t IParseTree
return ICollection
        public virtual ICollection<IParseTree> Evaluate(IParseTree t)
        {
            ParserRuleContext dummyRoot = new ParserRuleContext();
            dummyRoot.children = Antlr4.Runtime.Sharpen.Collections.SingletonList(t);
            // don't set t's parent.
            ICollection<IParseTree> work = new[] { dummyRoot };
            int i = 0;
            while (i < elements.Length)
            {
                HashSet<IParseTree> visited = new HashSet<IParseTree>();
                ICollection<IParseTree> next = new List<IParseTree>();
                foreach (IParseTree node in work)
                {
                    if (node.ChildCount > 0)
                    {
                        // only try to match next element if it has children
                        // e.g., //func/*/stat might have a token node for which
                        // we can't go looking for stat nodes.
                        ICollection<IParseTree> matching = elements[i].Evaluate(node);
                        foreach (IParseTree parseTree in matching)
                        {
                            if (visited.Add(parseTree))
                                next.Add(parseTree);
                        }
                    }
                }
                i++;
                work = next;
            }
            return work;
        }

Usage Example

コード例 #1
0
 public static ICollection <IParseTree> FindAll(IParseTree tree, string xpath, Parser parser)
 {
     Antlr4.Runtime.Tree.Xpath.XPath p = new Antlr4.Runtime.Tree.Xpath.XPath(parser, xpath);
     return(p.Evaluate(tree));
 }
All Usage Examples Of Antlr4.Runtime.Tree.Xpath.XPath::Evaluate