def _parse_escape(source, info, in_set): saved_ignore = source.ignore_space source.ignore_space = False ch = source.get() source.ignore_space = saved_ignore if not ch: return Character(0) if ch == u"g" and not in_set: here = source.pos try: return _parse_group_ref(source, info) except RegexpError: source.pos = here return make_character(info, ord(ch[0]), in_set) elif ch == u"G" and not in_set: return AtPosition(AT_BEGINNING) elif ch in u"pP": return _parse_property(source, info, ch == u"p", in_set) elif is_word(ord(ch[0])): if not in_set: if ch in POSITION_ESCAPES: return POSITION_ESCAPES[ch] if ch in CHARSET_ESCAPES: return CHARSET_ESCAPES[ch] elif ch in CHARACTER_ESCAPES: return Character(ord(CHARACTER_ESCAPES[ch])) return make_character(info, ord(ch[0]), in_set) if is_digit(ord(ch[0])): return _parse_numeric_escape(source, info, ch, in_set) else: return make_character(info, ord(ch[0]), in_set)
def _parse_escape(source, info, in_set): saved_ignore = source.ignore_space source.ignore_space = False ch = source.get() source.ignore_space = saved_ignore if not ch: raise RegexpError("bad escape") if ch == u"g" and not in_set: here = source.pos try: return _parse_group_ref(source, info) except RegexpError: source.pos = here return make_character(info, ord(ch[0]), in_set) elif ch == u"G" and not in_set: return AtPosition(AT_BEGINNING) elif ch in u"pP": return _parse_property(source, info, ch == u"p", in_set) elif is_word(ord(ch[0])): if not in_set: if ch in POSITION_ESCAPES: return POSITION_ESCAPES[ch] if ch in CHARSET_ESCAPES: return CHARSET_ESCAPES[ch] elif ch in CHARACTER_ESCAPES: return Character(ord(CHARACTER_ESCAPES[ch])) return make_character(info, ord(ch[0]), in_set) if is_digit(ord(ch[0])): return _parse_numeric_escape(source, info, ch, in_set) else: return make_character(info, ord(ch[0]), in_set)
def parse_number(source): acc = 0 while not source.at_end(): oldpos = source.pos ch = source.get() if not rsre_char.is_digit(ord(ch[0])): source.pos = oldpos return acc acc = 10 * acc + int(ch) return acc
def _parse_count(source): b = UnicodeBuilder(2) while True: here = source.pos ch = source.get() if is_digit(ord(ch[0])): b.append(ch) else: source.pos = here break return b.build()
def normalize_group(self, name): if is_digit(ord(name[0])): return int(name) else: return self.group_index[name]