Closed apkrelling closed 5 months ago
Check out this pull request on
See visual diffs & provide feedback on Jupyter Notebooks.
Powered by ReviewNB
Hey @xmnlab , I've made the changes we discussed:
from __future__ import annotations
and from typing import Any
Reopening the pull request.
traverse_ast
func now is suitable for both list and dict ASTsgraph_to_ascii
func to be able to deal with repeated node names.from astx.viz import traverse_ast, visualize, graph_to_ascii
import astx
block = astx.Block()
decl_a = astx.VariableDeclaration("a", type_=astx.Int32, value=astx.LiteralInt32(1))
decl_b = astx.VariableDeclaration("b", type_=astx.Int32, value=astx.LiteralInt32(1))
var_a = astx.Variable("a")
var_b = astx.Variable("b")
sum_op = astx.BinaryOp(op_code="+", lhs=var_a, rhs=var_b)
block.append(decl_a)
block.append(decl_b)
block.append(sum_op)
visualize(block.get_struct(simplified=True)) # png viz
graph = traverse_ast(block.get_struct(simplified=True))
graph = graph_to_ascii(graph) # ascii viz
This PR is a:
About this PR:
Author's checklist:
Copy and paste this template for your review's note:
## Reviewer's Checklist
- [ ] I managed to reproduce the problem locally from the `main` branch
- [ ] I managed to test the new changes locally
- [ ] I confirm that the issues mentioned were fixed/resolved .
@xmnlab , here's an update:
asciinet
and msgpack
to poetry
traverse_ast
into traverse_ast_ascii
and traverse_ast_png
graph_to_ascii
func in https://github.com/arxlang/astx/blob/main/src/astx/base.py#L161graph_to_ascii_overload
from None
to str
.from astx.viz import traverse_ast, visualize, graph_to_ascii
import astx
block = astx.Block()
decl_a = astx.VariableDeclaration("a", type_=astx.Int32, value=astx.LiteralInt32(1))
decl_b = astx.VariableDeclaration("b", type_=astx.Int32, value=astx.LiteralInt32(1))
var_a = astx.Variable("a")
var_b = astx.Variable("b")
sum_op = astx.BinaryOp(op_code="+", lhs=var_a, rhs=var_b)
block.append(decl_a)
block.append(decl_b)
block.append(sum_op)
visualize(block.get_struct(simplified=True)) # png viz
dot_graph = traverse_ast(block.get_struct(simplified=True))
graph = graph_to_ascii(dot_graph) # ascii viz
print(graph)
:tada: This PR is included in version 0.13.0 :tada:
The release is available on:
0.13.0
Your semantic-release bot :package::rocket:
Pull Request description
Add basic ascii AST visualization function and quick example.
This aims to help solve #22 .
How to test these changes:
run the
docs/tutorials/ascii_ast_example.ipynb
notebookPull Request checklists
This PR is a:
About this PR:
Author's checklist:
Additional information
png visualization:
ascii visualization:
Reviewer's checklist
Copy and paste this template for your review's note: