Next / Previous / Contents / Shipman's homepage

33. class BandNoSuffix: Short band number

This class is derived from class BandNoField. It handles parsing of a band number suffix, as found in new-band, destroyed band, and lost band encounter records.
# - - - - -   c l a s s   B a n d N o S u f f i x   - - - - -

class BandNoSuffix(BandNoField):
    '''Represents a band number specified as just a suffix.

      Exports (other than those inherited from BandNoField):
        BandNoSuffix.scanField(encounter, scan, fieldName): # Static
          [ (encounter is a BaseEncounter object) and
            (scan is a Scan object) and
            (fieldName is a field name in self.OUT_FIELD_LIST) ->
              if scan starts with a valid band number suffix in
              the context of encounter ->
                scan  :=  scan advanced past that field
                encounter.(fieldName)  :=  a BandNoField representing
                    that suffix joined with encounter.compiler.prefix
              else ->
                scan   :=   scan advanced no further than end of line
                Log()  +:=  error message(s)
                raise SyntaxError ]

Note that the value stored in the encounter record is the full band number. We obtain the prefix from the encounter record's .compiler.prefix attribute.

33.1. BandNoSuffix.scanField()

This method scans a band number suffix, joins it with the prefix from the BaseCompiler object, and stores a full BandNoField object in the BaseEncounter object. The intended function follows the generic model given in Section 26, “class FieldItem: Base class for encounter record fields”.
# - - -   B a n d N o S u f f i x . s c a n F i e l d   - - -  Static

    BAND_SUFFIX_PAT = re.compile(r'[ 0-9a-zA-Z?]{2}')

    def scanField(encounter, scan, fieldName):
        '''Scan a band number suffix field.

        #-- 1 --
        # [ if scan starts with BandNoSuffix.BAND_SUFFIX_PAT ->
        #     scan    :=  scan advanced past that pattern
        #     suffix  :=  characters that matched, uppercased
        #   else ->
        #     Log()  +:=  error message
        #     raise SyntaxError ]
        m = scan.tabReMatch(BandNoSuffix.BAND_SUFFIX_PAT)
        if  m is None:
            scan.syntax("Expecting a 2-digit band number suffix.")
            suffix =

Now we need to try to join the suffix to the prefix. There had better be a prefix line in effect.
        #-- 2 --
        # [ if encounter.compiler.prefix is None ->
        #     Log()  +:=  error message
        #     raise SyntaxError
        #   else -> I ]
        if  encounter.compiler.prefix is None:
            scan.syntax("There is no band string prefix line "
                        "currently in effect.")

Next we use a static method from the BandNoField class to join the prefix and suffix. See Section 32.6, “BandNoField.attachSuffix(): Join a band prefix and suffix”.
        #-- 3 --
        # [ encounter.(fieldName)  :=  a BandNoField object representing 
        #       self.compiler.prefix.text + suffix, allowing for
        #       rollover in the 00 case ]
        finalBandNo = BandNoField.attachSuffix(encounter,
            encounter.compiler.prefix.text, suffix)
        setattr(encounter, fieldName, finalBandNo)