summaryrefslogtreecommitdiff
path: root/symbol_analyzer/extractor.py
diff options
context:
space:
mode:
Diffstat (limited to 'symbol_analyzer/extractor.py')
-rw-r--r--symbol_analyzer/extractor.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/symbol_analyzer/extractor.py b/symbol_analyzer/extractor.py
new file mode 100644
index 0000000..0e8694c
--- /dev/null
+++ b/symbol_analyzer/extractor.py
@@ -0,0 +1,56 @@
+def parse_file(file):
+ f = open(file)
+ contents = f.read()
+ f.close()
+
+ significant_token = ""
+ depth = 0
+ tokens = []
+ swallen_tokens = [0, 0]
+ token_buffer = ""
+ define_striping = False
+ for c in contents:
+ if c == " " or c == "{" or c == "}" or \
+ c == ";" or c == ":" or c == "[" or c == "]" or \
+ c == "(" or c == ")" or c == "," or c == "\n" or c == "*":
+
+ if significant_token == "":
+ if c == "{" or c == "}":
+ depth += 1 if c == "{" else -1
+ elif significant_token == "#define":
+ if tokens[-1] == ")":
+ define_striping = True
+ depth = 1
+ if swallen_tokens[-2] != "\\" and swallen_tokens[-1] == "\n":
+ significant_token = ""
+ define_striping = False
+ depth = 0
+ else:
+ depth = 0
+ if swallen_tokens[-1] == ";":
+ significant_token = ""
+
+ if depth == 0:
+ if len(token_buffer) > 0:
+ if token_buffer in ["#define", "enum", "struct"]:
+ significant_token = token_buffer
+ tokens.append(token_buffer)
+ if c != ' ' and len(c) > 0:
+ tokens.append(c)
+ else:
+ if len(token_buffer) > 0:
+ if token_buffer in ["#define", "enum", "struct"]:
+ significant_token = token_buffer
+ swallen_tokens.append(token_buffer)
+ if c != ' ' and len(c) > 0:
+ swallen_tokens.append(c)
+
+ token_buffer = ""
+ continue
+
+ token_buffer += c
+
+ if depth == 0 and len(token_buffer) > 0:
+ tokens.append(token_buffer)
+
+ return tokens, swallen_tokens