tree-sitter icon indicating copy to clipboard operation
tree-sitter copied to clipboard

Aliasing to a Grammar Symbol without a Production Produces an AST without a Corresponding Node in node-types.json

Open berchn opened this issue 3 years ago • 2 comments

I've run into this issue recently in tree-sitter-python in regards to the following commit: https://github.com/tree-sitter/tree-sitter-python/commit/3324e923485177d72c1a87d315f3b31bf2294585

Notice that alias($.expression, $.as_pattern_target) uses $.as_pattern_target, and $.as_pattern_target does not have a production. In node-types.json, as_pattern specifies as_pattern_target as an accepted type for its alias field, but as_pattern_target does not exist as a type in node-types.json.

Is this behavior intended?

berchn avatar Feb 16 '22 16:02 berchn

Furthermore, this is also attempting to alias a grammar symbol which is specified as a supertype. Does it make sense to allow this?

berchn avatar Feb 16 '22 17:02 berchn

Possibly related to #455

But still the case for the latest Tree-sitter version:

  • https://github.com/tree-sitter/tree-sitter-python/blob/v0.23.0/grammar.js#L711
  • https://github.com/tree-sitter/tree-sitter-python/blob/v0.23.0/src/node-types.json#L396

Just based on the node-types.json it is impossible to tell what as_pattern_target refers to.

Marcono1234 avatar Sep 01 '24 14:09 Marcono1234