tree-sitter-bash
tree-sitter-bash copied to clipboard
Multiple variable assignment on the same line messes with subsequent parsing
Using (the very nice, thank you very much!) tree-sitter playground for bash, the following is parsed incorrectly:
FOO="bar" BAZ="quux"
my_func() {
echo "hello"
}
the tree looks like this:
program [0, 0] - [5, 0]
command [0, 0] - [2, 7]
variable_assignment [0, 0] - [0, 9]
name: variable_name [0, 0] - [0, 3]
value: string [0, 4] - [0, 9]
variable_assignment [0, 10] - [0, 20]
name: variable_name [0, 10] - [0, 13]
value: string [0, 14] - [0, 20]
name: command_name [2, 0] - [2, 7]
word [2, 0] - [2, 7]
ERROR [2, 7] - [2, 11]
command [3, 4] - [3, 16] ← this should have been function_definition
name: command_name [3, 4] - [3, 8]
word [3, 4] - [3, 8]
argument: string [3, 9] - [3, 16]
command [4, 0] - [4, 1]
name: command_name [4, 0] - [4, 1]
word [4, 0] - [4, 1]
Breaking the variable assignments into to two lines makes it parse correctly:
FOO="bar"
BAZ="quux"
my_func() {
echo "hello"
}
produces:
program [0, 0] - [6, 0]
variable_assignment [0, 0] - [0, 9]
name: variable_name [0, 0] - [0, 3]
value: string [0, 4] - [0, 9]
variable_assignment [1, 0] - [1, 10]
name: variable_name [1, 0] - [1, 3]
value: string [1, 4] - [1, 10]
function_definition [3, 0] - [5, 1]
name: word [3, 0] - [3, 7]
body: compound_statement [3, 10] - [5, 1]
command [4, 4] - [4, 16]
name: command_name [4, 4] - [4, 8]
word [4, 4] - [4, 8]
argument: string [4, 9] - [4, 16]
Locally I'm using language version 13 (release v0.19.0), I'm not sure which version is used by the playground.
AFAIK multiple variable assignments on the same line are legal in bash, so it looks to be a bug in parser.