summaryrefslogtreecommitdiff
path: root/symbol_analyzer/parser.py
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-07-10 23:12:04 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-07-10 23:12:04 +0530
commit2e8b78ab0ef01eaacd8094ff839ac93b4451e9c3 (patch)
tree35efbeb73f774513f711e0be6bfa5647033cee27 /symbol_analyzer/parser.py
parenta14da2fe3864712dab4e7c4cfb5c323026d668de (diff)
symbol analyzer init
Diffstat (limited to 'symbol_analyzer/parser.py')
-rw-r--r--symbol_analyzer/parser.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/symbol_analyzer/parser.py b/symbol_analyzer/parser.py
new file mode 100644
index 0000000..551857e
--- /dev/null
+++ b/symbol_analyzer/parser.py
@@ -0,0 +1,65 @@
+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