Next / Previous / Contents / Shipman's homepage

20.11. InputFile.__genCols(): Find the columns in the block list

# - - -   I n p u t F i l e . _ _ g e n C o l s

    def __genCols(self):
        '''Generate pairs of indices bracketing columns in self.

          [ self.__blockList is as invariant ->
              generate a sequence of tuples (fromx, tox) such that
              each tuple brackets one column in self.__blockList ]
        #-- 1
        startx = 0
        nBlocks = len(self.__blockList)

First generate all blocks but the last. The startx variable keeps track of the end of the previous block. The last column is a special case because there is no following block that is marked as a break.

        #-- 2
        # [ startx  :=  index of the first block in the last column
        #       of self.__blockList
        #   generate tuples (fromx, tox) such that each tuple brackets
        #   a column in self.__blockList except the last ]
        for blox in range(nBlocks):
            if self.__blockList[blox].isBreak():
                yield (startx, blox)
                startx = blox

        #-- 3
        yield (startx, nBlocks)

        #-- 4
        raise StopIteration