Created
June 1, 2022 12:58
-
-
Save mbednarski/d18f0c3b39f6d6e8a85c733485809592 to your computer and use it in GitHub Desktop.
This file contains 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
from pathlib import Path | |
import rich | |
import typer | |
from lark.tree import pydot__tree_to_png | |
from xdlang.pipeline import Parser | |
from xdlang.pipeline.ast_builder import AstBuilder | |
app = typer.Typer() | |
@app.command() | |
def build(): | |
pass | |
@app.command(help="Compiles and runs an xd program with a lot of debug info.") | |
def run(input_file: Path): | |
print("XD Compiler") | |
print(f"Compiling and running {input_file}") | |
parser = Parser() | |
with input_file.open("rt") as f: | |
tree = parser.parse_text(f.read()) | |
rich.print(tree) | |
pydot__tree_to_png(tree, str(input_file.with_suffix(".png")), rankdir="TB") | |
transformed = AstBuilder().transform(tree) | |
rich.print(transformed) | |
def main(): | |
app() | |
if __name__ == "__main__": | |
app() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment