/
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; }
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)); }