stsewd / tree-sitter-rst

reStructuredText grammar for tree-sitter
https://stsewd.dev/tree-sitter-rst/
MIT License
50 stars 7 forks source link

Include whitespace nodes ? #17

Closed Carreau closed 2 years ago

Carreau commented 2 years ago

This is more of a question about design and usability of API than a bug per se I I belive I can completely get the information I need from the current API, and it may be a dumb question as I'm not that familiar with tree sitter.

Would be it easy/possible to get whitespace nodes when parsing it would be easier to ignore them than to reconstruct them.

The reason is when parsing something like

"Element-wise maximum of two *arrays*" and see that one get 6 Node kind="text", to "".join(...) to get the text back. Though there is no spaces betweenElement, - and wise. Of course I can just iterate and check if start_point and end_point, but I though maybe it was easy to do in tree-sitter-rst, in particular as I don't believe the end user is suppose to create Node objects.

stsewd commented 2 years ago

A time ago I saw a similar question on the tree-sitter repo https://github.com/tree-sitter/tree-sitter/issues/497. And as far as I know, no other grammars have whitespace nodes.

Carreau commented 2 years ago

Ok, thanks for the pointer, so it seem like it's a no from what I can tell.

I wrote my own wrapper/proxy around the node class that is a drop-in replacement but insert whitespace nodes when iterating on children. Feel free to close.