def compiled(template, delimiters=DEFAULT_DELIMITERS):
re_tag = delimiters_to_re(delimiters)<EOL>tokens = []<EOL>index = <NUM_LIT:0><EOL>sections = []<EOL>tokens_stack = []<EOL>root = Root('<STR_LIT:root>')<EOL>root.filters = copy.copy(filters)<EOL>m = re_tag.search(template, index)<EOL>while m is not None:<EOL><INDENT>token = None<EOL>last_literal = None<EOL>strip_space = False<EOL>if m.start() > index:<EOL><INDENT>last_literal = Literal('<STR_LIT:str>', template[index:m.start()], root=root)<EOL>tokens.append(last_literal)<EOL><DEDENT>prefix, name, suffix = m.groups()<EOL>if prefix == '<STR_LIT:=>' and suffix == '<STR_LIT:=>':<EOL><INDENT>delimiters = re.split(r'<STR_LIT>', name)<EOL>if len(delimiters) != <NUM_LIT:2>:<EOL><INDENT>raise SyntaxError('<STR_LIT>' + m.group())<EOL><DEDENT>re_tag = delimiters_to_re(delimiters)<EOL>strip_space = True<EOL><DEDENT>elif prefix == '<STR_LIT:{>' and suffix == '<STR_LIT:}>':<EOL><INDENT>token = Variable(name, name, root=root)<EOL><DEDENT>elif prefix == '<STR_LIT>' and suffix == '<STR_LIT>':<EOL><INDENT>token = Variable(name, name, root=root)<EOL>token.escape = True<EOL><DEDENT>elif suffix != '<STR_LIT>' and suffix != None:<EOL><INDENT>raise SyntaxError('<STR_LIT>' + m.group())<EOL><DEDENT>elif prefix == '<STR_LIT:&>':<EOL><INDENT>token = Variable(name, name, root=root)<EOL><DEDENT>elif prefix == '<STR_LIT:!>':<EOL><INDENT>token = Comment(name, root=root)<EOL>if len(sections) <= <NUM_LIT:0>:<EOL><INDENT>strip_space = True<EOL><DEDENT><DEDENT>elif prefix == '<STR_LIT:>>':<EOL><INDENT>token = Partial(name, name, root=root)<EOL>strip_space = True<EOL>pos = is_standalone(template, m.start(), m.end())<EOL>if pos:<EOL><INDENT>token.indent = len(template[pos[<NUM_LIT:0>]:m.start()])<EOL><DEDENT><DEDENT>elif prefix == '<STR_LIT:#>' or prefix == '<STR_LIT>':<EOL><INDENT>sec_name = name.split('<STR_LIT:|>')[<NUM_LIT:0>].strip()<EOL>token = Section(sec_name, name, root=root) if prefix == '<STR_LIT:#>' else Inverted(name, name, root=root)<EOL>token.delimiter = delimiters<EOL>tokens.append(token)<EOL>token = None<EOL>tokens_stack.append(tokens)<EOL>tokens = []<EOL>sections.append((sec_name, prefix, m.end()))<EOL>strip_space = True<EOL><DEDENT>elif prefix == '<STR_LIT:/>':<EOL><INDENT>tag_name, sec_type, text_end = sections.pop()<EOL>if tag_name != name:<EOL><INDENT>raise SyntaxError("<STR_LIT>" + tag_name + "<STR_LIT>" + m.group())<EOL><DEDENT>children = tokens<EOL>tokens = tokens_stack.pop()<EOL>tokens[-<NUM_LIT:1>].text = template[text_end:m.start()]<EOL>tokens[-<NUM_LIT:1>].children = children<EOL>strip_space = True<EOL><DEDENT>else:<EOL><INDENT>raise SyntaxError('<STR_LIT>' + m.group())<EOL><DEDENT>if token is not None:<EOL><INDENT>tokens.append(token)<EOL><DEDENT>index = m.end()<EOL>if strip_space:<EOL><INDENT>pos = is_standalone(template, m.start(), m.end())<EOL>if pos:<EOL><INDENT>index = pos[<NUM_LIT:1>]<EOL>if last_literal: last_literal.value = last_literal.value.rstrip(spaces_not_newline)<EOL><DEDENT><DEDENT>m = re_tag.search(template, index)<EOL><DEDENT>tokens.append(Literal('<STR_LIT:str>', template[index:]))<EOL>root.children = tokens<EOL>return root<EOL>
Compile a template into token tree

    :template: TODO
    :delimiters: TODO
    :returns: the root token