# - - - T x n y . _ _ r e a d S t d
def __readStd ( self, stdFileName ):
'''Process the standard forms file.
[ stdFileName is a string ->
if stdFileName names a readable standard forms file
valid against itself and self.hier ->
self.taxaTree +:= taxa from that file
self.abTab +:= entries for the bindings of all
codes used in that file
else ->
Log() +:= error message(s)
raise IOError ]
'''
#-- 1 --
# [ if file (stdFileName) can be opened for reading ->
# scan := a Scan instance pointing at the start of
# that file
# errCount := error count from Log()
# else ->
# Log() +:= error message(s)
# raise IOError ]
try:
scan = Scan ( stdFileName )
errCount = Log().count()
except IOError, detail:
raise IOError ( "Can't open standard forms file '%s': %s" %
(stdFileName, detail) )
So that the operator can get more than one error message per
run, we pass each line of the file in turn to Section 17.5, “Txny.__readStdLine(): Process one line
from the standard forms file”, whether all the lines are
error-free or not.
#-- 2 -
# [ scan := scan advanced to end of file
# self.taxaTree +:= valid taxa from scan
# self.abTab +:= valid bindings from scan
# Log() +:= error messages from invalid lines in scan,
# if any ]
while not scan.atEndFile:
#-- 2 body --
# [ if line in scan is a valid std line in the context
# of self ->
# self.taxaTree +:= taxa from the line in scan
# self.abTab +:= bindings from the line in scan
# else ->
# self.taxaTree +:= valid taxa from the line in scan
# self.abTab +:= valid bindings from the line in scan
# Log() +:= error message(s) about the line
# in scan
# In any case ->
# scan := scan advanced to next line ]
try:
self.__readStdLine ( scan )
except SyntaxError:
pass
scan.nextLine()
If Log() has printed any error messages since
the beginning of this method, print a final error message and
terminate.
#-- 3 --
# [ if errCount < (current error count from Log()) ->
# Log() +:= error message
# raise IOError
# else -> I ]
scan.close()
netErrCount = Log().count() - errCount
if netErrCount > 0:
raise IOError ( "Execution terminated due to %d errors "
"in the standard forms file." %
netErrCount )