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

bug: Error parsing x, = (2, 3) #164

Open
2 tasks done
iuliadmtru opened this issue Dec 11, 2024 · 0 comments
Open
2 tasks done

bug: Error parsing x, = (2, 3) #164

iuliadmtru opened this issue Dec 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@iuliadmtru
Copy link

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-julia

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

x, = (2, 3) is valid Julia code. It assigns the first value of the tuple (2) to x and discards the rest. It does the same thing as x, _ = (2, 3). However, the Tree-sitter shows an error after x.

x, y, = (2, 3, 4) is also valid code but shows an error after y.

x, _ = (2, 3, 4) does not error. It produces:

(source_file [0, 0] - [1, 0]
  (assignment [0, 0] - [0, 16]
    (open_tuple [0, 0] - [0, 4]
      (identifier [0, 0] - [0, 1])
      (identifier [0, 3] - [0, 4]))
    (operator [0, 5] - [0, 6])
    (tuple_expression [0, 7] - [0, 16]
      (integer_literal [0, 8] - [0, 9])
      (integer_literal [0, 11] - [0, 12])
      (integer_literal [0, 14] - [0, 15]))))

Steps To Reproduce/Bad Parse Tree

  1. echo 'x, = (2, 3)' > demo.jl
  2. tree-sitter parse demo.jl
(source_file [0, 0] - [1, 0]
  (open_tuple [0, 0] - [0, 11]
    (identifier [0, 0] - [0, 1])
    (ERROR [0, 3] - [0, 4])
    (tuple_expression [0, 5] - [0, 11]
      (integer_literal [0, 6] - [0, 7])
      (integer_literal [0, 9] - [0, 10]))))

Expected Behavior/Parse Tree

julia> dump(Meta.parse("x, = (2, 3)"))
Expr
  head: Symbol =
  args: Array{Any}((2,))
    1: Expr
      head: Symbol tuple
      args: Array{Any}((1,))
        1: Symbol x
    2: Expr
      head: Symbol tuple
      args: Array{Any}((2,))
        1: Int64 2
        2: Int64 3

I think the Tree-sitter output should be something like:

(source_file [0, 0] - [1, 0]
  (assignment [0, 0] - [0, 14]
    (open_tuple [0, 0] - [0, 2]
      (identifier [0, 0] - [0, 1]))
    (operator [0, 3] - [0, 4])
    (tuple_expression [0, 5] - [0, 11]
      (integer_literal [0, 6] - [0, 7])
      (integer_literal [0, 9] - [0, 10]))))

Repro

No response

@iuliadmtru iuliadmtru added the bug Something isn't working label Dec 11, 2024
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

1 participant