Next / Previous / Contents / Shipman's homepage

21. class Maps2004Compiler: Compiler for MAPS 2004 protocol

Compared to the MAPS 2006 protocol, compiling the MAPS 2004 protocol has these differences:

Inheritance handles both these variations. We use the inherited mechanism until the scanEncounter() method, at which point we replace that method with that instantiates a Maps2004Encounter record instead of the inherited Maps2006Encounter record. The Maps2004Encounter class takes care of both the differences in input scanning, and the different output format.

baseclasses.py
# - - - - -   c l a s s   M a p s 2 0 0 4 C o m p i l e r   - - - - -

class Maps2004Compiler(Maps2006Compiler):
    '''Compiler logic for the MAPS 2004 protocol.

      Exports:  As inherited.
    '''

21.1. Maps2004Compiler.scanEncounter()

This method is identical to the same method in Maps2006Compiler except that it uses the Maps2004Encounter class instead of the Maps2006Encounter class.

baseclasses.py
# - - -   M a p s 2 0 0 4 C o m p i l e r . s c a n E n c o u n t e r

    def scanEncounter(self):
        '''Process an encounter line.
        '''

See Section 76, “class Maps2004Encounter and Section 74.6, “BaseEncounter.scanLine(): Scan a raw encounter record”.

baseclasses.py
        #-- 1 --
        # [ if the line in self.scan is a valid MAPS 2004
        #   encounter line ->
        #     self.oldEncounter  :=  a Maps2004Encounter object
        #                            representing that record
        #     yield that Maps2004Encounter object
        #   else ->
        #     Log()  +:=  error message(s) ]
        try:
            encounter = Maps2004Encounter.scanLine(self, self.scan)
            self.oldEncounter = encounter
            yield encounter
            
        except SyntaxError:
            pass

        #-- 2 --
        raise StopIteration