New version from Jeffrey after I complained about some glaring bugs.

This commit is contained in:
Guido van Rossum 1997-07-11 11:08:38 +00:00
parent 443389fd2e
commit 63e18195b8
2 changed files with 14 additions and 6 deletions

View File

@ -137,7 +137,7 @@ class MatchObject:
except (KeyError, TypeError):
raise IndexError
return self.regs[i]
def group(i):
def group(self, i):
if type(i) == type(''):
try:
i = self.re.groupindex[i]
@ -188,12 +188,13 @@ class Set(Instruction):
name = 'set'
def __init__(self, set):
self.set = set
print set
Instruction.__init__(self, chr(3), 33)
def assemble_set(self, position, labels):
def assemble(self, position, labels):
result = self.opcode
temp = 0
for i, c in map(lambda x: (x, chr(x)), range(256)):
if c in self.set[2]:
if c in self.set:
temp = temp | (1 << (i & 7))
if (i % 8) == 7:
result = result + chr(temp)
@ -203,7 +204,7 @@ class Set(Instruction):
result = '%-15s' % (self.name)
self.set.sort()
for char in self.set:
result = result + `char`
result = result + char
return result
class Exact(Instruction):
@ -768,7 +769,7 @@ def compile(pattern, flags=0):
expr.append(Label(label))
label = label + 1
if stack[-1][0][1] > 0:
if stack[-1][0].register > 0:
expr = [StartMemory(stack[-1][0].register)] + \
expr + \
[EndMemory(stack[-1][0].register)]
@ -1075,7 +1076,6 @@ def compile(pattern, flags=0):
if next not in set:
set.append(next)
last = next
if pattern[index] != ']':
raise error, 'incomplete set'

View File

@ -119,6 +119,10 @@ reop_match(self, args)
PyErr_SetString(ReopError, "match failure");
return NULL;
}
if (result == -1) {
Py_INCREF(Py_None);
return Py_None;
}
return makeresult(&re_regs, num_regs);
}
@ -162,6 +166,10 @@ reop_search(self, args)
PyErr_SetString(ReopError, "match failure");
return NULL;
}
if (result == -1) {
Py_INCREF(Py_None);
return Py_None;
}
return makeresult(&re_regs, num_regs);
}