public static MatchScanPattern FindPattern(
            this PatternScanResults Results, DelimClassification DelimClass)
        {
            MatchScanPattern found = null;

            if (Results == null)
            {
                found = null;
            }
            else if (Results.FoundPatterns != null)
            {
                found = Results.FoundPatterns.FindPattern(DelimClass);
            }
            else if ((Results.FoundPattern != null) &&
                     (Results.FoundPattern.MatchPattern.DelimClassification == DelimClass))
            {
                found = Results.FoundPattern;
            }
            else
            {
                found = null;
            }

            return(found);
        }
Example #2
0
 public ScanAtomCursor(MatchScanPattern MatchPattern, ScanStream ScanStream)
 {
     MatchPattern.AssignAtomText(ScanStream);
     this.AtomText    = MatchPattern.AtomText;
     this.AtomPattern = MatchPattern.MatchPattern;
     this.Position    = RelativePosition.At;
 }
        public static bool IsDelimClass(
            this PatternScanResults Results, DelimClassification DelimClass)
        {
            MatchScanPattern found = FindPattern(Results, DelimClass);

            if (found == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #4
0
        public static MatchScanPattern FindPattern(
            this MatchScanPatternList List, DelimClassification DelimClass)
        {
            MatchScanPattern found = null;

            if (List != null)
            {
                var node = List.FindNode(c => c.MatchPattern.DelimClassification == DelimClass);
                if (node != null)
                {
                    found = node.Value;
                }
            }

            return(found);
        }
        public void AddFound(ScanPattern Pattern, int Pos, int Lgth)
        {
            if (FoundPattern == null)
            {
                this.FoundPattern = Pattern;
                this.FoundPos     = Pos;
                this.MatchLgth    = Lgth;
            }
            else
            {
                if (FoundPatterns == null)
                {
                    FoundPatterns = new List <MatchScanPattern>();
                    MatchScanPattern matPat = new MatchScanPattern(FoundPattern, MatchLgth);
                    FoundPatterns.Add(matPat);
                }

                {
                    MatchScanPattern matPat = new MatchScanPattern(Pattern, Lgth);
                    FoundPatterns.Add(matPat);
                }
            }
        }
Example #6
0
        MatchPatternsAtStringLocation(string Text, int Ix, int Ex)
        {
            ScanPattern             foundPat     = null;
            char                    ch1          = Text[Ix];
            int                     foundMatchLx = 0;
            List <MatchScanPattern> foundPats    = null;
            PatternScanResults      nonWord      = new PatternScanResults();

            // find first pattern that matches lead char of the substring.
            int patIx = Array.IndexOf <char>(this.LeadChars, ch1);

            if (patIx >= 0)
            {
                // loop thru the ScanPatterns with a lead char that matches the first char
                // of the text being scanned.
                ScanPattern pat = this.ScanPatternsArray[patIx];
                while (pat != null)
                {
                    // use virtual method to compare if the pattern matches the text in the string.
                    var  rv      = pat.EqualsText(Text, Ix);
                    bool isMatch = rv.Item1;
                    int  matchLx = rv.Item2;

                    if (isMatch == true)
                    {
                        nonWord.AddFound(pat, Ix, matchLx);

                        // store the first found pattern.
                        if ((foundPat == null) && (foundPats == null))
                        {
                            foundPat     = pat;
                            foundMatchLx = matchLx;
                        }

                        // for now, skip any match with length < existing match.
                        else if (matchLx < foundMatchLx)
                        {
                        }

                        // length of this match exceeds what is already found.
                        // Replace all found ( shorter ) matches with this match.
                        else if (matchLx > foundMatchLx)
                        {
                            foundPats    = null;
                            foundPat     = pat;
                            foundMatchLx = matchLx;
                        }

                        // add the found pattern to the list of found patterns.
                        else
                        {
                            // create the list. add the initial found pattern to the list.
                            if (foundPats == null)
                            {
                                foundPats = new List <MatchScanPattern>();
                                MatchScanPattern matchPat = new MatchScanPattern(foundPat, Ix, foundMatchLx);
                                foundPats.Add(matchPat);
                            }

                            {
                                MatchScanPattern matchPat = new MatchScanPattern(pat, Ix, matchLx);
                                foundPats.Add(matchPat);
                            }
                        }
                    }
                    pat = pat.NextSameLeadChar;
                }
            }

            // the found patterns

            return(new
                   Tuple <ScanPattern, int, List <MatchScanPattern>, PatternScanResults>(
                       foundPat, foundMatchLx, foundPats, nonWord));
        }