but tree-sitter generate complains about a conflict:
Unresolved conflict for symbol sequence:
'typeof' expression • '<' …
Possible interpretations:
1: 'typeof' (binary_expression expression • '<' expression) (precedence: 'binary_relation', associativity: Left)
2: 'typeof' (call_expression expression • type_arguments arguments) (precedence: 'call')
3: 'typeof' (call_expression expression • type_arguments template_string) (precedence: 'call')
4: 'typeof' (instantiation_expression expression • type_arguments) (precedence: 'instantiation', associativity: Left)
5: (unary_expression 'typeof' expression) • '<' … (precedence: 'unary_void', associativity: Left)
Possible resolutions:
1: Specify a higher precedence in `call_expression` and `binary_expression` and `instantiation_expression` than in the other rules.
2: Specify a higher precedence in `unary_expression` than in the other rules.
3: Add a conflict for these rules: `call_expression`, `binary_expression`, `unary_expression`, `instantiation_expression`
Note that typeof stuff<T> should be parsed with an instantiation expression (possible interpretation 4).
I tried to change the precedences field in many different ways to fix the conflict, but couldn’t figure out how to make it work.
The following piece of code is valid but it is parsed incorrectly:
Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript
The output of
tree-sitter parse
is the following:This is a relatively new feature, called "instantiation expressions", since Typescript 4.7: see here.
Probably related: #243.
I tried to implement it myself as follows:
but
tree-sitter generate
complains about a conflict:Note that
typeof stuff<T>
should be parsed with an instantiation expression (possible interpretation 4). I tried to change theprecedences
field in many different ways to fix the conflict, but couldn’t figure out how to make it work.Is there someone who knows how to make it work?