Next / Previous / Contents / Shipman's homepage

42. Scan.tabReMatch(): Match and advance the position

logscan.py
# - - -   S c a n . t a b R e M a t c h

    def tabReMatch(self, r):
        '''If the text at self.pos matches, advance
        '''
        #-- 1 --
        # [ if (r is a string) and (regex (r) matches self.line
        #   starting at self.pos ->
        #       m  :=  a MatchObject representing that match
        #   else if compiled regex (r) matches self.line starting
        #   at self.pos ->
        #       m  :=  a MatchObject representing that match
        #   else ->
        #       m  :=  None ]
        m = self.reMatch(r)

        #-- 2 --
        # [ if m is not None ->
        #       self.pos  +:=  length of matched string in m ]
        if m is not None:
            self.pos += (m.end() - m.start())

        #-- 3 --
        return m