briot / tree-sitter-ada

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

Many field names are not used in queries #2

Closed stephe-ada-guru closed 1 year ago

stephe-ada-guru commented 1 year ago

I'm working on enhancing wisitoken to generate a tree-sitter grammar file from the wisitoken grammar file. I'm wondering about the tree-sitter field names; as I understand it, they are present so those names can be used in queries.

However, many of the field names defined in this tree-sitter grammar are not used in the queries in the queries directory (for example, 'prefix', 'condition'). What is the rationale for defining them? There must be some cost at run-time (it takes more memory, for one thing, possibly more time to search the tree), and there is a maintenance issue in the future. Both of these costs are pretty low.

stephe-ada-guru commented 1 year ago

One rationale is when there is a name in LRM Annex P syntax that is not in the grammar file, because it is a trivial production, such as parent_unit_name ::= name. In that case, we use 'name' in the grammar file, with a field name of 'parent_unit_name'.

briot commented 1 year ago

Hi Stephe,

I'd be interested to know why you want to generate another tree-sitter grammar from the wisitoken one, as opposed to reusing the one in this repository ? (better field testing would be one reason, of course). I did take inspiration from wisitoken grammar when I wrote the tree-sitter one, even if I ended up doing changes.

Mostly, the names in the grammar come either from the AARM itself, or sometimes from the wisitoken names if I remember right. The queries do not use them a lot, indeed, and we could chose to have different names if it helps (including sticking closer to the AARM, though sometimes the names in there lack consistency I find -- I cannot remember an example directly).

I am not sure how the performance cost. In practice, I have been using neovim with this tree-sitter grammar for quite a while now and haven't noticed any lag.