Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
 public virtual IEnumerable <EvalNode> Collect(NodePredicate predicate)
 {
     if (predicate(this))
     {
         return new List <EvalNode>()
                {
                    this
                }
     }
     ;
     else
     {
         return(Enumerable.Empty <EvalNode>());
     }
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        /// <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));
        }
Ejemplo n.º 5
0
 public ReplaceVisitor(NodePredicate predicate, Node template)
 {
     _predicate = predicate;
     _template  = template;
 }