Jakobeha / type-sitter

generate typed wrappers for tree-sitter grammars from node-types.json and queries
18 stars 2 forks source link

Generate an "all (named) nodes" supertype? #5

Closed wldmr closed 2 weeks ago

wldmr commented 3 weeks ago

When iterating over a file I find myself missing a supertype that encompasses all grammar elements (or at least the named ones). An example would be a formatter, where you'll want to make sure you don't miss any nodes (especially on a moving target, like the wldmr/tree-sitter-ink grammar that I'm developing.

So I've done the smallest change that solves my problem here. It basically just wedges in the three new supertypes in the NodeTypeMap::new() function.

I was thinking about maybe exposing an insert() method on NodeTypeMap and making parse_node_type_map() public, so users then could postprocess it themselves before writing it out. But that would mean making all of the innards public as well, so I wanted to consult you first.

My general question would be: Do you think this is something that you would want this library to offer, and if so, how?

I'm happy to implement this, if you're willing to help me along a bit (haven't fully grokked the code yet).

If not, do you think there's another/better way to get exhaustive (compile time) matching on all nodes?

Jakobeha commented 3 weeks ago

I think this is a good change. If you change the generated sexp_names to _all_named, _all_unnamed, and _all_nodes and submit a PR I'll merge.

I'm also fine with exposing more including NodeTypeMap, parse_node_type_map, and NodeType. How do you want to use public NodeTypeMap, and how do you imagine others would use it?

wldmr commented 3 weeks ago

Nice :). I've opened a PR and put a usage example in the comments. Let me know what you think, esp. if you see any potential problems with this.