예제 #1
0
 /**
  * Creates a new matcher with the specified element.
  *
  * @param e              the base regular expression element
  * @param buffer         the input character buffer to work with
  * @param ignoreCase     the character case ignore flag
  */
 internal Matcher(Element e, ReaderBuffer buffer, bool ignoreCase) {
     this.element = e;
     this.buffer = buffer;
     this.ignoreCase = ignoreCase;
     this.start = 0;
     Reset();
 }
예제 #2
0
 /**
  * Creates a new alternative element.
  *
  * @param first          the first alternative
  * @param second         the second alternative
  */
 public AlternativeElement(Element first, Element second)
 {
     elem1 = first;
     elem2 = second;
 }
예제 #3
0
 /**
  * Creats a new element repeater.
  *
  * @param elem           the element to repeat
  * @param min            the minimum count
  * @param max            the maximum count
  * @param type           the repeat type constant
  */
 public RepeatElement(Element elem,
                      int min,
                      int max,
                      RepeatType type)
 {
     this.elem = elem;
     this.min = min;
     if (max <= 0) {
         this.max = Int32.MaxValue;
     } else {
         this.max = max;
     }
     this.type = type;
     this.matchStart = -1;
     this.matches = null;
 }
예제 #4
0
 /**
  * Creates a new combine element.
  *
  * @param first          the first element
  * @param second         the second element
  */
 public CombineElement(Element first, Element second) {
     elem1 = first;
     elem2 = second;
 }
예제 #5
0
파일: RegExp.cs 프로젝트: netgrim/FleeSharp
 /**
  * Creates a new regular expression. The regular expression
  * can be either case-sensitive or case-insensitive.
  *
  * @param pattern        the regular expression pattern
  * @param ignoreCase     the character case ignore flag
  *
  * @throws RegExpException if the regular expression couldn't be
  *             parsed correctly
  *
  * @since 1.5
  */
 public RegExp(string pattern, bool ignoreCase) {
     this.pattern = pattern;
     this.ignoreCase = ignoreCase;
     this.pos = 0;
     this.element = ParseExpr();
     if (pos < pattern.Length) {
         throw new RegExpException(
             RegExpException.ErrorType.UNEXPECTED_CHARACTER,
             pos,
             pattern);
     }
 }
예제 #6
0
파일: RegExp.cs 프로젝트: netgrim/FleeSharp
        /**
         * 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;
            int                       firstPos;

            // 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) == ',') {
                    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 operator mode
            if (PeekChar(0) == '?') {
                ReadChar('?');
                type = RepeatElement.RepeatType.RELUCTANT;
            } else if (PeekChar(0) == '+') {
                ReadChar('+');
                type = RepeatElement.RepeatType.POSSESSIVE;
            }

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