briot / tree-sitter-ada

Ada grammar for tree-sitter
MIT License
21 stars 5 forks source link

What is the rationale for "hiding" some rules? #3

Closed stephe-ada-guru closed 1 year ago

stephe-ada-guru commented 1 year ago

Similar to issue 2. Apparently hiding rules has some impact on runtime speed? Do we have any measurements of that?

If a rule is hidden, I assume it cannot be referenced in a query, so hiding some seems problematic. On the other hand, there are many rules that are not hidden that are not referenced from the queries in this repository.

briot commented 1 year ago

The reason for hiding rules is actually not performance (though it might possibly help a bit, I did not measure that). It is to keep the queries simpler (and because the tree-sitter documentation encourages grammars to come up with a concrete syntax tree where each node corresponds to a terminal or non-terminal symbol (https://tree-sitter.github.io/tree-sitter/creating-parsers#writing-the-grammar).

The choice of whether to hide a rule or not is mostly me looking at the output tree in the tests, and deciding that we do not need the extra level of nodes for instance. Redundant nodes were also found when implementing queries to move the cursor "one level up" for instance. If the action does nothing visually, that generally indicated that there was an unnecessary node in the tree. Those navigation actions are not "queries" directly, just navigating in the tree.

I am definitely open to making some rules visible if you find that necessary for the emacs ada-mode (since that could likely be useful to neovim as well -- let's discuss on a case-by-case basis)