tree-sitter / tree-sitter-julia

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

Incorrectly parsed `if` condition? #117

Open simonmandlik opened 11 months ago

simonmandlik commented 11 months ago

This is from neovim:

if 1 + 1 < 2
end
if 2 > 1 + 1
end

and resulting nodes:

(if_statement) ; [1:1 - 2:3]
 condition: (integer_literal) ; [1:4 - 4]
 (binary_expression) ; [1:6 - 12]
  (unary_expression) ; [1:6 - 8]
   (operator) ; [1:6 - 6]
   (integer_literal) ; [1:8 - 8]
  (operator) ; [1:10 - 10]
  (integer_literal) ; [1:12 - 12]
(if_statement) ; [3:1 - 4:3]
 condition: (binary_expression) ; [3:4 - 12]
  (integer_literal) ; [3:4 - 4]
  (operator) ; [3:6 - 6]
  (binary_expression) ; [3:8 - 12]
   (integer_literal) ; [3:8 - 8]
   (operator) ; [3:10 - 10]
   (integer_literal) ; [3:12 - 12]

Isn't the first one wrong?

savq commented 11 months ago

Yes, this is parsed incorrectly.

Unfortunately, Julia allows omitting the terminator (newline or semicolon) between the condition and the consequent, so an expression like if x y end is syntactically valid. In this case, instead of x and y we have 1 and +1 < 2.