Skip to content

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

@iuliadmtru

Description

@iuliadmtru

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions