# - - - T x n y . _ _ f i n d S u b s p P a r e n t
def __findSubspParent ( self, scan, parentCode ):
'''Find the species with code (parentCode).
[ (scan is a Scan instance) and
(parentCode is a string) ->
if parentCode is in self.abTab as a StdBind for a
species ->
parent := the Taxon for that species
else ->
Log() +:= error message(s)
raise SyntaxError ]
'''
There is no guarantee that parentCode is in the
symbol table, or that it has a binding, or that the binding is
to a species. Check all these conditions.
#-- 1 --
# [ if parentCode is in self.abTab ->
# spSym := parentCode's entry in self.abTab
# else ->
# Log() +:= error message(s)
# raise SyntaxError ]
try:
spSym = self.abTab[parentCode]
except KeyError:
scan.syntax ( "Code '%s' is unknown." % parentCode )
#-- 2 --
# [ if spSym has a StdBind binding ->
# spBind := that binding
# else ->
# Log() +:= error message(s)
# raise SyntaxError ]
spBind = spSym.binding
if spBind is None:
scan.syntax ( "Code '%s' is undefined." % parentCode )
elif not isinstance ( spBind, StdBind ):
scan.syntax ( "Code '%s is not a taxon, it is '%s'." %
(parentCode, spBind) )
#-- 3 --
# [ spBind is a StdBind ->
# if spBind describes a species ->
# species := the Taxon for that species
# else ->
# Log() +:= error message(s)
# raise SyntaxError ]
species = spBind.lookup()
if species.rank.code != SPECIES_CODE:
scan.syntax ( "The taxon for code '%s' does not have "
"species rank; it is '%s', with rank '%s'." %
(parentCode, species, species.rank) )
#-- 4 --
return species