tree-sitter / tree-sitter-julia

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

Latest version does not handle where clauses with one parameter #108

Closed ronisbr closed 1 year ago

ronisbr commented 1 year ago

Hi!

With the latest commit, the following code produces an error:

function a(b::T) where T<:Number
    b
end
(function_definition function name: (identifier)
 (parameter_list (
  (typed_parameter parameter: (identifier) :: type: (identifier))
  ))
 (where_clause where (identifier))
 (ERROR (operator))
 (identifier) \n (identifier) \n end)

Everything works fine if I wrap the where clause in {}:

function a(b::T) where {T<:Number}
    b
end
(function_definition function name: (identifier)
 (parameter_list (
  (typed_parameter parameter: (identifier) :: type: (identifier))
  ))
 (where_clause where
  (curly_expression {
   (binary_expression (identifier) (operator) (identifier))
   }))
 \n (identifier) \n end)
ronisbr commented 1 year ago

If my analysis is right, the problem started with #106

savq commented 1 year ago

Yes. Previously your example parsed but didn't make any sense.

function a(b::T) where T<:Number
    b
end

was parsed as:

(function_definition … (where_clause (Identifier)) (type_clause (Identifier)) …

when it should parse as:

(function_definition … (where_clause (binary_expression (Identifier) (operator) (Identifier)) …

It'll be fixed in the next PR.