public StmtWord(string StmtText, StmtWord Parent, WordCursor WordCursor)
 {
     mStmtText   = StmtText;
     mSubWords   = null;
     mWordCursor = WordCursor;
     this.Parent = Parent;
 }
 /// <summary>
 /// construct this cursor as a copy of the input cursor.
 /// </summary>
 /// <param name="Cursor"></param>
 public StmtWordListCursor(StmtWordListCursor Cursor)
 {
     this.mRltv       = Cursor.mRltv;
     this.mNode       = Cursor.mNode;
     this.mList       = Cursor.mList;
     this.mStayAtFlag = Cursor.mStayAtFlag;
     this.mEdge       = Cursor.mEdge;
 }
 public StmtWordListCursor(StmtWordList List)
 {
     mRltv       = RelativePosition.Begin;
     mNode       = null;
     mList       = List;
     mStayAtFlag = false;
     mEdge       = WhichEdge.None;
 }
 public StmtWordListCursor(
     StmtWordList List, LinkedListNode <StmtWord> Node,
     WhichEdge Edge, RelativePosition Rltv)
 {
     mList       = List;
     mRltv       = Rltv;
     mNode       = Node;
     mEdge       = Edge;
     mStayAtFlag = false;
 }
 public StmtWord(
     string StmtText,
     StmtWord Parent, WordCursor WordCursor, WordCompositeCode CompositeCode)
 {
     mStmtText      = StmtText;
     mSubWords      = null;
     mWordCursor    = WordCursor;
     mCompositeCode = CompositeCode;
     this.Parent    = Parent;
 }
 public StmtWordListCursor(
     StmtWord Word, WhichEdge Edge, RelativePosition Rltv)
 {
     if (Word.IsTopWord == true)
     {
         mList = null;
         mRltv = Rltv;
         mNode = new LinkedListNode <StmtWord>(Word);
         mEdge = Edge;
     }
     else
     {
         mList = Word.Parent.SubWords;
         mRltv = Rltv;
         mEdge = Edge;
         mNode = Word.SubWordNode;
     }
 }
        public StmtWordListCursor NextDeep()
        {
            StmtWordListCursor        rv = null;
            LinkedListNode <StmtWord> node;
            WhichEdge edge = WhichEdge.None;

            // stay at the current location.
            if (StayAtFlag == true)
            {
                if (mRltv != RelativePosition.At)
                {
                    throw new ApplicationException("cursor not position at location to stay at");
                }
                StayAtFlag = false;
                rv         = new StmtWordListCursor(mList, mNode, mEdge, mRltv);
                node       = mNode;
            }

            else
            {
                switch (mRltv)
                {
                case RelativePosition.Begin:

                    // at begin of top word.
                    if ((mNode != null) && (StmtWordList.IsTopWord(mNode) == true))
                    {
                        rv = new StmtWordListCursor(null, mNode, WhichEdge.LeadEdge, RelativePosition.At);
                    }

                    // stmt list is null.
                    else if (mList == null)
                    {
                        throw new ApplicationException("List of sub words is null");
                    }

                    else if (mList.Count == 0)
                    {
                        rv = new StmtWordListCursor(mList, null, WhichEdge.None, RelativePosition.End);
                    }
                    else
                    {
                        StmtWordListCursor c1 = new StmtWordListCursor(
                            mList, mList.First, WhichEdge.LeadEdge, RelativePosition.Before);
                        rv = c1.NextDeep();
                    }
                    break;

                case RelativePosition.Before:
                    node = mNode;

                    if (StmtWordList.IsComposite(node))
                    {
                        edge = mEdge;
                        if (edge == WhichEdge.None)
                        {
                            edge = WhichEdge.LeadEdge;
                        }
                    }
                    else
                    {
                        edge = WhichEdge.None;
                    }

                    rv = new StmtWordListCursor(mList, mNode, edge, RelativePosition.At);
                    break;

                case RelativePosition.At:

                    // step down a level and read the first sub word of this word.
                    if ((mEdge == WhichEdge.LeadEdge) && (mNode.Value.HasSubWords == true))
                    {
                        StmtWordListCursor c1 =
                            new StmtWordListCursor(
                                mNode.Value.SubWords, null, WhichEdge.None, RelativePosition.Begin);
                        rv   = c1.NextDeep();
                        node = rv.Node;
                    }

                    // node has no child nodes. read the next sibling.
                    else if (mNode.Next != null)
                    {
                        rv = new StmtWordListCursor(
                            mList, mNode.Next, WhichEdge.LeadEdge, RelativePosition.At);
                        node = mNode.Next;
                    }

                    // read next from the parent of this node.
                    else
                    {
                        rv   = NextDeepFromParent(mNode.Value);
                        node = rv.Node;
                    }

                    break;

                case RelativePosition.After:

                    // Positioned after the lead edge of a composite word.
                    // Step down a level and read the first sub word of this word.
                    // ( the cursor will only be positioned like this if explicity set by user
                    //   code. )
                    if ((mEdge == WhichEdge.LeadEdge) && (mNode.Value.HasSubWords == true))
                    {
                        StmtWordListCursor c1 =
                            new StmtWordListCursor(
                                mNode.Value.SubWords, null, WhichEdge.None, RelativePosition.Begin);
                        rv   = c1.NextDeep();
                        node = rv.Node;
                    }

                    // read next sibling.
                    else if (mNode.Next != null)
                    {
                        node = mNode.Next;
                        rv   = new StmtWordListCursor(
                            mList, mNode.Next, WhichEdge.LeadEdge, RelativePosition.At);
                    }

                    // read next from the parent of this node.
                    else
                    {
                        rv   = NextDeepFromParent(mNode.Value);
                        node = rv.Node;
                    }

                    break;

                case RelativePosition.End:
                    rv = new StmtWordListCursor(
                        null, null, WhichEdge.None, RelativePosition.End);
                    break;

                default:
                    throw new ApplicationException("Next failed. Relative position is not set");
                }
            }

            return(rv);
        }