def to_type(self, tokens):
result = []<EOL>name_tokens = []<EOL>reference = pointer = array = False<EOL>inside_array = False<EOL>empty_array = True<EOL>templated_tokens = []<EOL>def add_type():<EOL><INDENT>if not name_tokens:<EOL><INDENT>return<EOL><DEDENT>names = []<EOL>modifiers = []<EOL>for t in name_tokens:<EOL><INDENT>if keywords.is_keyword(t.name):<EOL><INDENT>modifiers.append(t.name)<EOL><DEDENT>else:<EOL><INDENT>names.append(t.name)<EOL><DEDENT><DEDENT>name = '<STR_LIT>'.join(names)<EOL>templated_types = self.to_type(templated_tokens)<EOL>result.append(Type(name_tokens[<NUM_LIT:0>].start, name_tokens[-<NUM_LIT:1>].end,<EOL>name, templated_types, modifiers,<EOL>reference, pointer, array))<EOL>del name_tokens[:]<EOL>del templated_tokens[:]<EOL><DEDENT>i = <NUM_LIT:0><EOL>end = len(tokens)<EOL>while i < end:<EOL><INDENT>token = tokens[i]<EOL>if token.name == '<STR_LIT:]>':<EOL><INDENT>inside_array = False<EOL>if empty_array:<EOL><INDENT>pointer = True<EOL><DEDENT>else:<EOL><INDENT>array = True<EOL><DEDENT><DEDENT>elif inside_array:<EOL><INDENT>empty_array = False<EOL><DEDENT>elif token.name == '<STR_LIT:<>':<EOL><INDENT>templated_tokens, i = self._get_template_end(tokens, i + <NUM_LIT:1>)<EOL>continue<EOL><DEDENT>elif token.name == '<STR_LIT:U+002C>' or token.name == '<STR_LIT:(>':<EOL><INDENT>add_type()<EOL>reference = pointer = array = False<EOL>empty_array = True<EOL><DEDENT>elif token.name == '<STR_LIT:*>':<EOL><INDENT>pointer = True<EOL><DEDENT>elif token.name == '<STR_LIT:&>':<EOL><INDENT>reference = True<EOL><DEDENT>elif token.name == '<STR_LIT:[>':<EOL><INDENT>inside_array = True<EOL><DEDENT>elif token.name != '<STR_LIT:)>':<EOL><INDENT>name_tokens.append(token)<EOL><DEDENT>i += <NUM_LIT:1><EOL><DEDENT>add_type()<EOL>return result<EOL>
Convert [Token,...] to [Class(...), ] useful for base classes.

        For example, code like class Foo : public Bar<x, y> { ... };
        the "Bar<x, y>" portion gets converted to an AST.

        Returns:
          [Class(...), ...]