Commit 7190799a authored by Stefan Behnel's avatar Stefan Behnel

A bit more cythonisation in Machines.py and Transitions.py.

parent b2afb116
cimport cython
@cython.final
cdef class Node:
cdef readonly object transitions # TransitionMap
cdef readonly object action # Action
cdef public object epsilon_closure # dict
cdef readonly Py_ssize_t number
cdef readonly long action_priority
@cython.final
cdef class FastMachine: cdef class FastMachine:
cdef readonly dict initial_states cdef readonly dict initial_states
cdef readonly dict new_state_template cdef readonly dict new_state_template
......
...@@ -68,17 +68,15 @@ class Machine(object): ...@@ -68,17 +68,15 @@ class Machine(object):
class Node(object): class Node(object):
"""A state of an NFA or DFA.""" """A state of an NFA or DFA."""
transitions = None # TransitionMap
action = None # Action
action_priority = None # integer
number = 0 # for debug output
epsilon_closure = None # used by nfa_to_dfa()
def __init__(self): def __init__(self):
# Preinitialise the list of empty transitions, because # Preinitialise the list of empty transitions, because
# the nfa-to-dfa algorithm needs it # the nfa-to-dfa algorithm needs it
self.transitions = TransitionMap() self.transitions = TransitionMap() # TransitionMap
self.action_priority = LOWEST_PRIORITY self.action_priority = LOWEST_PRIORITY # integer
self.action = None # Action
self.number = 0 # for debug output
self.epsilon_closure = None # used by nfa_to_dfa()
def destroy(self): def destroy(self):
self.transitions = None self.transitions = None
...@@ -127,6 +125,9 @@ class Node(object): ...@@ -127,6 +125,9 @@ class Node(object):
def __lt__(self, other): def __lt__(self, other):
return self.number < other.number return self.number < other.number
def __hash__(self):
return id(self)
class FastMachine(object): class FastMachine(object):
""" """
......
...@@ -153,6 +153,7 @@ class TransitionMap(object): ...@@ -153,6 +153,7 @@ class TransitionMap(object):
map[hi:hi] = [code, map[hi - 1].copy()] map[hi:hi] = [code, map[hi - 1].copy()]
return hi return hi
@cython.ccall
def get_special(self, event): def get_special(self, event):
""" """
Get state set for special event, adding a new entry if necessary. Get state set for special event, adding a new entry if necessary.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment