[Python-checkins] CVS: python/dist/src/Lib sre.py,1.22,1.23 sre_compile.py,1.28,1.29 sre_constants.py,1.19,1.20 sre_parse.py,1.28,1.29
Fredrik Lundh
python-dev@python.org
Tue, 1 Aug 2000 15:47:51 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv10513/Lib
Modified Files:
sre.py sre_compile.py sre_constants.py sre_parse.py
Log Message:
final 0.9.8 updates:
-- added REPEAT_ONE operator
-- added ANY_ALL operator (used to represent "(?s).")
Index: sre.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** sre.py 2000/08/01 18:20:06 1.22
--- sre.py 2000/08/01 22:47:48 1.23
***************
*** 99,103 ****
except KeyError:
pass
! p = sre_compile.compile(pattern, flags)
if len(_cache) >= _MAXCACHE:
_cache.clear()
--- 99,106 ----
except KeyError:
pass
! try:
! p = sre_compile.compile(pattern, flags)
! except error, v:
! raise error, v # invalid expression
if len(_cache) >= _MAXCACHE:
_cache.clear()
Index: sre_compile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_compile.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -r1.28 -r1.29
*** sre_compile.py 2000/08/01 21:05:40 1.28
--- sre_compile.py 2000/08/01 22:47:48 1.29
***************
*** 74,77 ****
--- 74,84 ----
return charset
+ def _simple(av):
+ # check if av is a "simple" operator
+ lo, hi = av[2].getwidth()
+ if lo == 0:
+ raise error, "nothing to repeat"
+ return lo == hi == 1 and av[2][0][0] != SUBPATTERN
+
def _compile(code, pattern, flags):
# internal: compile a (sub)pattern
***************
*** 117,124 ****
elif op is ANY:
if flags & SRE_FLAG_DOTALL:
! emit(OPCODES[op])
else:
! emit(OPCODES[CATEGORY])
! emit(CHCODES[CATEGORY_NOT_LINEBREAK])
elif op in (REPEAT, MIN_REPEAT, MAX_REPEAT):
if flags & SRE_FLAG_TEMPLATE:
--- 124,130 ----
elif op is ANY:
if flags & SRE_FLAG_DOTALL:
! emit(OPCODES[ANY_ALL])
else:
! emit(OPCODES[ANY])
elif op in (REPEAT, MIN_REPEAT, MAX_REPEAT):
if flags & SRE_FLAG_TEMPLATE:
***************
*** 131,158 ****
emit(OPCODES[SUCCESS])
code[skip] = len(code) - skip
else:
! lo, hi = av[2].getwidth()
! if lo == 0:
! raise error, "nothing to repeat"
! if 0 and lo == hi == 1 and op is MAX_REPEAT:
! # FIXME: <fl> fast and wrong (but we'll fix that)
! emit(OPCODES[REPEAT_ONE])
! skip = len(code); emit(0)
! emit(av[0])
! emit(av[1])
! _compile(code, av[2], flags)
! emit(OPCODES[SUCCESS])
! code[skip] = len(code) - skip
else:
! emit(OPCODES[REPEAT])
! skip = len(code); emit(0)
! emit(av[0])
! emit(av[1])
! _compile(code, av[2], flags)
! code[skip] = len(code) - skip
! if op == MAX_REPEAT:
! emit(OPCODES[MAX_UNTIL])
! else:
! emit(OPCODES[MIN_UNTIL])
elif op is SUBPATTERN:
if av[0]:
--- 137,159 ----
emit(OPCODES[SUCCESS])
code[skip] = len(code) - skip
+ elif _simple(av) and op == MAX_REPEAT:
+ emit(OPCODES[REPEAT_ONE])
+ skip = len(code); emit(0)
+ emit(av[0])
+ emit(av[1])
+ _compile(code, av[2], flags)
+ emit(OPCODES[SUCCESS])
+ code[skip] = len(code) - skip
else:
! emit(OPCODES[REPEAT])
! skip = len(code); emit(0)
! emit(av[0])
! emit(av[1])
! _compile(code, av[2], flags)
! code[skip] = len(code) - skip
! if op == MAX_REPEAT:
! emit(OPCODES[MAX_UNTIL])
else:
! emit(OPCODES[MIN_UNTIL])
elif op is SUBPATTERN:
if av[0]:
Index: sre_constants.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_constants.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** sre_constants.py 2000/08/01 18:20:06 1.19
--- sre_constants.py 2000/08/01 22:47:48 1.20
***************
*** 21,24 ****
--- 21,25 ----
ANY = "any"
+ ANY_ALL = "any_all"
ASSERT = "assert"
ASSERT_NOT = "assert_not"
***************
*** 82,86 ****
FAILURE, SUCCESS,
! ANY,
ASSERT, ASSERT_NOT,
AT,
--- 83,87 ----
FAILURE, SUCCESS,
! ANY, ANY_ALL,
ASSERT, ASSERT_NOT,
AT,
Index: sre_parse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_parse.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -r1.28 -r1.29
*** sre_parse.py 2000/08/01 21:05:40 1.28
--- sre_parse.py 2000/08/01 22:47:48 1.29
***************
*** 143,147 ****
l, h = av.getwidth()
i = min(i, l)
! j = min(j, h)
lo = lo + i
hi = hi + j
--- 143,147 ----
l, h = av.getwidth()
i = min(i, l)
! j = max(j, h)
lo = lo + i
hi = hi + j