public void AddExpression(string text, bool caseSensitive, bool needSeparators, IPatternMatcher matcher,
            object tag)
        {
            if (StringUtils.IsNullOrEmpty(text))
                throw new ArgumentException("text may not be empty", "text"); // do not localize

            Char = text[0];

            if (!caseSensitive)
                ContainsCaseInsensitiveData = true;

            if (text.Length == 1)
            {
                PatternMatchReference patternMatcherReference = new PatternMatchReference(matcher);
                patternMatcherReference.NextSibling = FirstExpression;
                patternMatcherReference.Tag = tag;
                FirstExpression = patternMatcherReference;
            }
            else
            {
                string leftovers = text.Substring(1);
                char childChar = leftovers[0];
                int childIndex = (int) childChar & 0xff; //make a lookupindex

                TokenTreeNode node = ChildNodes[childIndex];
                if (node == null)
                {
                    TokenTreeNode child = new TokenTreeNode();
                    ChildNodes[childIndex] = child;
                    child.AddExpression(leftovers, caseSensitive, needSeparators, matcher, tag);

                    if (child.Char == ' ')
                    {
                        // if the node contains " " (whitespace)
                        // then add the node as a childnode of itself.
                        // thus allowing it to parse things like
                        // "end         sub" even if the pattern is "end sub" // do not localize
                        child.ChildNodes[(int) ' '] = child;
                    }
                }
                else
                {
                    while (node.NextSibling != null && node.Char != childChar)
                    {
                        node = node.NextSibling;
                    }

                    if (node.Char != childChar)
                    {
                        TokenTreeNode child = new TokenTreeNode();
                        node.NextSibling = child;
                        child.AddExpression(leftovers, caseSensitive, needSeparators, matcher, tag);
                    }
                    else
                    {
                        node.AddExpression(leftovers, caseSensitive, needSeparators, matcher, tag);
                    }
                }
            }
        }
Esempio n. 2
0
 private void AddExpressionWithoutPrefix(IPatternMatcher matcher, bool caseSensitive, bool needSeparators,
     object tag)
 {
     if (matcher.DefaultPrefixes != null)
     {
         foreach (string defaultPrefix in matcher.DefaultPrefixes)
         {
             AddExpression(defaultPrefix, caseSensitive, needSeparators, matcher, tag);
         }
     }
     else
     {
         PatternMatchReference patternMatcherReference = new PatternMatchReference(matcher);
         patternMatcherReference.Tag = tag;
         patternMatcherReference.NextSibling = root.FirstExpression;
         root.FirstExpression = patternMatcherReference;
     }
 }