def parse_definition_tokens(tokens, symbols): typedeffed = False simple_typedefs = [] structs = [] enums = [] functions = [] i = 0 while i < len(tokens): # skip comments if tokens[i] == "//": while tokens[i] != "\n": i += 1 i += 1 continue if tokens[i] == "typedef": if tokens[i + 1] in symbols: simple_typedefs.append(tokens[i + 2]) i += 2 if tokens[i] == "struct": 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 structs.append(defs) if 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) i += 1 if tokens[i] == "(": functions.append(tokens[i - 1]) return structs, enums, functions, simple_typedefs