Skip to content

Commit

Permalink
more cythonisation in the scanner/parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Behnel committed Nov 16, 2010
1 parent 698b502 commit d037a45
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
25 changes: 25 additions & 0 deletions 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)
13 changes: 5 additions & 8 deletions Cython/Plex/Actions.py
Expand Up @@ -8,6 +8,9 @@

class Action(object):

def perform(self, token_stream, text):
pass # abstract

def same_as(self, other):
return self is other

Expand All @@ -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

Expand All @@ -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

Expand All @@ -60,8 +59,6 @@ class Begin(Action):
for more information.
"""

state_name = None

def __init__(self, state_name):
self.state_name = state_name

Expand All @@ -88,7 +85,7 @@ def __repr__(self):
return "IGNORE"

IGNORE = Ignore()
IGNORE.__doc__ = Ignore.__doc__
#IGNORE.__doc__ = Ignore.__doc__

class Text(Action):
"""
Expand All @@ -104,6 +101,6 @@ def __repr__(self):
return "TEXT"

TEXT = Text()
TEXT.__doc__ = Text.__doc__
#TEXT.__doc__ = Text.__doc__


3 changes: 3 additions & 0 deletions Cython/Plex/Scanners.pxd
@@ -1,5 +1,7 @@
import cython

from Cython.Plex.Actions cimport Action

cdef class Scanner:

cdef public lexicon
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -87,6 +87,7 @@ def add_command_class(name, cls):
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",
Expand Down

0 comments on commit d037a45

Please sign in to comment.