/// <summary> /// Replaces all node for which predicate returns true anywhere in the tree /// with a clone of template. /// </summary> /// <returns>the number of nodes replaced</returns> public int ReplaceNodes(NodePredicate predicate, Node template) { ReplaceVisitor visitor = new ReplaceVisitor(predicate, template); Accept(visitor); return(visitor.Matches); }
public virtual IEnumerable <EvalNode> Collect(NodePredicate predicate) { if (predicate(this)) { return new List <EvalNode>() { this } } ; else { return(Enumerable.Empty <EvalNode>()); } }
public override IEnumerable <EvalNode> Collect(NodePredicate predicate) { List <EvalNode> ret = new List <EvalNode>(); if (predicate(this)) { ret.Add(this); } foreach (var child in children) { ret.AddRange(child.Collect(predicate)); } return(ret); }
/// <summary> /// Replaces all occurrences of the pattern pattern anywhere in the tree /// with a clone of template. /// </summary> /// <returns>the number of nodes replaced</returns> public int ReplaceNodes(Node pattern, Node template) { NodePredicate predicate = new NodePredicate(pattern.Matches); return(ReplaceNodes(predicate, template)); }
public ReplaceVisitor(NodePredicate predicate, Node template) { _predicate = predicate; _template = template; }