[pypy-svn] r15877 - pypy/dist/pypy/module/_sre

nik at codespeak.net nik at codespeak.net
Wed Aug 10 00:34:43 CEST 2005


Author: nik
Date: Wed Aug 10 00:34:40 2005
New Revision: 15877

Added:
   pypy/dist/pypy/module/_sre/interp_sre.py   (contents, props changed)
Modified:
   pypy/dist/pypy/module/_sre/__init__.py
   pypy/dist/pypy/module/_sre/app_sre.py
Log:
converted some obvious candidate functions to interp-level.


Modified: pypy/dist/pypy/module/_sre/__init__.py
==============================================================================
--- pypy/dist/pypy/module/_sre/__init__.py	(original)
+++ pypy/dist/pypy/module/_sre/__init__.py	Wed Aug 10 00:34:40 2005
@@ -18,4 +18,8 @@
     }
 
     interpleveldefs = {
+        '_is_digit':      'interp_sre._is_digit',
+        '_is_space':      'interp_sre._is_space',
+        '_is_word':       'interp_sre._is_word',
+        '_is_linebreak':  'interp_sre._is_linebreak',
     }

Modified: pypy/dist/pypy/module/_sre/app_sre.py
==============================================================================
--- pypy/dist/pypy/module/_sre/app_sre.py	(original)
+++ pypy/dist/pypy/module/_sre/app_sre.py	Wed Aug 10 00:34:40 2005
@@ -11,6 +11,7 @@
 from sre_constants import ATCODES, OPCODES, CHCODES, MAXREPEAT
 from sre_constants import SRE_INFO_PREFIX, SRE_INFO_LITERAL
 from sre_constants import SRE_FLAG_UNICODE, SRE_FLAG_LOCALE
+import _sre
 from _sre import CODESIZE
 
 
@@ -500,7 +501,7 @@
         return self.string_position == self.state.end
 
     def at_linebreak(self):
-        return not self.at_end() and _is_linebreak(self.peek_char())
+        return not self.at_end() and _sre._is_linebreak(self.peek_char())
 
     def at_boundary(self, word_checker):
         if self.at_beginning() and self.at_end():
@@ -1157,7 +1158,7 @@
         return ctx.at_beginning()
     at_beginning_string = at_beginning
     def at_beginning_line(self, ctx):
-        return ctx.at_beginning() or _is_linebreak(ctx.peek_char(-1))
+        return ctx.at_beginning() or _sre._is_linebreak(ctx.peek_char(-1))
     def at_end(self, ctx):
         return (ctx.remaining_chars() == 1 and ctx.at_linebreak()) or ctx.at_end()
     def at_end_line(self, ctx):
@@ -1165,9 +1166,9 @@
     def at_end_string(self, ctx):
         return ctx.at_end()
     def at_boundary(self, ctx):
-        return ctx.at_boundary(_is_word)
+        return ctx.at_boundary(_sre._is_word)
     def at_non_boundary(self, ctx):
-        return not ctx.at_boundary(_is_word)
+        return not ctx.at_boundary(_sre._is_word)
     def at_loc_boundary(self, ctx):
         return ctx.at_boundary(_is_loc_word)
     def at_loc_non_boundary(self, ctx):
@@ -1185,21 +1186,21 @@
 class _ChcodeDispatcher(_Dispatcher):
 
     def category_digit(self, ctx):
-        return _is_digit(ctx.peek_char())
+        return _sre._is_digit(ctx.peek_char())
     def category_not_digit(self, ctx):
-        return not _is_digit(ctx.peek_char())
+        return not _sre._is_digit(ctx.peek_char())
     def category_space(self, ctx):
-        return _is_space(ctx.peek_char())
+        return _sre._is_space(ctx.peek_char())
     def category_not_space(self, ctx):
-        return not _is_space(ctx.peek_char())
+        return not _sre._is_space(ctx.peek_char())
     def category_word(self, ctx):
-        return _is_word(ctx.peek_char())
+        return _sre._is_word(ctx.peek_char())
     def category_not_word(self, ctx):
-        return not _is_word(ctx.peek_char())
+        return not _sre._is_word(ctx.peek_char())
     def category_linebreak(self, ctx):
-        return _is_linebreak(ctx.peek_char())
+        return _sre._is_linebreak(ctx.peek_char())
     def category_not_linebreak(self, ctx):
-        return not _is_linebreak(ctx.peek_char())
+        return not _sre._is_linebreak(ctx.peek_char())
     def category_loc_word(self, ctx):
         return _is_loc_word(ctx.peek_char())
     def category_loc_not_word(self, ctx):
@@ -1226,36 +1227,12 @@
 _ChcodeDispatcher.build_dispatch_table(CHCODES, "")
 
 
-_ascii_char_info = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 6, 2,
-2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, 25, 25, 25,
-25, 25, 0, 0, 0, 0, 0, 0, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0,
-0, 0, 16, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0, 0, 0, 0 ]
-
-def _is_digit(char):
-    code = ord(char)
-    return code < 128 and _ascii_char_info[code] & 1
-
-def _is_space(char):
-    code = ord(char)
-    return code < 128 and _ascii_char_info[code] & 2
-
-def _is_word(char):
-    # NB: non-ASCII chars aren't words according to _sre.c
-    code = ord(char)
-    return code < 128 and _ascii_char_info[code] & 16
-
 def _is_loc_word(char):
     return (not (ord(char) & ~255) and char.isalnum()) or char == '_'
 
 def _is_uni_word(char):
     return char.isalnum() or char == '_'
 
-def _is_linebreak(char):
-    return char == "\n"
-
 # Static list of all unicode codepoints reported by Py_UNICODE_ISLINEBREAK.
 _uni_linebreaks = [10, 13, 28, 29, 30, 133, 8232, 8233]
 

Added: pypy/dist/pypy/module/_sre/interp_sre.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/_sre/interp_sre.py	Wed Aug 10 00:34:40 2005
@@ -0,0 +1,26 @@
+from pypy.interpreter.baseobjspace import ObjSpace
+
+_ascii_char_info = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 6, 2,
+2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, 25, 25, 25,
+25, 25, 0, 0, 0, 0, 0, 0, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0,
+0, 0, 16, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0, 0, 0, 0 ]
+
+_linebreak = ord("\n")
+
+def _is_digit(space, w_char):
+    code = space.int_w(space.ord(w_char))
+    return space.newbool(code < 128 and _ascii_char_info[code] & 1)
+
+def _is_space(space, w_char):
+    code = space.int_w(space.ord(w_char))
+    return space.newbool(code < 128 and _ascii_char_info[code] & 2)
+
+def _is_word(space, w_char):
+    code = space.int_w(space.ord(w_char))
+    return space.newbool(code < 128 and _ascii_char_info[code] & 16)
+
+def _is_linebreak(space, w_char):
+    return space.newbool(space.int_w(space.ord(w_char)) == _linebreak)



More information about the Pypy-commit mailing list