Next / Previous / Contents / Shipman's homepage

20.8. InputFile.__genChunks(): Bracket the chunks separated by break strings

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

    def __genChunks(self):
        '''Find the chunks of lines separated by break strings.

          [ generate a sequence of index pairs (first, last) that
            bracket the regions of self.__blockList consisting
            of one OutBlock with .goodBreak set followed by
            zero or more OutBlock instances with .goodBreak
            reset, such that first is the index of the first
            block and last is the index of the last+1 block ]
        #-- 1
        first = 0

        #-- 2
        for linex, block in enumerate(self.__blockList):
            if block.goodBreak and linex>0:
                yield (first, linex)
                first = linex

Finally, generate one pair that brackets the leftover chunk after the last break string.

        #-- 3
        yield (first, len(self.__blockList))