22 lines
417 B
Python
22 lines
417 B
Python
import textwrap
|
|
import os
|
|
from lark import Lark
|
|
|
|
p = Lark(open("grammar.lark").read())
|
|
|
|
if __name__ == "__main__":
|
|
with open("arith.ag") as f:
|
|
data = f.read()
|
|
|
|
t = p.parse(data)
|
|
print(t)
|
|
|
|
if not os.path.exists("gen"):
|
|
os.makedirs("gen")
|
|
with open("gen/arith.py", "w") as f:
|
|
f.write(textwrap.dedent("""
|
|
from typing import Generic, TypeVar
|
|
T = TypeVar('T')
|
|
class Thunk(Generic[T]):
|
|
pass
|
|
"""))
|