Next / Previous / Contents / Shipman's homepage

17.14. Txny.__addCodeColl(): Add standard and collision symbol bindings

nomcompile3
# - - -   T x n y . _ _ a d d C o d e C o l l

    def __addCodeColl ( self, scan, taxon ):
        '''Add standard and collision bindings for a taxon.

          [ taxon is a Taxon instance ->
              if a StdBind binding for taxon.disamb and a
              CollBind binding for taxon.canon can be combined
              with self.abTab ->
                self.abTab  +:=  a StdBind binding for taxon.disamb
                    and a CollBind binding for taxon.canon
              else ->
                Log()  +:=  error message(s)
                raise SyntaxError ]
        '''

This method is for taxa that are involved in a collision. It adds two bindings: a StdBind for the disambiguation, and a CollBind for the canonical code.

Adding the standard binding is handled in Section 17.13, “Txny.__addCodeStd(): Create a standard binding”.

nomcompile3
        #-- 1 --
        # [ if a StdBind binding for taxon.disamb can be
        #   combined with self.abTab ->
        #     self.abTab  +:=  a StdBind binding for taxon.disamb
        #   else ->
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        self.__addCodeStd ( scan, taxon, taxon.disamb )

Next we create a collision binding for the taxon's canonical code; see Section 29, “class CollBind: Cluster of colliding codes”.

nomcompile3
        #-- 2 --
        # [ collBind  :=  a new CollBind relating taxon.canon to
        #       taxon.disamb ]
        collBind = CollBind ( taxon.canon, set ( [taxon.disamb] ) )

Find the existing symbol table entry for taxon.canon. If there is none, create one with no binding. See Section 24.1, “AbTab.addAbbr(): Create a symbol table entry or find an existing one”.

nomcompile3
        #-- 3 --
        # [ if self.abTab has an entry for the code
        #   taxon.canon.strip().upper() ->
        #     collSym  :=  the existing AbSym instance
        #   else ->
        #     self.abTab  +:=  a new, unbound AbSym instance for
        #                      that code
        #     collSym  :=  that AbSym instance ]
        collSym = self.abTab.addAbbr ( taxon.canon )

Try to combine the new binding with collSym. This may fail if there is an existing, incompatible binding.

nomcompile3
        #-- 4 --
        # [ if collSym's binding can be combined with collBind ->
        #     collSym  :=  collSym with collBind added
        #   else ->
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        try:
            collSym.bind ( collBind )
        except ValueError:
            scan.syntax ( "This use of '%s' conflicts with '%s'." %
                          (taxon.canon, collSym.binding) )