Beispiel #1
0
        /**
         * Creates a copy of this transition but with another target
         * state.
         *
         * @param state          the new target state
         *
         * @return an identical copy of this transition
         */
        public override NFATransition Copy(NFAState state)
        {
            NFACharRangeTransition copy;

            copy          = new NFACharRangeTransition(inverse, ignoreCase, state);
            copy.contents = contents;
            return(copy);
        }
        /**
         * Parses a regular expression character set. This method handles
         * the contents of the '[...]' construct in a regular expression.
         *
         * @param start          the initial NFA state
         *
         * @return the terminating NFA state
         *
         * @throws RegExpException if an error was encountered in the
         *             pattern string
         */
        private NFAState ParseCharSet(NFAState start)
        {
            NFAState end = new NFAState();
            NFACharRangeTransition range;
            char min;
            char max;

            if (PeekChar(0) == '^')
            {
                ReadChar('^');
                range = new NFACharRangeTransition(true, ignoreCase, end);
            }
            else
            {
                range = new NFACharRangeTransition(false, ignoreCase, end);
            }
            start.AddOut(range);
            while (PeekChar(0) > 0)
            {
                min = (char)PeekChar(0);
                switch (min)
                {
                case ']':
                    return(end);

                case '\\':
                    range.AddCharacter(ReadEscapeChar());
                    break;

                default:
                    ReadChar(min);
                    if (PeekChar(0) == '-' &&
                        PeekChar(1) > 0 &&
                        PeekChar(1) != ']')
                    {
                        ReadChar('-');
                        max = ReadChar();
                        range.AddRange(min, max);
                    }
                    else
                    {
                        range.AddCharacter(min);
                    }
                    break;
                }
            }
            return(end);
        }