#=======================================================================
import cython
-cython.declare(BOL=object, EOL=object, EOF=object)
+cython.declare(BOL=object, EOL=object, EOF=object, NOT_FOUND=object)
import Errors
from Regexps import BOL, EOL, EOF
+NOT_FOUND = object()
+
class Scanner(object):
"""
A Scanner is used to read tokens from a stream of characters
position() --> (name, line, col)
Returns the position of the last token read using the
read() method.
-
+
begin(state_name)
Causes scanner to change state.
-
+
produce(value [, text])
Causes return of a token value to the caller of the
Scanner.
self.start_col = 0
self.text = None
self.state_name = None
-
+
self.lexicon = lexicon
self.stream = stream
self.name = name
# End inlined self.save_for_backup()
c = cur_char
#new_state = state.new_state(c) #@slow
- new_state = state.get(c, -1) #@fast
- if new_state == -1: #@fast
+ new_state = state.get(c, NOT_FOUND) #@fast
+ if new_state is NOT_FOUND: #@fast
new_state = c and state.get('else') #@fast
if new_state:
if trace: #TRACE#
"""
return (self.name, self.start_line, self.start_col)
+ def get_position(self):
+ """Python accessible wrapper around position(), only for error reporting.
+ """
+ return self.position()
+
def begin(self, state_name):
"""Set the current state of the scanner to the named state."""
self.initial_state = (