Пример #1
0
        protected void SimplifyLevel(SymTokenBalancerMarkerLevelNode aLevel)
        {
            System.Diagnostics.Debug.Assert(aLevel.IsRoot == false && aLevel.HasParent);
            SymNode parent      = aLevel.Parent;
            int     levelNumber = parent.Depth;
            //
            int childCount = parent.ChildCount;

            while (--childCount >= 0)
            {
                SymNode possibleLevelNode = parent[childCount];

                // We're looking to remove redundant bracketing from either side of the level
                // node. First check if we have a level node...
                if (possibleLevelNode is SymTokenBalancerMarkerLevelNode)
                {
                    // Then check whether it has a previous and a next node. These should
                    // be the SymTokenBalancerNodeEmittedElement nodes
                    if (possibleLevelNode.HasPrevious && possibleLevelNode.HasNext)
                    {
                        if (possibleLevelNode.Previous is SymTokenBalancerNodeEmittedElement && possibleLevelNode.Next is SymTokenBalancerNodeEmittedElement)
                        {
                            if (LevelCanBeMergedWithParent(possibleLevelNode as SymTokenBalancerMarkerLevelNode))
                            {
                                SymTokenBalancerNodeEmittedElement previous = (SymTokenBalancerNodeEmittedElement)possibleLevelNode.Previous;
                                SymTokenBalancerNodeEmittedElement next     = (SymTokenBalancerNodeEmittedElement)possibleLevelNode.Next;

                                // Insert value node prior to previous node (which is the opening bracket token).
                                parent.InsertChildrenFrom(possibleLevelNode, previous.Previous);

                                // Remove the opening bracket token
                                previous.Remove();

                                // Remove the level marker token
                                possibleLevelNode.Remove();

                                // Remove the closing bracket token.
                                next.Remove();
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        public void Subsume()
        {
            System.Diagnostics.Debug.Assert(IsComplete);
            //
            SymTokenBalancerNodeEmittedElement previous = EmittedElementPrevious;
            SymTokenBalancerNodeEmittedElement next     = EmittedElementNext;

            // Insert all my children as siblings of myself (i.e. make my parent's
            // grandchildren its direct children - i.e. promote them up the tree
            // by one level).
            SymNode   parent          = Parent;
            ArrayList parentsChildren = Parent.Children;

            parent.InsertChildrenFrom(this /* my children */, previous.Previous /* move them before the opening bracket */);

            // Remove the opening bracket token
            previous.Remove();

            // Remove the closing bracket token.
            next.Remove();

            // Remove the level marker token, i.e myself
            Remove();
        }