more cythonisation in the scanner/parser
authorStefan Behnel <scoder@users.berlios.de>
Tue, 16 Nov 2010 21:42:24 +0000 (22:42 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 16 Nov 2010 21:42:24 +0000 (22:42 +0100)
Cython/Plex/Actions.pxd [new file with mode: 0644]
Cython/Plex/Actions.py
Cython/Plex/Scanners.pxd
setup.py

diff --git a/Cython/Plex/Actions.pxd b/Cython/Plex/Actions.pxd
new file mode 100644 (file)
index 0000000..34660a2
--- /dev/null
@@ -0,0 +1,25 @@
+
+cdef class Action:
+  cdef perform(self, token_stream, text)
+  cpdef same_as(self, other)
+
+cdef class Return(Action):
+  cdef object value
+  cdef perform(self, token_stream, text)
+  cpdef same_as(self, other)
+
+cdef class Call(Action):
+  cdef object function
+  cdef perform(self, token_stream, text)
+  cpdef same_as(self, other)
+
+cdef class Begin(Action):
+  cdef object state_name
+  cdef perform(self, token_stream, text)
+  cpdef same_as(self, other)
+
+cdef class Ignore(Action):
+  cdef perform(self, token_stream, text)
+
+cdef class Text(Action):
+  cdef perform(self, token_stream, text)
index 9da4e34098c944d28c1e8bf862e1bfb25c546798..50e1c9ccbd06f7dcdcf47df2bff92e3ad91e70da 100644 (file)
@@ -8,6 +8,9 @@
 
 class Action(object):
 
+  def perform(self, token_stream, text):
+    pass # abstract
+
   def same_as(self, other):
     return self is other
 
@@ -18,8 +21,6 @@ class Return(Action):
   be returned as the value of the associated token
   """
 
-  value = None
-
   def __init__(self, value):
     self.value = value
 
@@ -38,8 +39,6 @@ class Call(Action):
   Internal Plex action which causes a function to be called.
   """
 
-  function = None
-
   def __init__(self, function):
     self.function = function
 
@@ -60,8 +59,6 @@ class Begin(Action):
   for more information.
   """
 
-  state_name = None
-
   def __init__(self, state_name):
     self.state_name = state_name
 
@@ -88,7 +85,7 @@ class Ignore(Action):
     return "IGNORE"
 
 IGNORE = Ignore()
-IGNORE.__doc__ = Ignore.__doc__
+#IGNORE.__doc__ = Ignore.__doc__
 
 class Text(Action):
   """
@@ -104,6 +101,6 @@ class Text(Action):
     return "TEXT"
 
 TEXT = Text()
-TEXT.__doc__ = Text.__doc__
+#TEXT.__doc__ = Text.__doc__
 
 
index c746cc5a38bddac91a82d2b443ac759adc0d0df8..8e93e4be9e05a14cc5fe86e63c3116dc4773f8a4 100644 (file)
@@ -1,5 +1,7 @@
 import cython
 
+from Cython.Plex.Actions cimport Action
+
 cdef class Scanner:
 
     cdef public lexicon
@@ -26,6 +28,7 @@ cdef class Scanner:
 
     @cython.locals(input_state=long)
     cdef next_char(self)
+    @cython.locals(action=Action)
     cdef tuple read(self)
     cdef tuple scan_a_token(self)
     cdef tuple position(self)
index 64b4330b1c6bbe76de337211a29def36cf8b33f5..9cd680c90f4e2ec5f94c0b1ce93749f72f9fdcac 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -87,6 +87,7 @@ else:
 def compile_cython_modules(profile=False):
     source_root = os.path.abspath(os.path.dirname(__file__))
     compiled_modules = ["Cython.Plex.Scanners",
+                        "Cython.Plex.Actions",
                         "Cython.Compiler.Scanning",
                         "Cython.Compiler.Parsing",
                         "Cython.Compiler.Visitor",