Next / Previous / Contents / Shipman's homepage

16.5. Rank.__scanCode(): Scan the code field

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

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

          [ scan is a Scan instance ->
              if the line in scan starts with a valid code field ->
                scan  :=  scan advanced past that field
                self.code  :=  that code, blank-stripped
              else ->
                scan  :=  scan advanced no further than end of line
                Log()  +:=  error message(s)
                raise SyntaxError ]
        '''

For the length of the field, see Section 6.9, “L_RANK_CODE. Right blanks are trimmed.

nomcompile3
        #-- 1 --
        # [ if the line in scan has at least L_RANK_CODE
        #   characters ->
        #     scan  :=  scan advanced by L_RANK_CODE
        #     rawCode  :=  next L_RANK_CODE characters from scan
        #   else ->
        #     scan  :=  scan advanced no further than end of line
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        try:
            rawCode = scan.move ( L_RANK_CODE )
        except IndexError:
            scan.syntax ( "Expecting the %d-character rank code." %
                          L_RANK_CODE )

        #-- 2 --
        self.code = rawCode.strip()