def parse_definition_tokens(tokens, symbols): typedeffed = False simple_typedefs = [] structs = [] enums = [] functions = [] imports = [] usage = [] i = 0 while i < len(tokens): # skip comments if tokens[i] == "//": while tokens[i] != "\n" and i < len(tokens): i += 1 i += 1 continue elif tokens[i] == "#include": imports.append(tokens[i + 1]) i += 2 elif tokens[i] == "typedef": if tokens[i + 1] in symbols: simple_typedefs.append(tokens[i + 2]) i += 2 elif tokens[i] == "struct": i += 1 defs = [] depth = 0 while i < len(tokens): if tokens[i] == "//": while tokens[i] != "\n": i += 1 i += 1 continue if tokens[i] == ";": if depth == 0: break if tokens[i] == "{": depth += 1 if tokens[i] == "}": depth -= 1 defs.append(tokens[i]) i += 1 structs.append(defs) elif tokens[i] == "enum": i += 1 defs = [] depth = 0 while True: if tokens[i] == "//": while tokens[i] != "\n": i += 1 i += 1 continue if tokens[i] == ";": if depth == 0: break if tokens[i] == "{": depth += 1 if tokens[i] == "}": depth -= 1 defs.append(tokens[i]) i += 1 enums.append(defs) elif tokens[i] == "(": functions.append(tokens[i - 1]) while tokens[i] != ")": i += 1 i += 1 else: usage.append(tokens[i]) i += 1 print(structs, enums, functions, simple_typedefs, imports) return structs, enums, functions, simple_typedefs, imports, usage