コード例 #1
0
        /// <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);
        }
コード例 #2
0
        public StmtWordListCursor NextDeepFromParent(StmtWord InChildWord)
        {
            StmtWordListCursor c1 = null;

            // end of the line if this node does not have a parent.
            if (InChildWord.Parent == null)
            {
                c1 = new StmtWordListCursor(
                    null, null, WhichEdge.None, RelativePosition.End);
            }

            // parent is the TopWord. Top word is special in that it is not a node in
            // a word list.
            else if (InChildWord.Parent.IsTopWord == true)
            {
                LinkedListNode <StmtWord> node = new LinkedListNode <StmtWord>(InChildWord.Parent);
                c1 = new StmtWordListCursor(
                    null, node, WhichEdge.TrailEdge, RelativePosition.At);
            }

            // position at the trailing edge of the parent word.
            else
            {
                StmtWord par = InChildWord.Parent;
                c1 = new StmtWordListCursor(
                    par.SubWords, par.SubWordNode, WhichEdge.TrailEdge, RelativePosition.At);
            }

            return(c1);
        }
コード例 #3
0
        public StmtWordListCursor PositionBegin()
        {
            StmtWordListCursor csr =
                new StmtWordListCursor(this, null, WhichEdge.None, RelativePosition.Begin);

            return(csr);
        }
コード例 #4
0
 /// <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;
 }
コード例 #5
0
        /// <summary>
        /// Get next stmt word deep. Assert that word gotten is either a sibling or child.
        /// Also assert that gotten word composite code is any of array of values.
        /// </summary>
        /// <param name="InAssertNodeRltv"></param>
        /// <param name="InAssertEqualAnyCompositeCode"></param>
        /// <param name="InExceptionText"></param>
        /// <returns></returns>
        public StmtWordListCursor NextDeep(
            AssertNextNodeRelative InAssertNodeRltv,
            WordCompositeCode[] InAssertEqualAnyCompositeCode,
            string InExceptionText)
        {
            StmtWord startWord = null;
            StmtWord nextWord  = null;

            // Setup startWord. Current cursor must be at a word.
            if (this.Position != RelativePosition.At)
            {
                throw new ApplicationException(
                          InExceptionText + " Not positioned at start word.");
            }
            startWord = this.Node.Value;

            // do the actual get next.
            StmtWordListCursor c1 = NextDeep();

            // isolate next word.
            if (c1.Position == RelativePosition.At)
            {
                nextWord = c1.Node.Value;
            }

            if (InAssertNodeRltv == AssertNextNodeRelative.IsChild)
            {
                if ((nextWord == null) || (nextWord.IsChildOf(startWord) == false))
                {
                    throw new ApplicationException(InExceptionText + " No child words.");
                }
            }

            if (InAssertNodeRltv == AssertNextNodeRelative.IsSibling)
            {
                if ((nextWord == null) || (nextWord.IsSiblingOf(startWord) == false))
                {
                    throw new ApplicationException(InExceptionText + " No next sibling word.");
                }
            }

            if (InAssertEqualAnyCompositeCode != null)
            {
                if (nextWord == null)
                {
                    throw new ApplicationException(InExceptionText + " Next word not found.");
                }

                else if (Array.IndexOf <WordCompositeCode>(
                             InAssertEqualAnyCompositeCode, nextWord.CompositeCode) == -1)
                {
                    throw new ApplicationException(InExceptionText + " Unexpected composite code " +
                                                   nextWord.CompositeCode.ToString());
                }
            }

            return(c1);
        }
コード例 #6
0
 public StmtWordSpan AddWord(
     StmtWordListCursor InCursor, MonoCaseString InExpectedWordText)
 {
     if (InCursor.Position != RelativePosition.At)
     {
         throw new ApplicationException("StmtWord cursor is not positioned at a word");
     }
     AddWord(InCursor.Node.Value, InExpectedWordText);
     return(this);
 }
コード例 #7
0
        /// <summary>
        /// advance the StmtWord cursor to the next word.  Then test that it contains the
        /// expected word value. Finally, add that StmtWord to the WordSpan string.
        /// </summary>
        /// <param name="InCursor"></param>
        /// <param name="InExpectedWordText"></param>
        /// <returns></returns>
        public StmtWordListCursor AddNextWord(
            StmtWordListCursor InCursor, MonoCaseString InExpectedWordText)
        {
            StmtWordListCursor c1 = InCursor.Next();

            if (c1.Position != RelativePosition.At)
            {
                throw new ApplicationException("Next StmtWord cursor is not positioned at a word");
            }
            AddWord(c1.Node.Value, InExpectedWordText);
            return(c1);
        }
コード例 #8
0
        public bool IsCorrTrailEdge(StmtWordListCursor InLeadEdge)
        {
            bool isTrailEdge = false;

            if (InLeadEdge.IsLeadEdge == false)
            {
                throw new ApplicationException("argument is not a lead edge cursor");
            }

            if (IsTrailEdge == true)
            {
                StmtWord teWord = this.StmtWord;
                StmtWord leWord = InLeadEdge.StmtWord;

                // the leading and trailing edge cursor contains the same StmtWord.
                if (teWord == leWord)
                {
                    isTrailEdge = true;
                }
            }

            return(isTrailEdge);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
 public StmtWordSpan AddWord(StmtWordListCursor InCursor)
 {
     this.Add(InCursor.Node.Value);
     return(this);
 }
コード例 #11
0
        public bool DoesMatch(StmtWordListCursor InCursor)
        {
            bool doesMatch = true;

            if (InCursor.IsAtEnd == true)
            {
                doesMatch = false;
            }

            // match CompositeCode.
            if ((doesMatch == true) && (mCompositeCode != WordCompositeCode.Any))
            {
                if (mCompositeCode != InCursor.StmtWord.CompositeCode)
                {
                    doesMatch = false;
                }
            }

            // brace character.
            if ((doesMatch == true) && (OpenBracePattern != null))
            {
                if (InCursor.StmtWord.IsBraced(OpenBracePattern) == false)
                {
                    doesMatch = false;
                }
            }

            // match Edge.
            if ((doesMatch == true) && (mEdge != WhichEdge.Any))
            {
                if (mEdge != InCursor.Edge)
                {
                    doesMatch = false;
                }
            }

            // match DelimClass.
            if ((doesMatch == true) && (mDelimClass != DelimClassification.Any))
            {
                if (mDelimClass != InCursor.StmtWord.DelimClass)
                {
                    doesMatch = false;
                }
            }

            // match WordText against allowed values.
            if ((doesMatch == true) && (mAllowedValues != null))
            {
                string s1 = null;
                switch (Case)
                {
                case CharCase.Upper:
                    s1 = InCursor.StmtWord.UpperWordText;
                    break;

                case CharCase.Lower:
                    s1 = InCursor.StmtWord.WordText.ToLower( );
                    break;

                default:
                    s1 = InCursor.StmtWord.WordText;
                    break;
                }
                int fx = Array.IndexOf <string>(AllowedValues, s1);
                if (fx == -1)
                {
                    doesMatch = false;
                }
            }

            // reverse the polarity of the match result.
            if (Polarity == RulePolarity.Negative)
            {
                doesMatch = !doesMatch;
            }

            return(doesMatch);
        }