summaryrefslogtreecommitdiffstats
path: root/Lib/sre_parse.py
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2000-06-30 09:13:06 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2000-06-30 09:13:06 (GMT)
commitb71624e6988966b53b72f9447bbaa06e0a004eb0 (patch)
tree0a2fe86c844aec7ca742c59f2d1360904a1fef0f /Lib/sre_parse.py
parentc155f828faeb115f82d527d786da4f662ebcbbd8 (diff)
downloadcpython-b71624e6988966b53b72f9447bbaa06e0a004eb0.zip
cpython-b71624e6988966b53b72f9447bbaa06e0a004eb0.tar.gz
cpython-b71624e6988966b53b72f9447bbaa06e0a004eb0.tar.bz2
- added support for (?P=name)
(closes #3 and #7 from the status report)
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r--Lib/sre_parse.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 40f2cb5..a6f3082 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -189,9 +189,9 @@ def isname(name):
def _group(escape, groups):
# check if the escape string represents a valid group
try:
- group = int(escape[1:])
- if group and group < groups:
- return group
+ gid = int(escape[1:])
+ if gid and gid < groups:
+ return gid
except ValueError:
pass
return None # not a valid group
@@ -442,7 +442,20 @@ def _parse(source, state, flags=0):
raise error, "illegal character in group name"
elif source.match("="):
# named backreference
- raise error, "not yet implemented"
+ name = ""
+ while 1:
+ char = source.get()
+ if char is None:
+ raise error, "unterminated name"
+ if char == ")":
+ break
+ name = name + char
+ if not isname(name):
+ raise error, "illegal character in group name"
+ gid = state.groupdict.get(name)
+ if gid is None:
+ raise error, "unknown group name"
+ subpattern.append((GROUP, gid))
else:
char = source.get()
if char is None: