fix scanner level error reporting in Plex/Errors.py
[cython.git] / Cython / Plex / Scanners.py
index 02c36a6a8bec78ad5cad4381d7490c13f4245f26..315742f309de1ad94f6cebbf6e485cd004d62f55 100644 (file)
@@ -8,11 +8,13 @@
 #=======================================================================
 
 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
@@ -35,10 +37,10 @@ class Scanner(object):
     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.
@@ -88,7 +90,7 @@ class Scanner(object):
     self.start_col = 0
     self.text = None
     self.state_name = None
-    
+
     self.lexicon = lexicon
     self.stream = stream
     self.name = name
@@ -179,8 +181,8 @@ class Scanner(object):
       # 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#
@@ -297,6 +299,11 @@ class Scanner(object):
     """
     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 = (