Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AST Visualisation #14

Open
rmhsilva opened this issue Aug 11, 2020 · 5 comments
Open

AST Visualisation #14

rmhsilva opened this issue Aug 11, 2020 · 5 comments

Comments

@rmhsilva
Copy link
Contributor

It'd be great to be able to visualise the result of parsing -- the AST. This could be triggered with a new CLI command, e.g. teal ast file.tl.

One approach: generate some graphviz based on the Node structure. See parser.py and nodes.py. Depends on the user having graphviz installed, so maybe a pure-python approach would be better!

@krrome
Copy link

krrome commented Aug 27, 2020

I'll work on this, but I'll use graphviz (pydot package) due to lack of alternatives.

@rmhsilva
Copy link
Contributor Author

Great! Sounds good, graphviz would be great for a first implementation.

@krrome
Copy link

krrome commented Aug 28, 2020

For the final version I have planned to:

  • Use similar symbols for similar node types + colouring
  • Maybe instead of creating a "Literal" node in the graph add it to the Argument node label

Not sure if I misunderstood things or maybe I found a bug during parsing / AST generation:

  • Often when attributes of nodes (defined in teal-lang/src/teal_lang/teal_parser/nodes.py) are list they are in fact used as if they were type Any since they at least sometimes contain just a node. E.g.: N_If.then is sometimes just a Node.

What do you think about this visualisation for the file teal-lang/examples/video/video.tl? In fact I'm not even sure if I am plotting the AST or the parse tree :D

video tl

@rmhsilva
Copy link
Contributor Author

rmhsilva commented Sep 3, 2020

Nice, looks great! Colouring and symbols will be super useful. A couple of thoughts

  • it'd be great to have event sources in the graph obvious. e.g., on_upload and on_http are special event-triggered functions, and their configuration is in hark.toml.
  • import statements can be shown as a single item, and therefore don't really need to be in the AST - filter them out.

The thought process guiding me: I want to be able to, at a glance, understand the key elements in my program. The inputs, events and functions (python and Hark) involved. Like, where data is coming from, which Python functions are using it, any constants, etc. If it helps me visualise data flow, even better. Sort of like we're building a pipeline data-flow visualisation (e.g. Airflow style - https://airflow.apache.org/docs/stable/ui.html).

@rmhsilva
Copy link
Contributor Author

rmhsilva commented Sep 4, 2020

Ah, and I missed your question about list vs Any. You're right, it looks like they're wrong type annotations. Created #20 for it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants