Extend main for export
This commit is contained in:
@@ -100,8 +100,20 @@ if __name__ == "__main__":
|
||||
print("")
|
||||
pretty_print(ast)
|
||||
|
||||
# Show AST graph
|
||||
if prompt_yesno("Display AST diagram?"):
|
||||
# Export DOT
|
||||
dot_str = ast.to_dot()
|
||||
if prompt_yesno("Export AST as .dot file?"):
|
||||
default = f"{path.stem}.dot"
|
||||
out = input(f"Filename [{default}]: ").strip()
|
||||
if not out:
|
||||
out = default
|
||||
try:
|
||||
Path(out).write_text(dot_str, encoding="utf-8")
|
||||
print(f"Saved DOT file as: {out}")
|
||||
except Exception as e:
|
||||
print(f"Could not save DOT file: {e}")
|
||||
|
||||
# Display AST diagram
|
||||
if prompt_yesno("Display AST diagram?"):
|
||||
render_ast_from_string(dot_str)
|
||||
print("Rendered AST diagram.")
|
||||
@@ -16,7 +16,7 @@ reserved = {
|
||||
'false': 'FALSE'
|
||||
}
|
||||
|
||||
# List of token names. This is always requiredy
|
||||
# List of token names.
|
||||
tokens = [
|
||||
'ID',
|
||||
'CONST',
|
||||
|
||||
Reference in New Issue
Block a user