code: def error(self, s, pos):
          
          print("Lexical error:")
          print("%s" % s[:pos+10])  # + 10 for trailing context
          print("%s^" % (" "*(pos-1)))
          for t in self.rv: print(t)
          raise SystemExit
docs: Show text and a caret under that. For example:
  x = 2y + z
       ^