- fixed lookahead assertions (#10, #11, #12)

- untabified sre_constants.py
This commit is contained in:
Fredrik Lundh 2000-06-30 10:41:31 +00:00
parent a4657f736c
commit 43b3b49b5a
6 changed files with 146 additions and 90 deletions

View file

@ -470,6 +470,25 @@ def _parse(source, state, flags=0):
if source.next is None or source.next == ")":
break
source.get()
elif source.next in ("=", "!"):
# lookahead assertions
char = source.get()
b = []
while 1:
p = _parse(source, state, flags)
if source.next == ")":
if b:
b.append(p)
p = _branch(state, b)
if char == "=":
subpattern.append((ASSERT, p))
else:
subpattern.append((ASSERT_NOT, p))
break
elif source.match("|"):
b.append(p)
else:
raise error, "pattern not properly closed"
else:
# flags
while FLAGS.has_key(source.next):