code: def print_error(input, err, scanner):
      
      p = err.pos
      # Figure out the line number
      line = input[:p].count('\n')
      print err.msg + " on line " + repr(line + 1) + ":"
      # Now try printing part of the line
      text = input[max(p - 80, 0):
          p + 80]
      p = p - max(p - 80, 0)
  
      # Strip to the left
      i = text[:p].rfind('\n')
      j = text[:p].rfind('\r')
      if i < 0 or (0 <= j < i):
          i = j
      if 0 <= i < p:
          p = p - i - 1
          text = text[i + 1:]
  
      # Strip to the right
      i = text.find('\n', p)
      j = text.find('\r', p)
      if i < 0 or (0 <= j < i):
          i = j
      if i >= 0:
          text = text[:i]
  
      # Now shorten the text
      while len(text) > 70 and p > 60:
          # Cut off 10 chars
          text = "..." + text[10:]
          p = p - 7
  
      # Now print the string, along with an indicator
      print '> ', text
      print '> ', ' ' * p + '^'
      print 'List of nearby tokens:', scanner
docs: This is a really dumb long function to print error messages nicely.