# - - - T x n y . _ _ a d d C o d e S t d
def __addCodeStd ( self, scan, taxon, code ):
'''Add a StdBind symbol binding for code to taxon.
[ (scan is a Scan instance) and
(taxon is a Taxon instance) and
(code is a bird code) ->
if a StdBind binding for taxon.canon can be
combined with self.abTab ->
self.abTab +:= a StdBind binding for taxon.canon
else ->
Log() +:= error message(s)
raise SyntaxError
'''
First we create a StdBind instance relating
code to taxon; see Section 27, “class StdBind: Code bound to a
taxon”.
#-- 1 --
# [ stdBind := a StdBind instance relating code to taxon
# using taxon.eng for the English name ]
stdBind = StdBind ( code, taxon, taxon.eng )
There may already be a binding for code; if
not, create a new, empty symbol table entry. See Section 24.1, “AbTab.addAbbr(): Create a symbol table
entry or find an existing one”.
#-- 2 --
# [ if code.strip().upper() is in self.abTab ->
# stdSym := the associated AbSym instance
# else ->
# self.abTab +:= a new, unbound AbSym instance for
# code.strip().upper()
# stdSym := that AbSym instance ]
stdSym = self.abTab.addAbbr ( code )
For the logic that adds a new standard binding, or fails if
there is an existing binding, see Section 25.2, “AbSym.bind(): Try to add a binding”.
#-- 3 --
# [ if stdSym's has no binding ->
# stdSym := stdSym bound to stdBind
# else ->
# Log() +:= error message(s)
# raise SyntaxError ]
try:
stdSym.bind ( stdBind )
except ValueError:
scan.syntax ( "This use of '%s' conflicts with '%s'." %
(code, stdSym.binding) )