tree-sitter-bash
tree-sitter-bash copied to clipboard
Spaces in subscript arithmetic expression
Hi, I'm using bash-language-server and found out it's using tree-sitter-bash, so hopefully I'm posting to the right repo. I found a problem, where an expression in array subscript can't be parsed if it contains spaces:
$ array=(aaa bbb ccc)
$ echo ${array[1234%2]} # works fine with bash and tree-sitter
aaa
$ echo ${array[1234 % 2]} # also works fine with bash, but not with tree-sitter
aaa
If I really wanted spaces, workaround can be made by using arithmetic expansion:
$ echo ${array[$((1234 % 2))]}
What do you think about this?
Thanks
Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.57. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!
Links: app homepage, dashboard and code for this bot.
Hi, as of now, the parser still can't deal with spaces in subscript arithmetic expression:
$ cat script.bash
echo ${array[1234 % 2]}
$ tree-sitter parse script.bash
Warning: You have not configured any parser directories!
Please run `tree-sitter init-config` and edit the resulting
configuration file to indicate where we should look for
language grammars.
(program [0, 0] - [1, 0]
(command [0, 0] - [0, 23]
name: (command_name [0, 0] - [0, 4]
(word [0, 0] - [0, 4]))
argument: (expansion [0, 5] - [0, 23]
(subscript [0, 7] - [0, 17]
name: (variable_name [0, 7] - [0, 12])
index: (word [0, 13] - [0, 17]))
(concatenation [0, 20] - [0, 22]
(word [0, 20] - [0, 21])))))
script.bash 0 ms (MISSING "]" [0, 17] - [0, 17])
Without spaces, the parser produces no "MISSING" messages:
$ cat script.bash
echo ${array[1234%2]}
$ tree-sitter parse script.bash
Warning: You have not configured any parser directories!
Please run `tree-sitter init-config` and edit the resulting
configuration file to indicate where we should look for
language grammars.
(program [0, 0] - [1, 0]
(command [0, 0] - [0, 21]
name: (command_name [0, 0] - [0, 4]
(word [0, 0] - [0, 4]))
argument: (expansion [0, 5] - [0, 21]
(subscript [0, 7] - [0, 20]
name: (variable_name [0, 7] - [0, 12])
index: (word [0, 13] - [0, 19])))))
Hi, as of now, the issue still remains.
I understand my last comment doesn't really add anything (although it's been a year, and I'm still tracking this issue). I do have other relevant info and that is that my original issue appeared in bash-language-server and it seems that they have made a workaround on their side: https://github.com/bash-lsp/bash-language-server/issues/706