tree-sitter-bash icon indicating copy to clipboard operation
tree-sitter-bash copied to clipboard

issue with multiple assignments on same line

Open lucy opened this issue 2 years ago • 1 comments

the if statement in

a= c=
b=
if true; then true; fi

gets parsed as a command name:

(program [0, 0] - [3, 0]
  (command [0, 0] - [2, 7]
    (variable_assignment [0, 0] - [0, 2]
      name: (variable_name [0, 0] - [0, 1]))
    (variable_assignment [0, 3] - [0, 5]
      name: (variable_name [0, 3] - [0, 4]))
    (variable_assignment [1, 0] - [1, 2]
      name: (variable_name [1, 0] - [1, 1]))
    name: (command_name [2, 0] - [2, 2]
      (word [2, 0] - [2, 2]))
    argument: (word [2, 3] - [2, 7]))
  (command [2, 9] - [2, 18]
    name: (command_name [2, 9] - [2, 13]
      (word [2, 9] - [2, 13]))
    argument: (word [2, 14] - [2, 18]))
  (command [2, 20] - [2, 22]
    name: (command_name [2, 20] - [2, 22]
      (word [2, 20] - [2, 22]))))

while

a= c= b=
if true; then true; fi

parses as an if_statement:

(program [0, 0] - [2, 0]
  (variable_assignments [0, 0] - [0, 8]
    (variable_assignment [0, 0] - [0, 2]
      name: (variable_name [0, 0] - [0, 1]))
    (variable_assignment [0, 3] - [0, 5]
      name: (variable_name [0, 3] - [0, 4]))
    (variable_assignment [0, 6] - [0, 8]
      name: (variable_name [0, 6] - [0, 7])))
  (if_statement [1, 0] - [1, 22]
    condition: (command [1, 3] - [1, 7]
      name: (command_name [1, 3] - [1, 7]
        (word [1, 3] - [1, 7])))
    (command [1, 14] - [1, 18]
      name: (command_name [1, 14] - [1, 18]
        (word [1, 14] - [1, 18])))))

lucy avatar Oct 23 '23 20:10 lucy

reserved rules api might be needed for this (not a thing yet)

amaanq avatar Feb 10 '24 06:02 amaanq