Ejemplo n.º 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);
        }
        /// <summary>
        /// Parses a regular expression character set. This method handles
        /// the contents of the '[...]' construct in a regular expression.
        /// </summary>
        /// <param name="start">The initial NFA state</param>
        /// <returns>The terminating NFA state</returns>
        /// <exception cref="RegExpException">
        /// If an error was encountered in the pattern string
        /// </exception>
        private NFAState ParseCharSet(NFAState start)
        {
            NFAState end = new NFAState();
            NFACharRangeTransition range;
            char min;
            char max;

            if (this.PeekChar(0) == '^')
            {
                this.ReadChar('^');
                range = new NFACharRangeTransition(true, this.ignoreCase, end);
            }
            else
            {
                range = new NFACharRangeTransition(false, this.ignoreCase, end);
            }

            start.AddOut(range);

            while (this.PeekChar(0) > 0)
            {
                min = (char)this.PeekChar(0);
                switch (min)
                {
                case ']':
                    return(end);

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

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

                    break;
                }
            }

            return(end);
        }
Ejemplo n.º 3
0
        /**
         * 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;
        }
Ejemplo n.º 4
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;
        }