/// <summary> /// Check that the sequence of patterns matches the StmtWord stream starting /// at the specified cursor. Returns list of cursors which match the pattern. /// </summary> /// <param name="InCursor"></param> /// <returns></returns> public List <StmtWordListCursor> DoMatch(StmtWordListCursor InCursor) { bool mr = true; StmtWordListCursor c1 = InCursor; List <StmtWordListCursor> matchedCursors = new List <StmtWordListCursor>(); foreach (CursorMatchPattern pat in this) { if (pat.DoesMatch(c1) == false) { mr = false; break; } // add to list of matching cursors. This list corresponds to the list of // match patterns. matchedCursors.Add(c1); c1 = c1.NextDeep(); } if (mr == false) { matchedCursors = null; } return(matchedCursors); }
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); }