[Python-checkins] CVS: python/dist/src/Lib sre_compile.py,1.21,1.22 sre_parse.py,1.22,1.23
Fredrik Lundh
python-dev@python.org
Sun, 2 Jul 2000 15:25:42 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv13488/Lib
Modified Files:
sre_compile.py sre_parse.py
Log Message:
- experimental: added two new attributes to the match object:
"lastgroup" is the name of the last matched capturing group,
"lastindex" is the index of the same group. if no group was
matched, both attributes are set to None.
the (?P#) feature will be removed in the next relase.
Index: sre_compile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_compile.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** sre_compile.py 2000年07月02日 17:33:27 1.21
--- sre_compile.py 2000年07月02日 22:25:39 1.22
***************
*** 299,305 ****
"sorry, but this version only supports 100 named groups"
return _sre.compile(
pattern, flags,
array.array(WORDSIZE, code).tostring(),
! p.pattern.groups-1, p.pattern.groupdict
)
--- 299,311 ----
"sorry, but this version only supports 100 named groups"
+ # map in either direction
+ groupindex = p.pattern.groupdict
+ indexgroup = [None] * p.pattern.groups
+ for k, i in groupindex.items():
+ indexgroup[i] = k
+
return _sre.compile(
pattern, flags,
array.array(WORDSIZE, code).tostring(),
! p.pattern.groups-1, groupindex, indexgroup
)
Index: sre_parse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_parse.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** sre_parse.py 2000年07月02日 17:33:27 1.22
--- sre_parse.py 2000年07月02日 22:25:39 1.23
***************
*** 516,519 ****
--- 516,521 ----
while 1:
p = _parse(source, state)
+ if group is not None:
+ p.append((INDEX, group))
if source.match(")"):
if b: