mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
- added support for (?P=name)
(closes #3 and #7 from the status report)
This commit is contained in:
parent
c155f828fa
commit
b71624e698
2 changed files with 17 additions and 6 deletions
|
@ -189,9 +189,9 @@ def isname(name):
|
||||||
def _group(escape, groups):
|
def _group(escape, groups):
|
||||||
# check if the escape string represents a valid group
|
# check if the escape string represents a valid group
|
||||||
try:
|
try:
|
||||||
group = int(escape[1:])
|
gid = int(escape[1:])
|
||||||
if group and group < groups:
|
if gid and gid < groups:
|
||||||
return group
|
return gid
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
return None # not a valid group
|
return None # not a valid group
|
||||||
|
@ -442,7 +442,20 @@ def _parse(source, state, flags=0):
|
||||||
raise error, "illegal character in group name"
|
raise error, "illegal character in group name"
|
||||||
elif source.match("="):
|
elif source.match("="):
|
||||||
# named backreference
|
# 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:
|
else:
|
||||||
char = source.get()
|
char = source.get()
|
||||||
if char is None:
|
if char is None:
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
test_sre
|
test_sre
|
||||||
test_support -- test failed re module pickle
|
test_support -- test failed re module pickle
|
||||||
test_support -- test failed re module cPickle
|
test_support -- test failed re module cPickle
|
||||||
=== Syntax error: ('(?P<foo_123>a)(?P=foo_123)', 'aa', 0, 'g1', 'a')
|
|
||||||
=== Failed incorrectly ('^(.+)?B', 'AB', 0, 'g1', 'A')
|
=== Failed incorrectly ('^(.+)?B', 'AB', 0, 'g1', 'A')
|
||||||
=== Failed incorrectly ('(a+)+\\1', 'aa', 0, 'found+"-"+g1', 'aa-a')
|
=== Failed incorrectly ('(a+)+\\1', 'aa', 0, 'found+"-"+g1', 'aa-a')
|
||||||
=== grouping error ('([^/]*/)*sub1/', 'd:msgs/tdir/sub1/trial/away.cpp', 0, 'found+"-"+g1', 'd:msgs/tdir/sub1/-tdir/') 'd:msgs/tdir/sub1/-trial/' should be 'd:msgs/tdir/sub1/-tdir/'
|
=== grouping error ('([^/]*/)*sub1/', 'd:msgs/tdir/sub1/trial/away.cpp', 0, 'found+"-"+g1', 'd:msgs/tdir/sub1/-tdir/') 'd:msgs/tdir/sub1/-trial/' should be 'd:msgs/tdir/sub1/-tdir/'
|
||||||
=== Syntax error: ('(?P<id>aa)(?P=id)', 'aaaa', 0, 'found+"-"+id', 'aaaa-aa')
|
|
||||||
=== grouping error ('([abc])*bcd', 'abcd', 0, 'found+"-"+g1', 'abcd-a') 'abcd-c' should be 'abcd-a'
|
=== grouping error ('([abc])*bcd', 'abcd', 0, 'found+"-"+g1', 'abcd-a') 'abcd-c' should be 'abcd-a'
|
||||||
=== grouping error ('(?i)([abc])*bcd', 'ABCD', 0, 'found+"-"+g1', 'ABCD-A') 'ABCD-C' should be 'ABCD-A'
|
=== grouping error ('(?i)([abc])*bcd', 'ABCD', 0, 'found+"-"+g1', 'ABCD-A') 'ABCD-C' should be 'ABCD-A'
|
||||||
=== Syntax error: ('a(?!b).', 'abad', 0, 'found', 'ad')
|
=== Syntax error: ('a(?!b).', 'abad', 0, 'found', 'ad')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue