Next / Previous / Contents / Shipman's homepage

20.4. InputFile.__readLine(): Process one input line

# - - -   I n p u t F i l e . _ _ r e a d L i n e

    def __readLine(self, rawLine):
        '''Break one input line into OutBlock instances.

          [ rawLine is a nonempty string ->
              self.__blockList  +:=  OutBlock instances representing
                  rawLine with tabs expanded, with each line
                  represented as a FirstBlock
                  followed by zero or more OverflowBlock
                  instances ]              

We maintain a count of the input lines in self.nInLines.

        #-- 1
        self.nInLines += 1

Before we start changing the line's contents, we check to see if it starts with the break string.

        #-- 2
        # [ if rawLine starts with Args().breakString ->
        #     goodBreak  :=  True
        #   else ->
        #     goodBreak  :=  False ]
        goodBreak = rawLine.startswith(Args().breakString)

Section 20.5, “InputFile.__trimLine(): Implement length changes” can modify the content of the line. The length of the returned value is the output length: each character will occupy one character's width in the output.

        #-- 3
        # [ trimmedLine  :=  rawLine with any changes made to it,
        #       as specified by Args(), that change its length,
        #       and trailing whitespace removed if present ]
        trimmedLine = self.__trimLine(rawLine)

Now that we know the output length, we can slice the input line into pieces for output; see Section 20.6, “InputFile.__sliceLine(): Cut an input line into output lines”.

        #-- 4
        # [ self.__blockList  +:=  (a new FirstBlock instance with
        #       goodBreak=(goodBreak) made from trimmedLine up to
        #       size self.bodyLayout.charsPerCol) + (zero or more
        #       OverflowBlock instances representing the
        #       remainder of trimmedLine sliced into pieces of
        #       size self.bodyLayout.charsPerOver) ]
        self.__sliceLine(trimmedLine, goodBreak)