val:ty
This commit is contained in:
parent
744496e32e
commit
8f51231f5b
2 changed files with 13 additions and 5 deletions
13
aggen.py
13
aggen.py
|
@ -155,9 +155,16 @@ def gen(program: List[Decl]) -> GenResult:
|
|||
assert isinstance(node_desc, NodeDesc)
|
||||
res.starts.add(node_desc.nonterminal)
|
||||
|
||||
class_fields = []
|
||||
for field_name, field_ty in what_fields[node_desc.name].items():
|
||||
class_fields.append(f"{field_name}: Thunk[{field_ty}]")
|
||||
g = textwrap.indent("\n".join(class_fields), " ")
|
||||
|
||||
class_decl = textwrap.dedent(
|
||||
f"""
|
||||
class {node_desc.nonterminal}: pass
|
||||
class {node_desc.nonterminal}:
|
||||
{g}
|
||||
pass
|
||||
"""
|
||||
)
|
||||
res.extra += class_decl
|
||||
|
@ -168,9 +175,7 @@ def gen(program: List[Decl]) -> GenResult:
|
|||
v_class_name = gensym(f"{node_desc.nonterminal}_var")
|
||||
class_decl = textwrap.dedent(
|
||||
f"""
|
||||
class {v_class_name}({node_desc.nonterminal}):
|
||||
''' '''
|
||||
pass
|
||||
class {v_class_name}({node_desc.nonterminal}): pass
|
||||
"""
|
||||
)
|
||||
res.extra += class_decl
|
||||
|
|
|
@ -24,8 +24,11 @@ if __name__ == "__main__":
|
|||
|
||||
if not os.path.exists("gen"):
|
||||
os.makedirs("gen")
|
||||
|
||||
with open("agruntime.tmpl.py", "r") as f:
|
||||
fmt_str = f.read()
|
||||
|
||||
with open("gen/arith.py", "w") as f:
|
||||
fmt_str = open("agruntime.tmpl.py", "r").read()
|
||||
f.write(
|
||||
fmt_str.format(
|
||||
pd=res.parser_data,
|
||||
|
|
Loading…
Reference in a new issue