'Returns the template string as a (type, value, indent) list,
where type is either <str>, <arg>, <if>, <for>, <eval> or <exec>.
With <eval> and <exec>, value is a compiled code object
that can be executed with eval() or exec() respectively.'

def _compile(self, string):

    a = []
    i = 0
    for m in _MARKUP.finditer(string):
        s = m.group(1)
        j = m.start(1)
        n = string[:j].count('\n')
        w = re.compile('(^|\\n)(.*?)$')
        w = re.search(w, string[:j])
        w = re.sub('[^\\t]', '    ', string[w.start(2):j])
        if (i != j):
            a.append(('<str>', string[i:j], ''))
        if (s.startswith('$') and (j > 0) and (string[(j - 1)] == '$')):
            a.append(('<str>', s, ''))
        elif (s.startswith('${') and s.endswith('}')):
            a.append(('<arg>', s[2:(-1)], w))
        elif s.startswith('$'):
            a.append(('<arg>', s[1:], w))
        elif (s.startswith('<%') and m.group(2)):
            a.append(('<if>', (m.group(2), self._compile(m.group(3).lstrip('\n'))), w))
        elif (s.startswith('<%') and m.group(4)):
            a.append(('<for>', (m.group(4), m.group(5), self._compile(m.group(6).lstrip('\n'))), w))
        elif (s.startswith('<%=') and s.endswith('%>')):
            a.append(('<eval>', compile((('\n' * n) + self._escape(s[3:(-2)])), '<string>', 'eval'), w))
        elif (s.startswith('<%') and s.endswith('%>')):
            a.append(('<exec>', compile((('\n' * n) + self._escape(s[2:(-2)])), '<string>', 'exec'), w))
        else:
            raise SyntaxError(("template    has    no    end    tag    for    '%s'    (line    %s)" % (s, (n + 1))))
        i = m.end(1)
    a.append(('<str>', string[i:], ''))
    return a
