condense9 / hark-lang

A serverless virtual machine
https://guide.condense9.com
Apache License 2.0
108 stars 8 forks source link

AST Visualisation #14

Open rmhsilva opened 4 years ago

rmhsilva commented 4 years ago

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 commented 4 years ago

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

rmhsilva commented 4 years ago

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

krrome commented 4 years ago

For the final version I have planned to:

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

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 commented 4 years ago

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

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 commented 4 years ago

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!