Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrectly parsed if condition? #117

Open
simonmandlik opened this issue Sep 20, 2023 · 1 comment
Open

Incorrectly parsed if condition? #117

simonmandlik opened this issue Sep 20, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@simonmandlik
Copy link

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
Copy link
Collaborator

savq commented Sep 21, 2023

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.

@savq savq added the bug Something isn't working label Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants