tree-sitter / tree-sitter-julia

Julia grammar for Tree-sitter
MIT License
93 stars 32 forks source link

How to improve assignments and scope qualifiers? #67

Closed savq closed 1 year ago

savq commented 1 year ago

Currently, the grammar defines three rules related to assignment:

variable_declaration doesn't actually do anything right now. const and let rules could be defined in terms of assignment_expression. The only place variable_declaration might be useful is in global/local declarations, but those are not defined in the grammar yet.

assignment_expression is not defined as an _expression to avoid conflicts. This is only a problem with simple assignments, but compound assignments don't have that problem. In fact, it's necessary to allow compound assignments in more places to allow things like xs[i+=1].

A viable solution might be:

  1. Define a rule assignment_statement (that only uses =)
  2. Redefine const, let, etc. to use assignment_statement
  3. Redefine assignment_expression to only use compound assignments

Fixing quote expressions is necessary to add local/global scope qualifiers to avoid test regressions. see https://github.com/tree-sitter/tree-sitter-julia/pull/6#issuecomment-663881117 (that's why this is an issue and not a PR).