Next / Previous / Contents / Shipman's homepage

20.2. StdHead.__scanRankCode()

nomcompile3
# - - -   S t d H e a d . _ _ s c a n R a n k C o d e

    def __scanRankCode ( self, hier, scan ):
        '''Process the rank code field.

          [ (hier is a Hier instance) and
            (scan is a Scan instance) ->
              if scan starts with a rank code ->
                if the rank code is in hier ->
                  scan  :=  scan advanced past that rank code
                  self.rank  :=  the Rank instance corresponding to
                                 that code in hier
                else ->
                  scan  :=  scan not advanced past end of line
                  raise KeyError
              else if scan starts with L_RANK_CODE blanks ->
                scan  :=  scan advanced L_RANK_CODE
                self.rank  :=  None
              else ->
                scan  :=  scan advanced not past end of line
                Log()  +:=  error message(s)
                raise SyntaxError ]
        '''
        #-- 1 --
        # [ if the line in scan has at least L_RANK_CODE characters ->
        #     scan  :=  scan advanced L_RANK_CODE
        #     rankCode  :=  those characters, stripped
        #   else ->
        #     scan  :=  scan advanced no further than end of line
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        try:
            rankCode = scan.move ( L_RANK_CODE ).strip()
        except IndexError:
            scan.syntax ( "Expecting the rank code field." )

        #-- 2 --
        # [ if rankCode == '' ->
        #     self.rank  :=  None
        #   else if rankCode is a valid rank code in hier ->
        #     self.rank  :=  corresponding Rank object from hier
        #   else ->
        #     scan  :=  scan advanced no further than end of line
        #     raise KeyError ]
        if rankCode == '':
            self.rank = None
        else:
            self.rank = hier.lookupRankCode ( rankCode )