tree-sitter-julia
tree-sitter-julia copied to clipboard
Improve module, type and function definitions
Types and modules
- Add bare module definitions.
- Fix single line structs.
- Split tests for structs and other types.
Functions
- Add operators as names in function definitions.
- Add zero method function definitions.
- Add short form function definitions.
- Add function signature rule (shared by block and short function definitions).
- Add
whereclauses. - Refactor anonymous block functions (
function() ... end). Consider them function definitions, not function expressions. - Split tests for function definitions into 4 sections.
Function parameters and scoped identifiers
- Add anonymous typed parameters.
- Add parameters to
do_clause. - Rename
spread_expressiontoslurp_expression(yes, that's the real name). - Allow
_primary_expressionandprefixed_string_literalas types intyped_parameterandreturn_type. - Allow scoped identifiers in:
- function definitions
- macro identifiers
- type parameters
Misc
- Split import rules into
selected_importand_import_list. These cannot be used in the same import statement. - Remove 29 files from known-failures.
Caveats:
whereis actually a binary operator. It can be used in places beyond function definitions. A new rule could be added in the future to handle more use cases.- I wanted to add a
_parameterrule as suggested here, but this caused more conflicts than necessary. - I made the terminator after
do_clauseparameters mandatory. - The conflicts that were added are mostly due to the fact that
assignment_expressionstill allowscall_expressionin the LHS. - The reason for calling
...a "slurp" comes from here: What does the...operator do?
Once assignment patterns are fixed, these conflicts could be removed (and _parameter could finally be added), but I think that belongs in another PR.
Closes #26 Closes #41 Closes #42 Closes #36, but the implementation is different from #43 Closes #57
Very nice, I will close https://github.com/tree-sitter/tree-sitter-julia/pull/43 in favor of getting this one through.
Could you also add support for empty functions, for example function f end. These are often used to add docstrings.
This is awesome, thanks!
Just wanted to report a minor issue I found in which sometimes type assertions can be parsed as symbols, see this example

Another minor issue, the ∈ character in for loops is not being recognized (should be @keyword.operator to match in).

Just wanted to report a minor issue I found in which sometimes type assertions can be parsed as symbols, see this example
@ExpandingMan The PR fixes this 👍
Another minor issue, the ∈ character in for loops is not being recognized (should be @keyword.operator to match in).
This can be fixed in either the grammar or the queries, and it's a bit unrelated to the rest of the PR. I'll add a fix for this in nvim-treesitter first.
Ok. All the updated rules and their correspoding tests should be ready.
Should this be merged, @maxbrunsfeld ? Seems like a significant improvement.
Regarding slurp_expression, would splat_expression be more appropriate? I see ... described as the "splat operator" more than anything else. You'll also see it called the "splat operator" (but not the "slurp operator") in Python, Ruby, and other places.
I wrote the wrong thing in the PR comment (I updated it). For future reference:
spread_parameterwas renamed toslurp_parameter(here)spread_expressionwas renamed tosplat_expression(in #83)
That's the "correct" naming convention in Julia. See What does the ... operator do?