Created
October 26, 2021 09:57
-
-
Save Lerking/f08899dd733a1452502f2ed0395144c7 to your computer and use it in GitHub Desktop.
Regex demo for converting c header to asm inc file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| TOKENS = {"EXT_FUNC": "extern"} | |
| function_extern = re.compile(r'^[\D+\s+]+[a-zA-Z]+[\s+|\(\w\W\)]+;|\s+[\D+]') | |
| t = "void somefunction(p,p);" | |
| t1 = "GType gtk_widget_get_type (void) G_GNUC_CONST;" | |
| def external_func(txt): | |
| x = re.search(function_extern, txt) | |
| print(x.group()) | |
| if x is not None: | |
| tmp = [] | |
| l = [x for x in re.split(r"\s|\(", x.group()) if x != ""] | |
| print(l) | |
| tmp.append("EXT_FUNC") | |
| tmp.append(l[1]) | |
| return tmp | |
| else: | |
| return None | |
| parse = [] | |
| parse.append(external_func(t)) | |
| parse.append(external_func(t1)) | |
| print(parse) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment