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

`'#'` as part of a quote should not be a comment

Open naclsn opened this issue 3 years ago • 2 comments

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.

naclsn avatar Jun 17 '22 08:06 naclsn

I believe it's fixed in #109. Could you check check master?

oxalica avatar Jul 30 '22 08:07 oxalica

Wow I got very confused by the timestamp on this commit. But it seems it does not quite cover every cases:

image (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).

naclsn avatar Jul 30 '22 10:07 naclsn

Forgot to add this to the issues I fixed in #186

amaanq avatar Aug 18 '23 05:08 amaanq