tree-sitter / tree-sitter-julia

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

binary_expression inside macrocall_expression becomes short_function_definition #98

Closed ignamartinoli closed 4 months ago

ignamartinoli commented 1 year ago

This code:

using Test

const I = x -> x

@test I(1) === 1
@test I(I) === 1

The relevant tree produced for the two last lines is:

  macrocall_expression [8, 0] - [8, 16]
    macro_identifier [8, 0] - [8, 5]
      identifier [8, 1] - [8, 5]
    macro_argument_list [8, 6] - [8, 16]
      binary_expression [8, 6] - [8, 16]
        call_expression [8, 6] - [8, 10]
          identifier [8, 6] - [8, 7]
          argument_list [8, 7] - [8, 10]
            integer_literal [8, 8] - [8, 9]
        operator [8, 11] - [8, 14]
        integer_literal [8, 15] - [8, 16]
  macrocall_expression [9, 0] - [9, 16]
    macro_identifier [9, 0] - [9, 5]
      identifier [9, 1] - [9, 5]
    macro_argument_list [9, 6] - [9, 16]
      short_function_definition [9, 6] - [9, 14]
        name: identifier [9, 6] - [9, 7]
        parameters: parameter_list [9, 7] - [9, 10]
          identifier [9, 8] - [9, 9]
        operator [9, 12] - [9, 14]
      identifier [9, 15] - [9, 16]

The first @test is correctly recognized, the second not.

This is the resulting highlight is:

20230221 - 14:37:31

Because of this bug, on the egality operator for the second @test, only the last two = get highlighted

savq commented 1 year ago

I've looked at this a couple of times now, and I'm still not sure about how to adjust the precedence of macro calls and short functions so this doesn't happen.

The nvim-treesitter Julia highlighting was updated a few weeks ago so this isn't as noticeable, but the bug is still there!