def split_text(self, text):
    'Split input template text into directives and raw text chunks.'
    tokens = []
    line = 1
    style = self.style[(- 1)]

    def make_splitter(delims):
        return re.compile(('(?s)(.*?)%s(.*?)%s' % delims))
    splitter = make_splitter((style['START_TAG'], style['END_TAG']))
    while True:
        match = splitter.match(text)
        if (not match):
            break
        text = text[match.end():]
        (pre, dir) = (match.group(1), match.group(2))
        prelines = pre.count('\n')
        dirlines = dir.count('\n')
        postlines = 0
        if dir.startswith('#'):
            match = re.search((CHOMP_FLAGS + '$'), dir)
            if match:
                dir = match.group()
            else:
                dir = ''
        else:
            match = re.match(('(%s)?\\s*' % CHOMP_FLAGS), dir)
            chomp = Chomp(((match and match.group(1)) or style['PRE_CHOMP']))
            if match:
                dir = dir[match.end():]
            pre = PRE_CHOMP[chomp](pre)
        match = re.search(('\\s*(%s)?\\s*$' % CHOMP_FLAGS), dir)
        chomp = Chomp(((match and match.group(1)) or style['POST_CHOMP']))
        if match:
            dir = dir[:match.start()]
        (text, postlines) = POST_CHOMP[chomp](text, postlines)
        if pre:
            if style['INTERPOLATE']:
                tokens.append([pre, line, 'ITEXT'])
            else:
                tokens.extend(['TEXT', pre])
        line += prelines
        if dir:
            match = re.match('(?i)TAGS\\s+(.*)', dir)
            if match:
                tags = re.split('\\s+', match.group(1))
                if (len(tags) > 1):
                    splitter = make_splitter(tuple((re.escape(x) for x in tags[:2])))
                elif (tags[0] in TAG_STYLE):
                    splitter = make_splitter(TAG_STYLE[tags[0]])
                else:
                    sys.stderr.write(('Invalid TAGS style: %s' % tags[0]))
            else:
                if (dirlines > 0):
                    line_range = ('%d-%d' % (line, (line + dirlines)))
                else:
                    line_range = str(line)
                tokens.append([dir, line_range, self.tokenise_directive(dir)])
        line += (dirlines + postlines)
    if text:
        if style['INTERPOLATE']:
            tokens.append([text, line, 'ITEXT'])
        else:
            tokens.extend(['TEXT', text])
    return tokens
Split input template text into directives and raw text chunks.
def split_text(self, text):
    
    tokens = []
    line = 1
    style = self.style[(- 1)]

    def make_splitter(delims):
        return re.compile(('(?s)(.*?)%s(.*?)%s' % delims))
    splitter = make_splitter((style['START_TAG'], style['END_TAG']))
    while True:
        match = splitter.match(text)
        if (not match):
            break
        text = text[match.end():]
        (pre, dir) = (match.group(1), match.group(2))
        prelines = pre.count('\n')
        dirlines = dir.count('\n')
        postlines = 0
        if dir.startswith('#'):
            match = re.search((CHOMP_FLAGS + '$'), dir)
            if match:
                dir = match.group()
            else:
                dir = 
        else:
            match = re.match(('(%s)?\\s*' % CHOMP_FLAGS), dir)
            chomp = Chomp(((match and match.group(1)) or style['PRE_CHOMP']))
            if match:
                dir = dir[match.end():]
            pre = PRE_CHOMP[chomp](pre)
        match = re.search(('\\s*(%s)?\\s*$' % CHOMP_FLAGS), dir)
        chomp = Chomp(((match and match.group(1)) or style['POST_CHOMP']))
        if match:
            dir = dir[:match.start()]
        (text, postlines) = POST_CHOMP[chomp](text, postlines)
        if pre:
            if style['INTERPOLATE']:
                tokens.append([pre, line, 'ITEXT'])
            else:
                tokens.extend(['TEXT', pre])
        line += prelines
        if dir:
            match = re.match('(?i)TAGS\\s+(.*)', dir)
            if match:
                tags = re.split('\\s+', match.group(1))
                if (len(tags) > 1):
                    splitter = make_splitter(tuple((re.escape(x) for x in tags[:2])))
                elif (tags[0] in TAG_STYLE):
                    splitter = make_splitter(TAG_STYLE[tags[0]])
                else:
                    sys.stderr.write(('Invalid TAGS style: %s' % tags[0]))
            else:
                if (dirlines > 0):
                    line_range = ('%d-%d' % (line, (line + dirlines)))
                else:
                    line_range = str(line)
                tokens.append([dir, line_range, self.tokenise_directive(dir)])
        line += (dirlines + postlines)
    if text:
        if style['INTERPOLATE']:
            tokens.append([text, line, 'ITEXT'])
        else:
            tokens.extend(['TEXT', text])
    return tokens