예제 #1
0
        private void ParseText(Row Row, Segment CurrentSegment, string Text)
        {
            int  CurrentPosition = 0;
            bool HasComplex      = true;

            while (true)
            {
                ScanResultWord Word = GetNextWord(Text, CurrentSegment, CurrentPosition,
                                                  ref HasComplex);

                if (!Word.HasContent)
                {
                    ParseTools.AddString(Text.Substring(CurrentPosition), Row,
                                         CurrentSegment.BlockType.Style, CurrentSegment);
                    break;
                }
                else
                {
                    ParseTools.AddString(Text.Substring(CurrentPosition, Word.Position -
                                                        CurrentPosition), Row,
                                         CurrentSegment.BlockType.Style, CurrentSegment);
                    ParseTools.AddPatternString(Word.Token, Row, Word.Pattern,
                                                Word.ParentList.Style, CurrentSegment,
                                                false);
                    CurrentPosition = Word.Position + Word.Token.Length;
                }
            }
        }
예제 #2
0
        private ScanResultWord GetNextComplexWord(String Text, Segment
                                                  CurrentSegment, int StartPositon)
        {
            if (StartPositon >= Text.Length)
            {
                return(new ScanResultWord());
            }

            ScanResultWord Result = new ScanResultWord();

            int CurrentPosition = 0;

            //look for keywords


            foreach (PatternList List in CurrentSegment.BlockType.KeywordsList)
            {
                foreach (Pattern Word in List.ComplexPatterns)
                {
                    PatternScanResult psr = Word.IndexIn(Text, StartPositon, false,
                                                         Separators);
                    CurrentPosition = psr.Index;
                    if ((CurrentPosition < Result.Position || Result.HasContent == false) &&
                        psr.Token != "")
                    {
                        Result.HasContent = true;
                        Result.Position   = CurrentPosition;
                        Result.Token      = psr.Token;
                        Result.Pattern    = Word;
                        Result.ParentList = List;

                        if (List.NormalizeCase)
                        {
                            if (!Word.IsComplex)
                            {
                                Result.Token = Word.StringPattern;
                            }
                        }
                    }
                }
            }

            //look for operators
            foreach (PatternList List in CurrentSegment.BlockType.OperatorsList)
            {
                foreach (Pattern Word in List.ComplexPatterns)
                {
                    PatternScanResult psr = Word.IndexIn(Text, StartPositon, false,
                                                         Separators);
                    CurrentPosition = psr.Index;
                    if ((CurrentPosition < Result.Position || Result.HasContent == false) &&
                        psr.Token != "")
                    {
                        Result.HasContent = true;
                        Result.Position   = CurrentPosition;
                        Result.Token      = psr.Token;
                        Result.Pattern    = Word;
                        Result.ParentList = List;

                        if (List.NormalizeCase)
                        {
                            if (!Word.IsComplex)
                            {
                                Result.Token = Word.StringPattern;
                            }
                        }
                    }
                }
            }

            if (Result.HasContent)
            {
                return(Result);
            }
            else
            {
                return(new ScanResultWord());
            }
        }
예제 #3
0
        private ScanResultWord GetNextWord(string Text, Segment CurrentSegment, int
            StartPos, ref bool HasComplex)
        {
            BlockType block = CurrentSegment.BlockType;

            #region ComplexFind

            int BestComplexPos = - 1;
            Pattern BestComplexPattern = null;
            string BestComplexToken = "";
            ScanResultWord complexword = new ScanResultWord();
            if (HasComplex)
            {
                foreach (Pattern pattern in block.ComplexPatterns)
                {
                    PatternScanResult scanres = pattern.IndexIn(Text, StartPos,
                                                                pattern.Parent.CaseSensitive, this.Separators);
                    if (scanres.Token != "")
                    {
                        if (scanres.Index < BestComplexPos || BestComplexPos == - 1)
                        {
                            BestComplexPos = scanres.Index;
                            BestComplexPattern = pattern;
                            BestComplexToken = scanres.Token;
                        }
                    }
                }

                if (BestComplexPattern != null)
                {
                    complexword.HasContent = true;
                    complexword.ParentList = BestComplexPattern.Parent;
                    complexword.Pattern = BestComplexPattern;
                    complexword.Position = BestComplexPos;
                    complexword.Token = BestComplexToken;
                    HasComplex = true;
                }
                else
                {
                    HasComplex = false;
                }
            }

            #endregion

            #region SimpleFind

            ScanResultWord simpleword = new ScanResultWord();
            for (int i = StartPos; i < Text.Length; i++)
            {
                //bailout if we found a complex pattern before this char pos
                if (i > complexword.Position && complexword.HasContent)
                    break;

                #region 3+ char pattern

                if (i <= Text.Length - 3)
                {
                    string key = Text.Substring(i, 3).ToLower
                        (CultureInfo.InvariantCulture);
                    PatternCollection patterns2 = (PatternCollection)
                        block.LookupTable[key];
                    //ok , there are patterns that start with this char
                    if (patterns2 != null)
                    {
                        foreach (Pattern pattern in patterns2)
                        {
                            int len = pattern.StringPattern.Length;
                            if (i + len > Text.Length)
                                continue;

                            char lastpatternchar = char.ToLower(pattern.StringPattern[len -
                                1]);
                            char lasttextchar = char.ToLower(Text[i + len - 1]);

                            #region Case Insensitive

                            if (lastpatternchar == lasttextchar)
                            {
                                if (!pattern.IsKeyword || (pattern.IsKeyword &&
                                    pattern.HasSeparators(Text, i)))
                                {
                                    if (!pattern.Parent.CaseSensitive)
                                    {
                                        string s = Text.Substring(i, len).ToLower
                                            (CultureInfo.InvariantCulture);

                                        if (s == pattern.StringPattern.ToLower
                                            (CultureInfo.InvariantCulture))
                                        {
                                            simpleword.HasContent = true;
                                            simpleword.ParentList = pattern.Parent;
                                            simpleword.Pattern = pattern;
                                            simpleword.Position = i;
                                            if (pattern.Parent.NormalizeCase)
                                                simpleword.Token = pattern.StringPattern;
                                            else
                                                simpleword.Token = Text.Substring(i, len);
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        string s = Text.Substring(i, len);

                                        if (s == pattern.StringPattern)
                                        {
                                            simpleword.HasContent = true;
                                            simpleword.ParentList = pattern.Parent;
                                            simpleword.Pattern = pattern;
                                            simpleword.Position = i;
                                            simpleword.Token = pattern.StringPattern;
                                            break;
                                        }
                                    }

                                }
                            }
                        }

                        #endregion
                    }
                }

                #endregion

                if (simpleword.HasContent)
                    break;

                #region single char pattern

                char c = Text[i];
                PatternCollection patterns = (PatternCollection) block.LookupTable[c];
                if (patterns != null)
                {
                    //ok , there are patterns that start with this char
                    foreach (Pattern pattern in patterns)
                    {
                        int len = pattern.StringPattern.Length;
                        if (i + len > Text.Length)
                            continue;

                        char lastpatternchar = pattern.StringPattern[len - 1];
                        char lasttextchar = Text[i + len - 1];

                        if (!pattern.Parent.CaseSensitive)
                        {
                            #region Case Insensitive

                            if (char.ToLower(lastpatternchar) == char.ToLower(lasttextchar))
                            {
                                if (!pattern.IsKeyword || (pattern.IsKeyword &&
                                    pattern.HasSeparators(Text, i)))
                                {
                                    string s = Text.Substring(i, len).ToLower
                                        (CultureInfo.InvariantCulture);

                                    if (s == pattern.StringPattern.ToLower
                                        (CultureInfo.InvariantCulture))
                                    {
                                        simpleword.HasContent = true;
                                        simpleword.ParentList = pattern.Parent;
                                        simpleword.Pattern = pattern;
                                        simpleword.Position = i;
                                        if (pattern.Parent.NormalizeCase)
                                            simpleword.Token = pattern.StringPattern;
                                        else
                                            simpleword.Token = Text.Substring(i, len);
                                        break;
                                    }
                                }
                            }

                            #endregion
                        }
                        else
                        {
                            #region Case Sensitive

                            if (lastpatternchar == lasttextchar)
                            {
                                if (!pattern.IsKeyword || (pattern.IsKeyword &&
                                    pattern.HasSeparators(Text, i)))
                                {
                                    string s = Text.Substring(i, len);

                                    if (s == pattern.StringPattern)
                                    {
                                        simpleword.HasContent = true;
                                        simpleword.ParentList = pattern.Parent;
                                        simpleword.Pattern = pattern;
                                        simpleword.Position = i;
                                        simpleword.Token = pattern.StringPattern;
                                        break;
                                    }
                                }
                            }

                            #endregion
                        }
                    }

                    if (simpleword.HasContent)
                        break;
                }

                #endregion
            }

            #endregion

            if (complexword.HasContent && simpleword.HasContent)
            {
                if (simpleword.Position == complexword.Position)
                {
                    if (simpleword.Token.Length >= complexword.Token.Length)
                        return simpleword;
                    else
                        return complexword;
                }

                if (simpleword.Position < complexword.Position)
                    return simpleword;

                if (simpleword.Position > complexword.Position)
                    return complexword;

            }

            if (simpleword.HasContent)
                return simpleword;

            if (complexword.HasContent)
                return complexword;

            return new ScanResultWord();
        }
예제 #4
0
        private ScanResultWord GetNextWord(string Text, Segment CurrentSegment, int
                                           StartPos, ref bool HasComplex)
        {
            BlockType block = CurrentSegment.BlockType;

            #region ComplexFind

            int            BestComplexPos     = -1;
            Pattern        BestComplexPattern = null;
            string         BestComplexToken   = "";
            ScanResultWord complexword        = new ScanResultWord();
            if (HasComplex)
            {
                foreach (Pattern pattern in block.ComplexPatterns)
                {
                    PatternScanResult scanres = pattern.IndexIn(Text, StartPos,
                                                                pattern.Parent.CaseSensitive, this.Separators);
                    if (scanres.Token != "")
                    {
                        if (scanres.Index < BestComplexPos || BestComplexPos == -1)
                        {
                            BestComplexPos     = scanres.Index;
                            BestComplexPattern = pattern;
                            BestComplexToken   = scanres.Token;
                        }
                    }
                }


                if (BestComplexPattern != null)
                {
                    complexword.HasContent = true;
                    complexword.ParentList = BestComplexPattern.Parent;
                    complexword.Pattern    = BestComplexPattern;
                    complexword.Position   = BestComplexPos;
                    complexword.Token      = BestComplexToken;
                    HasComplex             = true;
                }
                else
                {
                    HasComplex = false;
                }
            }

            #endregion

            #region SimpleFind

            ScanResultWord simpleword = new ScanResultWord();
            for (int i = StartPos; i < Text.Length; i++)
            {
                //bailout if we found a complex pattern before this char pos
                if (i > complexword.Position && complexword.HasContent)
                {
                    break;
                }

                #region 3+ char pattern

                if (i <= Text.Length - 3)
                {
                    string key = Text.Substring(i, 3).ToLower
                                     (CultureInfo.InvariantCulture);
                    PatternCollection patterns2 = (PatternCollection)
                                                  block.LookupTable[key];
                    //ok , there are patterns that start with this char
                    if (patterns2 != null)
                    {
                        foreach (Pattern pattern in patterns2)
                        {
                            int len = pattern.StringPattern.Length;
                            if (i + len > Text.Length)
                            {
                                continue;
                            }

                            char lastpatternchar = char.ToLower(pattern.StringPattern[len -
                                                                                      1]);
                            char lasttextchar = char.ToLower(Text[i + len - 1]);

                            #region Case Insensitive

                            if (lastpatternchar == lasttextchar)
                            {
                                if (!pattern.IsKeyword || (pattern.IsKeyword &&
                                                           pattern.HasSeparators(Text, i)))
                                {
                                    if (!pattern.Parent.CaseSensitive)
                                    {
                                        string s = Text.Substring(i, len).ToLower
                                                       (CultureInfo.InvariantCulture);

                                        if (s == pattern.StringPattern.ToLower
                                                (CultureInfo.InvariantCulture))
                                        {
                                            simpleword.HasContent = true;
                                            simpleword.ParentList = pattern.Parent;
                                            simpleword.Pattern    = pattern;
                                            simpleword.Position   = i;
                                            if (pattern.Parent.NormalizeCase)
                                            {
                                                simpleword.Token = pattern.StringPattern;
                                            }
                                            else
                                            {
                                                simpleword.Token = Text.Substring(i, len);
                                            }
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        string s = Text.Substring(i, len);

                                        if (s == pattern.StringPattern)
                                        {
                                            simpleword.HasContent = true;
                                            simpleword.ParentList = pattern.Parent;
                                            simpleword.Pattern    = pattern;
                                            simpleword.Position   = i;
                                            simpleword.Token      = pattern.StringPattern;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        #endregion
                    }
                }

                #endregion

                if (simpleword.HasContent)
                {
                    break;
                }

                #region single char pattern

                char c = Text[i];
                PatternCollection patterns = (PatternCollection)block.LookupTable[c];
                if (patterns != null)
                {
                    //ok , there are patterns that start with this char
                    foreach (Pattern pattern in patterns)
                    {
                        int len = pattern.StringPattern.Length;
                        if (i + len > Text.Length)
                        {
                            continue;
                        }

                        char lastpatternchar = pattern.StringPattern[len - 1];
                        char lasttextchar    = Text[i + len - 1];

                        if (!pattern.Parent.CaseSensitive)
                        {
                            #region Case Insensitive

                            if (char.ToLower(lastpatternchar) == char.ToLower(lasttextchar))
                            {
                                if (!pattern.IsKeyword || (pattern.IsKeyword &&
                                                           pattern.HasSeparators(Text, i)))
                                {
                                    string s = Text.Substring(i, len).ToLower
                                                   (CultureInfo.InvariantCulture);

                                    if (s == pattern.StringPattern.ToLower
                                            (CultureInfo.InvariantCulture))
                                    {
                                        simpleword.HasContent = true;
                                        simpleword.ParentList = pattern.Parent;
                                        simpleword.Pattern    = pattern;
                                        simpleword.Position   = i;
                                        if (pattern.Parent.NormalizeCase)
                                        {
                                            simpleword.Token = pattern.StringPattern;
                                        }
                                        else
                                        {
                                            simpleword.Token = Text.Substring(i, len);
                                        }
                                        break;
                                    }
                                }
                            }

                            #endregion
                        }
                        else
                        {
                            #region Case Sensitive

                            if (lastpatternchar == lasttextchar)
                            {
                                if (!pattern.IsKeyword || (pattern.IsKeyword &&
                                                           pattern.HasSeparators(Text, i)))
                                {
                                    string s = Text.Substring(i, len);

                                    if (s == pattern.StringPattern)
                                    {
                                        simpleword.HasContent = true;
                                        simpleword.ParentList = pattern.Parent;
                                        simpleword.Pattern    = pattern;
                                        simpleword.Position   = i;
                                        simpleword.Token      = pattern.StringPattern;
                                        break;
                                    }
                                }
                            }

                            #endregion
                        }
                    }

                    if (simpleword.HasContent)
                    {
                        break;
                    }
                }

                #endregion
            }

            #endregion

            if (complexword.HasContent && simpleword.HasContent)
            {
                if (simpleword.Position == complexword.Position)
                {
                    if (simpleword.Token.Length >= complexword.Token.Length)
                    {
                        return(simpleword);
                    }
                    else
                    {
                        return(complexword);
                    }
                }

                if (simpleword.Position < complexword.Position)
                {
                    return(simpleword);
                }

                if (simpleword.Position > complexword.Position)
                {
                    return(complexword);
                }
            }

            if (simpleword.HasContent)
            {
                return(simpleword);
            }

            if (complexword.HasContent)
            {
                return(complexword);
            }


            return(new ScanResultWord());
        }
예제 #5
0
        private ScanResultWord GetNextComplexWord(String Text, Segment
            CurrentSegment, int StartPositon)
        {
            if (StartPositon >= Text.Length)
                return new ScanResultWord();

            ScanResultWord Result = new ScanResultWord();

            int CurrentPosition = 0;

            //look for keywords

            foreach (PatternList List in CurrentSegment.BlockType.KeywordsList)
            {
                foreach (Pattern Word in List.ComplexPatterns)
                {
                    PatternScanResult psr = Word.IndexIn(Text, StartPositon, false,
                                                         Separators);
                    CurrentPosition = psr.Index;
                    if ((CurrentPosition < Result.Position || Result.HasContent == false)
                        && psr.Token != "")
                    {
                        Result.HasContent = true;
                        Result.Position = CurrentPosition;
                        Result.Token = psr.Token;
                        Result.Pattern = Word;
                        Result.ParentList = List;

                        if (List.NormalizeCase)
                            if (!Word.IsComplex)
                                Result.Token = Word.StringPattern;
                    }
                }
            }

            //look for operators
            foreach (PatternList List in CurrentSegment.BlockType.OperatorsList)
            {
                foreach (Pattern Word in List.ComplexPatterns)
                {
                    PatternScanResult psr = Word.IndexIn(Text, StartPositon, false,
                                                         Separators);
                    CurrentPosition = psr.Index;
                    if ((CurrentPosition < Result.Position || Result.HasContent == false)
                        && psr.Token != "")
                    {
                        Result.HasContent = true;
                        Result.Position = CurrentPosition;
                        Result.Token = psr.Token;
                        Result.Pattern = Word;
                        Result.ParentList = List;

                        if (List.NormalizeCase)
                            if (!Word.IsComplex)
                                Result.Token = Word.StringPattern;
                    }
                }
            }

            if (Result.HasContent)
                return Result;
            else
                return new ScanResultWord();
        }