Example #1
0
        private NFAState ParseAtomModifier(NFAState start, NFAState end)
        {
            int min      = 0;
            int max      = -1;
            int firstPos = _pos;

            // Read min and max
            switch (ReadChar())
            {
            case '?':
                min = 0;
                max = 1;
                break;

            case '*':
                min = 0;
                max = -1;
                break;

            case '+':
                min = 1;
                max = -1;
                break;

            case '{':
                min = ReadNumber();
                max = min;
                if (PeekChar(0) == ',')
                {
                    ReadChar(',');
                    max = -1;
                    if (PeekChar(0) != '}')
                    {
                        max = ReadNumber();
                    }
                }
                ReadChar('}');
                if (max == 0 || (max > 0 && min > max))
                {
                    throw new RegExpException(
                              RegExpException.ErrorType.INVALID_REPEAT_COUNT,
                              firstPos,
                              _pattern);
                }
                break;

            default:
                throw new RegExpException(
                          RegExpException.ErrorType.UNEXPECTED_CHARACTER,
                          _pos - 1,
                          _pattern);
            }

            // Read possessive or reluctant modifiers
            if (PeekChar(0) == '?')
            {
                throw new RegExpException(
                          RegExpException.ErrorType.UNSUPPORTED_SPECIAL_CHARACTER,
                          _pos,
                          _pattern);
            }
            else if (PeekChar(0) == '+')
            {
                throw new RegExpException(
                          RegExpException.ErrorType.UNSUPPORTED_SPECIAL_CHARACTER,
                          _pos,
                          _pattern);
            }

            // Handle supported repeaters
            if (min == 0 && max == 1)
            {
                return(start.AddOut(new NFAEpsilonTransition(end)));
            }
            else if (min == 0 && max == -1)
            {
                if (end.Outgoing.Length == 0)
                {
                    end.MergeInto(start);
                }
                else
                {
                    end.AddOut(new NFAEpsilonTransition(start));
                }
                return(start);
            }
            else if (min == 1 && max == -1)
            {
                if (start.Outgoing.Length == 1 &&
                    end.Outgoing.Length == 0 &&
                    end.Incoming.Length == 1 &&
                    start.Outgoing[0] == end.Incoming[0])
                {
                    end.AddOut(start.Outgoing[0].Copy(end));
                }
                else
                {
                    end.AddOut(new NFAEpsilonTransition(start));
                }
                return(end);
            }
            else
            {
                throw new RegExpException(
                          RegExpException.ErrorType.INVALID_REPEAT_COUNT,
                          firstPos,
                          _pattern);
            }
        }
Example #2
0
 public NFANonWordTransition(NFAState state) : base(state)
 {
 }
Example #3
0
 public override NFATransition Copy(NFAState state)
 {
     return(new NFANonWordTransition(state));
 }
Example #4
0
 public override NFATransition Copy(NFAState state)
 {
     return(new NFAWhitespaceTransition(state));
 }
Example #5
0
 public NFANonWhitespaceTransition(NFAState state) : base(state)
 {
 }
Example #6
0
 public override NFATransition Copy(NFAState state)
 {
     return(new NFADigitTransition(state));
 }
Example #7
0
 public NFANonDigitTransition(NFAState state) : base(state)
 {
 }
Example #8
0
 public override NFATransition Copy(NFAState state)
 {
     return(new NFACharTransition(_match, state));
 }
Example #9
0
 public NFADotTransition(NFAState state) : base(state)
 {
 }
Example #10
0
 public NFACharTransition(char match, NFAState state) : base(state)
 {
     _match = match;
 }
Example #11
0
 public override NFATransition Copy(NFAState state)
 {
     return(new NFAEpsilonTransition(state));
 }
Example #12
0
 public NFAEpsilonTransition(NFAState state) : base(state)
 {
 }
Example #13
0
 public abstract NFATransition Copy(NFAState state);
Example #14
0
 protected NFATransition(NFAState state)
 {
     this.State = state;
     this.State.AddIn(this);
 }