-
-
Notifications
You must be signed in to change notification settings - Fork 82
Description
I was editing this bash code today and realized that the heredoc was being terminated early and incorrectly by treesitter.
: <<'END_COMMENT'
This section is a heredoc (<<) redirected to a NOP command (:).
The single quotes around END_COMMENT are important,
because it disables variable resolving and command resolving
within these lines. Without the single-quotes around END_COMMENT,
any $() `` would get executed as commands.
END_COMMENT
Here the END_COMMENT was treated by treesitter as the end when the heredoc only terminates upon seeing END_COMMENT at the start of a line.
I'm still a noob so still learning how to set up a treesitter development environment to try to poke around and come up with the fix myself. So if someone wants to show me how i can get past getting stuck here, then that would also be appreciated.
I got tree-sitter cli installed and cloned tree-sitter-bash. Then I ran npm i in there and tree-sitter generate and tree-sitter test. Then I made the following change:
diff --git i/corpus/commands.txt w/corpus/commands.txt
index bca86b4..9c44a49 100644
--- i/corpus/commands.txt
+++ w/corpus/commands.txt
@@ -217,6 +217,18 @@ EOF
(program (redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body))
+======================================
+Heredocs with closure not at BOL
+======================================
+: <<EOF
+even if EOF shows up in the middle of a line
+it should not terminate the heredoc
+EOF
+
+---
+
+(program (redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body))
+
======================================
Quoted Heredocs
======================================But no amount of subsequent tree-sitter test calls allows the new test I added to be picked up. Here I am stuck.