More wip stuff

This commit is contained in:
IQuant 2024-11-24 20:47:58 +03:00
parent a830e0f33c
commit c7b389a389
4 changed files with 7660 additions and 18 deletions

View file

@ -8,15 +8,36 @@ lines_iter = iter(lines)
parsed = []
def maybe_map_types(name, typ):
if name == "entity_id":
typ = "entity_id"
if name == "component_id":
typ = "component_id"
if typ == "float":
typ = "number"
if typ == "uint":
typ = "color"
if typ == "uint32":
typ = "color"
return typ
def parse_arg(arg_s):
if "|" in arg_s:
raise ValueError("multiple argument types not supported")
other, *default = arg_s.split(" = ", maxsplit=1)
if "{" in arg_s:
raise ValueError("no table support for now")
if "multiple_types" in arg_s:
raise ValueError("no 'multiple_types' either")
other, *default = arg_s.split("=", maxsplit=1)
other = other.strip()
if default:
default = default[0]
default = default[0].strip()
else:
default = None
name, typ = other.split(":", maxsplit=1)
typ = maybe_map_types(name, typ)
return {
"name": name,
"typ": typ,
@ -34,14 +55,15 @@ def parse_ret(ret_s):
raise ValueError("multiple return types not supported")
if "{" in ret_s:
raise ValueError("tables in returns not supported")
if "multiple_types" in ret_s:
raise ValueError("no 'multiple_types' either")
typ = other
typ = ret_s
name = None
if ":" in other:
name, typ = other.split(":", maxsplit=1)
if ":" in ret_s:
name, typ = ret_s.split(":", maxsplit=1)
if name == "entity_id":
typ = "entity_id"
typ = maybe_map_types(name, typ)
return {
"name": name,
@ -51,9 +73,11 @@ def parse_ret(ret_s):
ignore = {
"PhysicsApplyForceOnArea",
"GetRandomActionWithType",
}
skipped = 0
deprecated = 0
# 2 lazy 2 parse xml properly
try:
@ -63,7 +87,7 @@ try:
fn_line = line.strip()
ret_line = next(lines_iter).strip()
desc_line = next(lines_iter).strip()
fn_name, other = fn_line.removeprefix('<th><span class="function">').split('</span>(<span class="field_name">', maxsplit=1)
args = other.removesuffix('</span><span class="func">)</span></th>').strip().split(", ")
try:
@ -73,17 +97,28 @@ try:
print(f"Skipping {fn_name}: {e}")
continue
ret = ret_line.removeprefix('<th><span class="field_name">').removesuffix('</span></th></th>').strip()
rets = ret_line.removeprefix('<th><span class="field_name">').removesuffix('</span></th></th>').strip()
desc = desc_line.removeprefix('<th><span class="description">').removesuffix('</span></th></th>').strip().replace("</br>", "\n")
if "Debugish" in rets:
rets, desc = rets.split(" (", maxsplit=1)
desc = desc.removesuffix(")")
rets = rets.split(", ")
try:
ret = parse_ret(ret)
rets = [parse_ret(ret) for ret in rets if ret]
except ValueError as e:
print(f"Skipping {fn_name}: {e}")
skipped += 1
continue
desc = desc_line.removeprefix('<th><span class="description">').removesuffix('</span></th></th>').strip().replace("</br>", "\n")
if not desc:
desc = "Nolla forgot to include a description :("
if "Deprecated" in desc_line:
deprecated += 1
print(f"Skipping {fn_name}: deprecated")
continue
#print(fn_line, ret_line, desc_line)
if fn_name not in ignore:
@ -92,11 +127,15 @@ try:
"fn_name": fn_name,
"args": args,
"desc": desc,
"rets": rets
})
else:
skipped += 1
except StopIteration:
pass
print("Total skipped:", skipped)
json.dump(parsed, open("ewext/noita_api_macro/src/lua_api.json", "w"), indent=None)
print("Total skipped:", skipped, deprecated)
print("Total parsed:", len(parsed))
json.dump(parsed, open("ewext/noita_api_macro/src/lua_api.json", "w"), indent=2)