Exemplo n.º 1
0
        private void ParseText(Row Row, Segment CurrentSegment, string Text)
        {
            int  CurrentPosition = 0;
            bool HasComplex      = true;

            while (true)
            {
                ScanResult_Word 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;
                }
            }
        }
Exemplo n.º 2
0
        private ScanResult_Word GetNextComplexWord(String Text, Segment CurrentSegment, int StartPositon)
        {
            if (StartPositon >= Text.Length)
            {
                return(new ScanResult_Word());
            }

            ScanResult_Word Result = new ScanResult_Word();

            int CurrentPosition = 0;

            //look for keywords


            PatternListList keywordsList = CurrentSegment.BlockType.KeywordsList;

            PatternList List = null;

            for (int i = 0; i < keywordsList.Count; i++)
            {
                List = keywordsList[i];

                PatternCollection complexPatterns = List.ComplexPatterns;

                Pattern Word = null;

                for (int j = 0; j < complexPatterns.Count; j++)
                {
                    Word = complexPatterns[j];

                    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

            PatternListList pattList = CurrentSegment.BlockType.OperatorsList;


            PatternList patternList = null;

            for (int i = 0; i < pattList.Count; i++)
            {
                patternList = pattList[i];

                PatternCollection complexPatterns = patternList.ComplexPatterns;

                for (int j = 0; j < complexPatterns.Count; j++)
                {
                    Pattern Word = complexPatterns[j];

                    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 = patternList;

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

            if (Result.HasContent)
            {
                return(Result);
            }
            else
            {
                return(new ScanResult_Word());
            }
        }
Exemplo n.º 3
0
        private ScanResult_Word GetNextWord(string Text, Segment CurrentSegment, int StartPos, ref bool HasComplex)
        {
            BlockType block = CurrentSegment.BlockType;

            #region ComplexFind
            int             BestComplexPos     = -1;
            Pattern         BestComplexPattern = null;
            string          BestComplexToken   = "";
            ScanResult_Word complexword        = new ScanResult_Word();
            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
            ScanResult_Word simpleword = new ScanResult_Word();
            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();
                    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();

                                        if (s == pattern.StringPattern.ToLower())
                                        {
                                            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();

                                    if (s == pattern.StringPattern.ToLower())
                                    {
                                        simpleword.HasContent = true;
                                        simpleword.ParentList = pattern.Parent;
                                        simpleword.Pattern    = pattern;
                                        simpleword.Position   = i;
                                        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 ScanResult_Word());
        }