tree-sitter-bash
tree-sitter-bash copied to clipboard
`'#'` as part of a quote should not be a comment
Adding to the pile of incorrect comment parsing (see #41, #70, #116).
'#', when affixed to a quote or an expansion/substitution, should not delimit a comment, as in:
echo 'word'#not-comment
echo $(uname -a)#not-comment
echo `uname -a`#not-comment
echo $hey#not-comment
# ...
(ref.: Shell Command Language - rule 8).
This also seems to be the case for variable assignment:
var=#something
echo "'$var'" # -> '#something'
I couldn't tell from documentation if this is intended behavior, but it is for dash, bash and zsh.
I believe it's fixed in #109. Could you check check master?
Wow I got very confused by the timestamp on this commit. But it seems it does not quite cover every cases:
(tree-sitter parse hello.bash sais the same but with more characters)
From my little understanding of #109 it seems the parser will not make # start a comment when it's already in the word rule (last line). But when it just parsed an other rule successfully (eg. raw_string for the first line), any # will start a comment (as it cannot start a word).
Probably this has to be solved directly in the scanner, with either a lookbehind or an equivalent to token.immediate($.word).
Forgot to add this to the issues I fixed in #186