Next / Previous / Contents / Shipman's homepage

17.16. Txny.__readAltLine(): Process one line of the alt file

nomcompile3
# - - -   T x n y . _ _ r e a d A l t L i n e

    def __readAltLine ( self, scan ):
        '''Read one line from the alt forms file.

          [ scan is a Scan instance ->
              if line in scan is valid ->
                scan  :=  scan advanced to end of file
                self.taxaTree  +:=  taxon from the line in scan, if
                                    there is one
                self.abTab  +:=  bindings from the line in scan
              else ->
                scan  :=  scan advanced not past end of line
                Log()  +:=  error message(s)
                raise SyntaxError ]
        '''
        #-- 1 --
        # [ if the line in scan starts with a valid bird code,
        #   right-padded to abbrMod.ABBR_L ->
        #     scan  :=  scan advanced by abbrMod.ABBR_L
        #     code  :=  next abbrMod.ABBR_L characters from scan
        #   else ->
        #     scan  :=  scan advanced no further than end of line
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        code = self.__scanAbbr ( scan )

        #-- 2 --
        # [ if line in scan contains at least one character ->
        #     scan  :=  scan advanced 1
        #     recordType  :=  next character from scan
        #   else ->
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        recordType = scan.move(1)

We use a dictionary to route each different record type to the method that processes that type; see Section 17.27, “Txny.dispatchTable: Routing table for alt records”.

nomcompile3
        #-- 3 --
        # [ if (recordType is a key in Txny.__dispatchTable) and
        #   (code+recordType+(line in scan)) is a valid alt forms
        #   line ->
        #     scan  :=  scan advanced to end of line
        #     self.taxaTree  +:=  taxon from that line, if any
        #     self.abTab  +:=   bindings from that line
        #   else ->
        #     scan  :=  scan advanced no further than end of line
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        try:
            scanner = Txny.__dispatchTable[recordType]
        except KeyError:
            scan.syntax ( "Record type '%s' is not valid." %
                          recordType )
        scanner ( self, scan, code )

For the purposes of Cleanroom verification, here is the generic intended function against which each of the scanner methods in Txny.__dispatchTable must be verified.

nomcompile3
        #================================================================
        # Generic intended function for methods in Txny.__dispatchTable
        #----------------------------------------------------------------
        # [ (scan is a Scan instance) and
        #   (code is a bird code) ->
        #     if (code+recordType+(line in scan)) is a valid alt
        #     forms line ->
        #       scan  :=  scan advanced to end of line
        #       self.taxaTree  +:=  taxon from that line, if any
        #       self.abTab  +:=  bindings from that line
        #     else ->
        #       scan  :=  scan advanced no further than end of line
        #       Log()  +:=  error message(s)
        #       raise SyntaxError ]
        #----------------------------------------------------------------