Zig AST explorer

Hello all,

I was poking about writing a linter between projects for personal use when I get even more distracted (linter was already a distraction) by the idea of packaging zigs AST parser into a static website to explore what the tokeniser and parser were producing

Zlinter - Zig AST explorer (currently targeting 0.14.1 - also builds for master on a different branch but I’m not sure how to deploy both through GitHub Actions so sticking with 0.14.x as it’s more stable)

It’s plain JS and CSS (no bundling or polyfills or whatever web devs do these days) so mileage may vary on some browsers (I’ve only tested on desktop)

Maybe once Zig is stable I will upstream something to the astexplorer.net project, OR maybe it’s not that useful and was more of a recreational programming exercise, which is also fine by me

I will probably update it to provide more interpreted context about the nodes instead of the raw data… unless I get distracted by something else… :upside_down_face:

14 Likes

I noticed one minor thing, not sure if it is even noteworthy or worth any effort to “fix”, but while it tokenizes standard doc comments ///, file-level documentation with //! doesn’t seem to be included.

But either way, very neat, and thanks for sharing!

1 Like

Thanks for pointing this out!

This bug made me question whether all nodes (like tokens for comments) were being visited when walking the tree, and I think this catches another bug - fn_ proto_* aren’t included under fn_decl, which looks like a bug in ZLS where fn_decl is being treated like a proto, instead of first walking the .fn_decl and then the fn_proto_* in data.lhs/node_and_node.@"0"

It looks simple enough to fix, assuming this isn’t by design. I’ll take a better look tomorrow.

1 Like