summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/sre_compile.py19
-rw-r--r--Lib/sre_constants.py8
-rw-r--r--Lib/sre_parse.py4
-rw-r--r--Lib/test/output/test_sre3
4 files changed, 19 insertions, 15 deletions
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
index 701b267..828b170 100644
--- a/Lib/sre_compile.py
+++ b/Lib/sre_compile.py
@@ -148,18 +148,25 @@ def _compile(code, pattern, flags):
skip = len(code); emit(0)
emit(av[0])
emit(av[1])
+ mark = MAXCODE
+ if av[2][0][0] == SUBPATTERN:
+ # repeated subpattern
+ gid, foo = av[2][0][1]
+ if gid:
+ mark = (gid-1)*2
+ emit(mark)
_compile(code, av[2], flags)
emit(OPCODES[SUCCESS])
code[skip] = len(code) - skip
elif op is SUBPATTERN:
- group = av[0]
- if group:
+ gid = av[0]
+ if gid:
emit(OPCODES[MARK])
- emit((group-1)*2)
+ emit((gid-1)*2)
_compile(code, av[1], flags)
- if group:
+ if gid:
emit(OPCODES[MARK])
- emit((group-1)*2+1)
+ emit((gid-1)*2+1)
elif op in (SUCCESS, FAILURE):
emit(OPCODES[op])
elif op in (ASSERT, ASSERT_NOT):
@@ -207,7 +214,7 @@ def _compile(code, pattern, flags):
emit(CHCODES[CH_UNICODE[av]])
else:
emit(CHCODES[av])
- elif op is GROUP:
+ elif op is GROUPREF:
if flags & SRE_FLAG_IGNORECASE:
emit(OPCODES[OP_IGNORE[op]])
else:
diff --git a/Lib/sre_constants.py b/Lib/sre_constants.py
index 076637d..ef32c32 100644
--- a/Lib/sre_constants.py
+++ b/Lib/sre_constants.py
@@ -29,8 +29,8 @@ BRANCH = "branch"
CALL = "call"
CATEGORY = "category"
CHARSET = "charset"
-GROUP = "group"
-GROUP_IGNORE = "group_ignore"
+GROUPREF = "groupref"
+GROUPREF_IGNORE = "groupref_ignore"
IN = "in"
IN_IGNORE = "in_ignore"
INDEX = "index"
@@ -90,7 +90,7 @@ OPCODES = [
CALL,
CATEGORY,
CHARSET,
- GROUP, GROUP_IGNORE,
+ GROUPREF, GROUPREF_IGNORE,
INDEX,
IN, IN_IGNORE,
INFO,
@@ -136,7 +136,7 @@ CHCODES = makedict(CHCODES)
# replacement operations for "ignore case" mode
OP_IGNORE = {
- GROUP: GROUP_IGNORE,
+ GROUPREF: GROUPREF_IGNORE,
IN: IN_IGNORE,
LITERAL: LITERAL_IGNORE,
NOT_LITERAL: NOT_LITERAL_IGNORE
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 07ab782..053335a 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -241,7 +241,7 @@ def _escape(source, escape, state):
if group:
if (not source.next or
not _group(escape + source.next, state.groups)):
- return GROUP, group
+ return GROUPREF, group
escape = escape + source.get()
elif source.next in OCTDIGITS:
escape = escape + source.get()
@@ -450,7 +450,7 @@ def _parse(source, state):
gid = state.groupdict.get(name)
if gid is None:
raise error, "unknown group name"
- subpattern.append((GROUP, gid))
+ subpattern.append((GROUPREF, gid))
elif source.match("#"):
index = ""
while 1:
diff --git a/Lib/test/output/test_sre b/Lib/test/output/test_sre
index 3ba209d..d949f25 100644
--- a/Lib/test/output/test_sre
+++ b/Lib/test/output/test_sre
@@ -1,7 +1,4 @@
test_sre
=== Failed incorrectly ('^(.+)?B', 'AB', 0, 'g1', '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 ('([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'
=== Failed incorrectly ('^(.+)?B', 'AB', 0, 'g1', 'A')