Next / Previous / Contents / Shipman's homepage

74.15. BaseEncounter.scanTailField(): Scan one free-form tail field

A tail field always starts with a TAIL_CUE_CHAR (apostrophe), followed by a character that identifies the field type, followed by more content whose format is specific to that field type (but never including another TAIL_CUE_CHAR).

baseclasses.py
# - - -   B a s e E n c o u n t e r . s c a n T a i l F i e l d   - - -

    def scanTailField(self, scan):
        '''Scan one free-form tail field.

          [ if scan starts with TAIL_CUE_CHAR followed by
            a valid tail field ->
              scan  :=  scan advanced past that field
              self  :=  self with data from that field stored
                        using field names in self.OUT_FIELD_NAMES
            else ->
              scan   :=   scan advanced no further than end of line
              Log()  +:=  error message(s)
              raise SyntaxError ]
        '''

        #-- 1 --
        # [ if scan starts with TAIL_CUE_CHAR ->
        #     scan  :=  scan advanced past that character
        #   else ->
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        m = scan.tabMatch(TAIL_CUE_CHAR)
        if  m is None:
            scan.syntax("Expecting the tail field cue character "
                        "(%s)." % TAIL_CUE_CHAR)

        #-- 2 --
        # [ if the line in scan has at least one character left ->
        #     scan       :=  scan advanced one
        #     fieldType  :=  next character from scan, uppercased
        #   else ->
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        try:
            fieldType = scan.move(1).upper()
        except IndexError:
            scan.syntax("Expecting a tail field type character.")

For the dictionary that maps tail code fields to the methods that process them, see Section 74.21, “BaseEncounter.tailDispatch: Tail field routing dictionary”.

baseclasses.py
        #-- 3 --
        # [ if fieldType is a key in self.tailDispatch ->
        #     tailMethod  :=  corresponding value
        #   else ->
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        try:
            tailMethod = self.tailDispatch [ fieldType ]
        except KeyError:
            validKeys = "".join(self.tailDispatch.keys())
            scan.syntax("Invalid tail field type code: expecting "
                         "one of '%s'." % validKeys)

At this point, tailMethod contains the method that processes the selected type of tail field. These methods must have intended functions that match the generic intended function given here:

baseclasses.py
        #-- 4 --
        # [ if scan starts with the data part of a field corresponding
        #   to tailMethod ->
        #     scan  :=  scan advanced past that data
        #     self  :=  self with the data from that field added
        #   else ->
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        tailMethod(self, scan)