tree-sitter / tree-sitter-go

Go grammar for tree-sitter
MIT License
310 stars 65 forks source link

Accept only identifiers on LHS of := #74

Closed adonovan closed 1 month ago

adonovan commented 2 years ago

This PR changes short_var_declaration to accept only a list of identifiers on the left side. This prevents an (expression_list (identifier)) query from spuriously matching an identifier in a declaration.

Also:

I notice there is a tension here between what highlighting wants (mostly correct heuristics for things like new and iota) and what Stack Graphs wants (a minimal, regular, and semantically factored tree---since the program that converts TS trees to SG graphs can't express top-down recursive propagation of modal concepts like def vs. use).

Also, unrelated:

Checklist:

maxbrunsfeld commented 2 years ago

Makes sense!

dominikh commented 1 year ago

Are there any plans to move forward with this PR? In particular

we no longer treat the identifiers nil, true, false, iota, new, and make specially. All are legal identifiers, readily reused as field or method names without ambiguity, and the last three are not infrequently redefined as local variables.

would be nice to get in.

adonovan commented 1 year ago

I have no plans to do anything with this PR. Feel free to take it over.