bash-language-server icon indicating copy to clipboard operation
bash-language-server copied to clipboard

Failed to parse expression: here document

Open mkopec3 opened this issue 5 years ago • 4 comments

Code that triggers the issue:

#!/bin/sh

cat <<!HEREDOC!
hello
this
is
smth..
!HEREDOC!

Screenshot from VSCode: bash_ide_heredoc

Identified on: Bash IDE 1.3.3 + VSCode (Version: 1.33.1)

mkopec3 avatar Apr 29 '19 15:04 mkopec3

Seems that the exclamation mark causes the issue. Should it be reported here: https://github.com/tree-sitter/tree-sitter-bash/issues ?

mkopec3 avatar Apr 29 '19 16:04 mkopec3

Thanks for reporting this issue. It seems to be a grammar issue.

I created an issue: https://github.com/tree-sitter/tree-sitter-bash/issues/58

skovhus avatar Sep 23 '19 19:09 skovhus

I had a similar problem, as I was using this in all my scripts:

cat <<!
text...
!

Although it worked, I thought I was working on the edge of legality, messing with "history" notations, So when I started using shellcheck, I switched to

cat <<Q
text...
Q

Note that the tabbed entry for readability is important (might impact how this gets fixed):

cat <<-!
<tab>...text...
!

dseynhae avatar Sep 23 '19 19:09 dseynhae

i have a similar problem...

read -r -d '' some-var << __EOF__ || true
blabla
blabla
__EOF__

the parser does not like the underlin (__) at the beginning.

macduke avatar Jul 21 '20 09:07 macduke

This seems to have been fixed in the newer version of the grammar

skovhus avatar Nov 25 '22 13:11 skovhus