tree-sitter-julia
tree-sitter-julia copied to clipboard
Incorrectly parsed `if` condition?
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?
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.