arxlang / astx

https://astx.arxlang.org/
Other
1 stars 4 forks source link

feat: add ascii repr in the console #52

Closed apkrelling closed 5 months ago

apkrelling commented 8 months ago

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 notebook

Pull Request checklists

This PR is a:

About this PR:

Author's checklist:

Additional information

png visualization:

Screenshot from 2024-03-06 11-40-39

ascii visualization:

ascii_ast

Reviewer'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 .
review-notebook-app[bot] commented 8 months ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

apkrelling commented 7 months ago

Hey @xmnlab , I've made the changes we discussed:

apkrelling commented 5 months ago

Reopening the pull request.

apkrelling commented 5 months ago

Changes:

How to test these changes:

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

Pull Request checklists

This PR is a:

About this PR:

Author's checklist:

Additional information

ascii visualization:

Screenshot from 2024-05-13 13-47-18

Reviewer'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 .
apkrelling commented 5 months ago

@xmnlab , here's an update:

How to test these changes:

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)
github-actions[bot] commented 5 months ago

:tada: This PR is included in version 0.13.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: