[Python-checkins] CVS: python/dist/src/Lib sre.py,1.21,1.22 sre_compile.py,1.26,1.27 sre_constants.py,1.18,1.19 sre_parse.py,1.26,1.27
Fredrik Lundh
python-dev@python.org
Tue, 1 Aug 2000 11:20:10 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv13106/Lib
Modified Files:
sre.py sre_compile.py sre_constants.py sre_parse.py
Log Message:
SRE 0.9.8: passes the entire test suite
-- reverted REPEAT operator to use "repeat context" strategy
(from 0.8.X), but done right this time.
-- got rid of backtracking stack; use nested SRE_MATCH calls
instead (should probably put it back again in 0.9.9 ;-)
-- properly reset state in scanner mode
-- don't use aggressive inlining by default
Index: sre.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** sre.py 2000/07/23 21:46:17 1.21
--- sre.py 2000/08/01 18:20:06 1.22
***************
*** 6,11 ****
# Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved.
#
# Portions of this engine have been developed in cooperation with
! # CNRI. Hewlett-Packard provided funding for 2.0 integration and
# other compatibility work.
#
--- 6,15 ----
# Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved.
#
+ # This version of the SRE library can be redistributed under CNRI's
+ # Python 1.6 license. For any other use, please contact Secret Labs
+ # AB (info@pythonware.com).
+ #
# Portions of this engine have been developed in cooperation with
! # CNRI. Hewlett-Packard provided funding for 1.6 integration and
# other compatibility work.
#
***************
*** 25,29 ****
X = VERBOSE = sre_compile.SRE_FLAG_VERBOSE
! # sre extensions (may or may not be in 2.0 final)
T = TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE
U = UNICODE = sre_compile.SRE_FLAG_UNICODE
--- 29,33 ----
X = VERBOSE = sre_compile.SRE_FLAG_VERBOSE
! # sre extensions (may or may not be in 1.6/2.0 final)
T = TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE
U = UNICODE = sre_compile.SRE_FLAG_UNICODE
***************
*** 169,173 ****
class Scanner:
def __init__(self, lexicon):
! from sre_constants import BRANCH, SUBPATTERN, INDEX
self.lexicon = lexicon
# combine phrases into a compound pattern
--- 173,177 ----
class Scanner:
def __init__(self, lexicon):
! from sre_constants import BRANCH, SUBPATTERN
self.lexicon = lexicon
# combine phrases into a compound pattern
***************
*** 176,181 ****
for phrase, action in lexicon:
p.append(sre_parse.SubPattern(s, [
! (SUBPATTERN, (None, sre_parse.parse(phrase))),
! (INDEX, len(p))
]))
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
--- 180,184 ----
for phrase, action in lexicon:
p.append(sre_parse.SubPattern(s, [
! (SUBPATTERN, (len(p), sre_parse.parse(phrase))),
]))
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
Index: sre_compile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_compile.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -r1.26 -r1.27
*** sre_compile.py 2000/07/23 21:46:17 1.26
--- sre_compile.py 2000/08/01 18:20:06 1.27
***************
*** 6,12 ****
# Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
#
! # Portions of this engine have been developed in cooperation with
! # CNRI. Hewlett-Packard provided funding for 2.0 integration and
! # other compatibility work.
#
--- 6,10 ----
# Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
#
! # See the sre.py file for information on usage and redistribution.
#
***************
*** 125,128 ****
--- 123,127 ----
elif op in (REPEAT, MIN_REPEAT, MAX_REPEAT):
if flags & SRE_FLAG_TEMPLATE:
+ raise error, "internal: unsupported template operator"
emit(OPCODES[REPEAT])
skip = len(code); emit(0)
***************
*** 137,143 ****
raise error, "nothing to repeat"
if 0 and lo == hi == 1 and op is MAX_REPEAT:
! # FIXME: <fl> need a better way to figure out when
! # it's safe to use this one (in the parser, probably)
! emit(OPCODES[MAX_REPEAT_ONE])
skip = len(code); emit(0)
emit(av[0])
--- 136,141 ----
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])
***************
*** 147,173 ****
code[skip] = len(code) - skip
else:
! emit(OPCODES[op])
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:
! gid = av[0]
! if gid:
emit(OPCODES[MARK])
! emit((gid-1)*2)
_compile(code, av[1], flags)
! if gid:
emit(OPCODES[MARK])
! emit((gid-1)*2+1)
elif op in (SUCCESS, FAILURE):
emit(OPCODES[op])
--- 145,166 ----
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]:
emit(OPCODES[MARK])
! emit((av[0]-1)*2)
_compile(code, av[1], flags)
! if av[0]:
emit(OPCODES[MARK])
! emit((av[0]-1)*2+1)
elif op in (SUCCESS, FAILURE):
emit(OPCODES[op])
***************
*** 198,206 ****
emit(ATCODES[av])
elif op is BRANCH:
tail = []
for av in av[1]:
- emit(OPCODES[op])
skip = len(code); emit(0)
- emit(MAXCODE) # save mark
_compile(code, av, flags)
emit(OPCODES[JUMP])
--- 191,198 ----
emit(ATCODES[av])
elif op is BRANCH:
+ emit(OPCODES[op])
tail = []
for av in av[1]:
skip = len(code); emit(0)
_compile(code, av, flags)
emit(OPCODES[JUMP])
***************
*** 224,230 ****
emit(OPCODES[op])
emit(av-1)
- elif op in (MARK, INDEX):
- emit(OPCODES[op])
- emit(av)
else:
raise ValueError, ("unsupported operand type", op)
--- 216,219 ----
***************
*** 295,309 ****
pass
! def compile(p, flags=0):
! # internal: convert pattern list to internal format
- # compile, as necessary
- if type(p) in STRING_TYPES:
- import sre_parse
- pattern = p
- p = sre_parse.parse(p, flags)
- else:
- pattern = None
-
flags = p.pattern.flags | flags
code = []
--- 284,289 ----
pass
! def _compile1(p, flags):
flags = p.pattern.flags | flags
code = []
***************
*** 316,319 ****
--- 296,313 ----
code.append(OPCODES[SUCCESS])
+
+ return code
+
+ def compile(p, flags=0):
+ # internal: convert pattern list to internal format
+
+ if type(p) in STRING_TYPES:
+ import sre_parse
+ pattern = p
+ p = sre_parse.parse(p, flags)
+ else:
+ pattern = None
+
+ code = _compile1(p, flags)
# print code
Index: sre_constants.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_constants.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** sre_constants.py 2000/07/23 21:46:17 1.18
--- sre_constants.py 2000/08/01 18:20:06 1.19
***************
*** 7,13 ****
# Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved.
#
! # Portions of this engine have been developed in cooperation with
! # CNRI. Hewlett-Packard provided funding for 2.0 integration and
! # other compatibility work.
#
--- 7,11 ----
# Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved.
#
! # See the sre.py file for information on usage and redistribution.
#
***************
*** 34,38 ****
IN = "in"
IN_IGNORE = "in_ignore"
- INDEX = "index"
INFO = "info"
JUMP = "jump"
--- 32,35 ----
***************
*** 41,46 ****
MARK = "mark"
MAX_REPEAT = "max_repeat"
! MAX_REPEAT_ONE = "max_repeat_one"
MIN_REPEAT = "min_repeat"
NEGATE = "negate"
NOT_LITERAL = "not_literal"
--- 38,44 ----
MARK = "mark"
MAX_REPEAT = "max_repeat"
! MAX_UNTIL = "max_until"
MIN_REPEAT = "min_repeat"
+ MIN_UNTIL = "min_until"
NEGATE = "negate"
NOT_LITERAL = "not_literal"
***************
*** 92,96 ****
CHARSET,
GROUPREF, GROUPREF_IGNORE,
- INDEX,
IN, IN_IGNORE,
INFO,
--- 90,93 ----
***************
*** 98,108 ****
LITERAL, LITERAL_IGNORE,
MARK,
! MAX_REPEAT,
! MAX_REPEAT_ONE,
! MIN_REPEAT,
NOT_LITERAL, NOT_LITERAL_IGNORE,
NEGATE,
RANGE,
! REPEAT
]
--- 95,106 ----
LITERAL, LITERAL_IGNORE,
MARK,
! MAX_UNTIL,
! MIN_UNTIL,
NOT_LITERAL, NOT_LITERAL_IGNORE,
NEGATE,
RANGE,
! REPEAT,
! REPEAT_ONE,
! SUBPATTERN
]
Index: sre_parse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_parse.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -r1.26 -r1.27
*** sre_parse.py 2000/07/23 21:46:17 1.26
--- sre_parse.py 2000/08/01 18:20:06 1.27
***************
*** 6,12 ****
# Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved.
#
! # Portions of this engine have been developed in cooperation with
! # CNRI. Hewlett-Packard provided funding for 2.0 integration and
! # other compatibility work.
#
--- 6,10 ----
# Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved.
#
! # See the sre.py file for information on usage and redistribution.
#
***************
*** 537,542 ****
p = _parse_sub(source, state)
subpattern.append((SUBPATTERN, (group, p)))
- if group is not None:
- p.append((INDEX, group))
else:
while 1:
--- 535,538 ----