# - - - T x n y . _ _ r e a d S t d L i n e
def __readStdLine ( self, scan ):
'''Process one line from the std forms file
[ scan is a Scan instance ->
if line in scan is a valid std line in the context
of self ->
if the rank of the line in scan is in self.hier ->
scan := scan advanced to end of line
self.taxaTree +:= taxa from the line in scan
self.abTab +:= bindings from the line in scan
Log() +:= error message(s) for duplicate or
inconsistent bindings, if any
else ->
scan := scan advanced not past end of line
else ->
scan := scan advanced not past end of line
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
raise SyntaxError ]
'''
As a convenience for the preparation of the standard forms file, we ignore blank lines.
#-- 1 --
# [ if the line in scan is empty or contains only whitespace ->
# return
# else -> I ]
if scan.line.strip() == '':
return
A line in the standard forms file has two main parts:
The first two fields, the rank code and the status code,
are the same for all lines. This part is scanned by
Section 20, “class StdHead: The common front part of a
standard forms line”.
The format of the rest of the line depends on the rank.
If the rank code is nonblank, the rest of the line is
called the nonspecies tail. This
is scanned by Section 21, “class NonSpTail: Scanner for the non-species
tail”.
If the rank code is blank, the rest is called the
species tail, and may define
a new genus as well as a new species. This part is
scanned by Section 22, “class SpTail: Scanner for the species
tail”.
Hence, our first step is to invoke the StdHead
constructor. This constructor will raise a KeyError exception if the rank code is not in
our hierarchy; in that case, we simply return, because
this line is to be ignored. If the line is not in the
right format, it will raise SyntaxError.
#-- 2 --
# [ if the line in scan starts with a standard forms head ->
# if the rank code is blank or a code in self.hier ->
# scan := scan advanced past the head
# stdHead := a StdHead instance representing the head
# else ->
# scan := scan not advanced past end of line
# return
# else ->
# scan := scan advanced not past end of line
# Log() +:= error messages
# raise SyntaxError ]
try:
stdHead = StdHead ( self.hier, scan )
except KeyError:
return
If the line starts with a rank code, stdHead.rank will contain the corresponding Rank instance;
parse the rest of the line using Section 17.6, “Txny.__scanNonSpTail(): Process
higher-taxon tail”. If the line had no rank code,
it is a species line, and stdHead.rank is set
to None; parse the remainder using
Section 17.8, “Txny.__scanSpTail(): Process a species
tail”.
#-- 3 --
# [ if (stdHead.rank is not None) and
# (line in scan contains a valid non-species tail) ->
# scan := scan advanced to end of line
# self.taxaTree +:= taxon added from stdHead and
# that tail
# else if (stdHead.rank is None) and
# (line in scan contains a valid species tail) ->
# scan := scan advanced to end of line
# self.taxaTree +:= taxa added from stdHead and that tail
# self.abTab +:= bindings added from stdHead and that tail
# else ->
# scan := scan advanced not past end of line
# Log() +:= error message(s)
# raise SyntaxError ]
if stdHead.rank is not None:
#-- 3.1 --
# [ if line in scan contains a valid non-species tail ->
# scan := scan advanced to end of line
# self.taxaTree +:= taxon added from stdHead and
# that tail
# Log() +:= error messages for duplicate or
# inconsistent bindings, if any
# else ->
# scan := scan advanced not past end of line
# Log() +:= error message(s)
# raise SyntaxError ]
self.__scanNonSpTail ( scan, stdHead )
else:
#-- 3.2 --
# [ if line in scan contains a valid species tail ->
# scan := scan advanced to end of line
# self.taxaTree +:= taxa from stdHead and that tail
# self.abTab +:= bindings from stdHead and that tail
# else ->
# scan := scan advanced not past end of line
# Log() +:= error message(s)
# raise SyntaxError ]
self.__scanSpTail ( scan, stdHead )