private void analyze()
        {
            _elements = new List<PatternElement>();

            char c;
            bool escaped = false;
            bool inCommentLine = false;
            PatternComment commentLine = null;
            bool inCommentGroup = false;
            bool inCharClass = false;
            int groupDepth = -1;
            var groupStack = new List<PatternGroup>();

            for (int i = 0; i < _pattern.Length; i++)
            {
                if (!escaped)
                {
                    c = _pattern[i];

                    switch (c)
                    {
                        case '(':
                            if (!inCharClass)
                            {
                                groupDepth++;

                                var group = new PatternGroup { StartIndex = i };
                                switch (_pattern.Substring(i + 1, 2))
                                {
                                    case "?<":
                                        group.Type = PatterGroupType.NamedCapture;
                                        break;

                                    case"?:":
                                        group.Type = PatterGroupType.Noncapture;
                                        break;

                                    case "?>":
                                        group.Type = PatterGroupType.Atomic;
                                        break;

                                    case "?=":
                                    case "?!":
                                        group.Type = PatterGroupType.LookAround;
                                        break;

                                    case "?#":
                                        group.Type = PatterGroupType.Comment;
                                        inCommentGroup = true;
                                        break;
                                }

                                groupStack.Add(group);
                                _elements.Add(group);
                            }
                            break;

                        case ')':
                            if (!inCharClass && !inCommentLine)
                            {
                                groupStack[groupDepth].EndIndex = i;
                                groupDepth--;
                            }

                            break;

                        case '#':
                            if (!inCharClass)
                            {
                                inCommentLine = true;
                                commentLine = new PatternComment { StartIndex = i };
                                _elements.Add(commentLine);
                            }
                            break;

                        case '\n':
                            if (inCommentLine)
                            {
                                inCommentLine = false;
                                commentLine.EndIndex = i;
                            }
                            break;
                    }
                }
                else
                {
                    escaped = false;
                }
            }

            if (inCommentLine)
            {
                inCommentLine = false;
                commentLine.EndIndex = _pattern.Length - 1;
            }
        }
Exemple #2
0
 public virtual void Exit(PatternComment patternComment)
 {
 }
Exemple #3
0
 public virtual UstNode Visit(PatternComment patternComment)
 {
     return(VisitChildren(patternComment));
 }
Exemple #4
0
 public virtual void Enter(PatternComment patternComment)
 {
 }