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

Failed to parse here document ending with a backslash

Open cr1st1p opened this issue 5 years ago • 4 comments

Inside vscode, I get 'Failed to parse exception' for the following code:

#! /usr/bin/env bash

f() {
    cat << 'EOS'
        echo 'test1' \
        ; echo 'test2' \
EOS
}

f

It works if I add en empty line above the ending EOS, but it ends in the output, which is totally undesirable for my use case. It works also if I just remove the last backslash - but, again, I need that one.

cr1st1p avatar Jan 29 '20 09:01 cr1st1p

I don't believe this is a bug. You're escaping the return so you're putting the EOS on the same line as test2 so the here doc isn't closed. You can test this interactively a see it continues the input of the here doc.

derekschrock avatar May 03 '20 08:05 derekschrock

@derekschrock I did test this before posting. Let me know if you tested and what happened in your case.

Besides testing, look closer - I'm using the quoted form of end of here-string: 'EOS' Meaning the backslash won't be a continuation line marker. You would be right if I would have used the non quoted EOS marker.

I reported this bug also to 'shfmt' where it was quickly fixed.

Regards.

cr1st1p avatar May 03 '20 14:05 cr1st1p

Yeah, you're right sorry for that. I missed it was a quoted here-doc. Too late while I was searching issues for my own here-doc related problems.

derekschrock avatar May 03 '20 16:05 derekschrock

I have experienced the same problem with the extra caveat that the error reproduction is coupled to the existence of a git repo: If the file I'm editing is inside a git repo I get the error, if I move the file (or remove the .git dir) all is fine. Using the server through terminal vim + ale plugin.

iddinev avatar Jun 02 '20 09:06 iddinev