Example #1
0
        private RepeatElement.RepeatType RepeatType(RepeatElement.RepeatType type)
        {
            var flag4 = this.PeekChar(0) == Convert.ToInt32('?');

            if (flag4)
            {
                this.ReadChar('?');
                type = RepeatElement.RepeatType.Reluctant;
            }
            else
            {
                var flag5 = this.PeekChar(0) == Convert.ToInt32('+');
                if (flag5)
                {
                    this.ReadChar('+');
                    type = RepeatElement.RepeatType.Possessive;
                }
            }
            return(type);
        }
Example #2
0
        //*
        // * Parses a regular expression atom modifier. This method handles
        // * the AtomModifier production in the grammar (see regexp.grammar).
        // *
        // * @param elem the element to modify
        // *
        // * @return the modified element
        // *
        // * @throws RegExpException if an error was encountered in the
        // * pattern string
        //

        private Element ParseAtomModifier(Element elem)
        {
            int min = 0;
            int max = -1;

            RepeatElement.RepeatType type = default(RepeatElement.RepeatType);
            int firstPos = 0;

            // Read min and max
            type = RepeatElement.RepeatType.GREEDY;
            switch (ReadChar())
            {
            case '?':
                min = 0;
                max = 1;
                break;

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

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

            case '{':
                firstPos = pos - 1;
                min      = ReadNumber();
                max      = min;
                if (PeekChar(0) == Convert.ToInt32(','))
                {
                    ReadChar(',');
                    max = -1;
                    if (PeekChar(0) != Convert.ToInt32('}'))
                    {
                        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 operator mode
            if (PeekChar(0) == Convert.ToInt32('?'))
            {
                ReadChar('?');
                type = RepeatElement.RepeatType.RELUCTANT;
            }
            else if (PeekChar(0) == Convert.ToInt32('+'))
            {
                ReadChar('+');
                type = RepeatElement.RepeatType.POSSESSIVE;
            }

            return(new RepeatElement(elem, min, max, type));
        }