Skip to content

Instantly share code, notes, and snippets.

@Lerking
Created October 26, 2021 09:57
Show Gist options
  • Select an option

  • Save Lerking/f08899dd733a1452502f2ed0395144c7 to your computer and use it in GitHub Desktop.

Select an option

Save Lerking/f08899dd733a1452502f2ed0395144c7 to your computer and use it in GitHub Desktop.
Regex demo for converting c header to asm inc file
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