TakeChildren() public method

public TakeChildren ( QueryListNode from ) : void
from QueryListNode
return void
        public override QueryNode Trim()
        {
            // Trim depth first
            List<QueryNode> copy = new List<QueryNode> (Children);
            foreach (QueryNode child in copy)
                child.Trim ();

            if (Keyword == Keyword.Not) {
                if (ChildCount != 1) {
                    if (Parent != null) {
                        Parent.RemoveChild (this);
                    } else {
                        return null;
                    }
                }
            } else {
                if (ChildCount <= 1) {
                    if (Parent != null) {
                        QueryListNode p = Parent;
                        p.RemoveChild (this);
                        p.TakeChildren (this);
                    } else if (ChildCount == 1) {
                        Children[0].Parent = null;
                        return Children[0];
                    }
                }
            }

            return this;
        }
示例#2
0
        void ParseToken(QueryToken token)
        {
            switch (token.ID)
            {
            case TokenID.OpenParen:
                DepthPush();
                break;

            case TokenID.CloseParen:
                DepthPop();
                break;

            case TokenID.Not:
                NodePush(new QueryListNode(Keyword.Not));
                break;

            case TokenID.Or:
            case TokenID.And:
                // Only push a node if the current_parent is not the same as this token
                if (current_parent.Keyword == Keyword.Not ||
                    current_parent.Keyword == (token.ID == TokenID.Or ? Keyword.And : Keyword.Or))
                {
                    var list = new QueryListNode(token.ID == TokenID.Or ? Keyword.Or : Keyword.And);
                    var p    = current_parent.Parent;

                    if (p != null)
                    {
                        current_parent.Parent.RemoveChild(current_parent);
                    }

                    if (current_parent.Keyword == Keyword.Not || current_parent.ChildCount > 1)
                    {
                        list.AddChild(current_parent);
                    }
                    else
                    {
                        list.TakeChildren(current_parent);
                    }

                    current_parent = p;
                    NodePush(list);
                }
                break;

            case TokenID.Term:
                NodePush(QueryTermNode.ParseUserQuery(field_set, token.Term));
                break;
            }
        }
示例#3
0
        private void ParseToken(QueryToken token)
        {
            switch (token.ID) {
                case TokenID.OpenParen:
                    DepthPush ();
                    break;

                case TokenID.CloseParen:
                    DepthPop ();
                    break;

                case TokenID.Not:
                    NodePush (new QueryListNode (Keyword.Not));
                    break;

                case TokenID.Or:
                case TokenID.And:
                    // Only push a node if the current_parent is not the same as this token
                    if (current_parent.Keyword == Keyword.Not ||
                            current_parent.Keyword == (token.ID == TokenID.Or ? Keyword.And : Keyword.Or)) {

                        QueryListNode list = new QueryListNode (token.ID == TokenID.Or ? Keyword.Or : Keyword.And);
                        QueryListNode p = current_parent.Parent;

                        if (p != null) {
                            current_parent.Parent.RemoveChild (current_parent);
                        }

                        if (current_parent.Keyword == Keyword.Not || current_parent.ChildCount > 1) {
                            list.AddChild (current_parent);
                        } else {
                            list.TakeChildren (current_parent);
                        }

                        current_parent = p;
                        NodePush (list);
                    }
                    break;

                case TokenID.Term:
                    NodePush (QueryTermNode.ParseUserQuery (field_set, token.Term));
                    break;
            }
        }