diff options
author | Fredrik Lundh <fredrik@pythonware.com> | 2000-07-03 18:44:21 (GMT) |
---|---|---|
committer | Fredrik Lundh <fredrik@pythonware.com> | 2000-07-03 18:44:21 (GMT) |
commit | 6f013982366154ce570f69b6117dbcc6b1d5d89a (patch) | |
tree | 00f3bcae833f7bbcb15ba1a22ef2bdac3c148033 /Lib/sre_compile.py | |
parent | 40c48685a2b16dc7fdccd82fe1d927e52ed5e3db (diff) | |
download | cpython-6f013982366154ce570f69b6117dbcc6b1d5d89a.zip cpython-6f013982366154ce570f69b6117dbcc6b1d5d89a.tar.gz cpython-6f013982366154ce570f69b6117dbcc6b1d5d89a.tar.bz2 |
- added lookbehind support (?<=pattern), (?<!pattern).
the pattern must have a fixed width.
- got rid of array-module dependencies; the match pro-
gram is now stored inside the pattern object, rather
than in an extra string buffer.
- cleaned up a various of potential leaks, api abuses,
and other minors in the engine module.
- use mal's new isalnum macro, rather than my own work-
around.
- untabified test_sre.py. seems like I removed a couple
of trailing spaces in the process...
Diffstat (limited to 'Lib/sre_compile.py')
-rw-r--r-- | Lib/sre_compile.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py index 36986eb..701b267 100644 --- a/Lib/sre_compile.py +++ b/Lib/sre_compile.py @@ -10,18 +10,10 @@ # other compatibility work. # -import array import _sre from sre_constants import * -# find an array type code that matches the engine's code size -for WORDSIZE in "Hil": - if len(array.array(WORDSIZE, [0]).tostring()) == _sre.getcodesize(): - break -else: - raise RuntimeError, "cannot find a useable array type" - MAXCODE = 65535 def _charset(charset, fixup): @@ -170,7 +162,20 @@ def _compile(code, pattern, flags): emit((group-1)*2+1) elif op in (SUCCESS, FAILURE): emit(OPCODES[op]) - elif op in (ASSERT, ASSERT_NOT, CALL): + elif op in (ASSERT, ASSERT_NOT): + emit(OPCODES[op]) + skip = len(code); emit(0) + if av[0] >= 0: + emit(0) # look ahead + else: + lo, hi = av[1].getwidth() + if lo != hi: + raise error, "look-behind requires fixed-width pattern" + emit(lo) # look behind + _compile(code, av[1], flags) + emit(OPCODES[SUCCESS]) + code[skip] = len(code) - skip + elif op is CALL: emit(OPCODES[op]) skip = len(code); emit(0) _compile(code, av, flags) @@ -305,7 +310,7 @@ def compile(p, flags=0): indexgroup[i] = k return _sre.compile( - pattern, flags, - array.array(WORDSIZE, code).tostring(), - p.pattern.groups-1, groupindex, indexgroup + pattern, flags, code, + p.pattern.groups-1, + groupindex, indexgroup ) |