Whenever we call the scan.error() method
to report a syntax error, we want to include information
about what banding sheet contained the error. This
method is called from inside the Scan
class, and the string returned by this method is included
in the error message. The relevant information is the
current band size and page number.
See the discussion of the Python “bound
method” technique used with this function in Section 74.3, “BaseEncounter.__init__():
Constructor”.
There is one potential hitch here. What if there is an
error on the very first line of the file? In that case,
we'll want to return a simple “?” result. In this case, the self.pageHeader value will be None
# - - - B a s e C o m p i l e r . s c a n C a l l b a c k - - -
def scanCallback(self, scan):
'''Return an error localization string.
'''
if self.pageHeader is None:
return "?"
else:
return("sheet %s-%s" %
(self.pageHeader.size, self.pageHeader.pageNo))