From: Stefan Behnel Date: Tue, 16 Nov 2010 21:42:24 +0000 (+0100) Subject: more cythonisation in the scanner/parser X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d037a456fc7fc8c29c1929e6865f328d9f880970;p=cython.git more cythonisation in the scanner/parser --- diff --git a/Cython/Plex/Actions.pxd b/Cython/Plex/Actions.pxd new file mode 100644 index 00000000..34660a2d --- /dev/null +++ b/Cython/Plex/Actions.pxd @@ -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) diff --git a/Cython/Plex/Actions.py b/Cython/Plex/Actions.py index 9da4e340..50e1c9cc 100644 --- a/Cython/Plex/Actions.py +++ b/Cython/Plex/Actions.py @@ -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__ diff --git a/Cython/Plex/Scanners.pxd b/Cython/Plex/Scanners.pxd index c746cc5a..8e93e4be 100644 --- a/Cython/Plex/Scanners.pxd +++ b/Cython/Plex/Scanners.pxd @@ -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) diff --git a/setup.py b/setup.py index 64b4330b..9cd680c9 100644 --- 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",