Handle heredoc delimiters that include spaces (#47)
* Handle heredoc delimiters that include spaces * Update test to use multi-line heredoc to demonstrate bug This change demonstrates the bug described in https://github.com/tree-sitter/tree-sitter-bash/pull/47#discussion_r280183823. * Handle multi-line heredocs with spaces in delimiter Fixes the failing test introduced in 0d8adbc335. /xref https://github.com/tree-sitter/tree-sitter-bash/pull/47#discussion_r280183823
This commit is contained in:
parent
97e13b8145
commit
4f3cbc36b9
|
@ -212,6 +212,11 @@ cat << "EOF"
|
||||||
a=$b
|
a=$b
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
cat <<"END OF FILE"
|
||||||
|
hello,
|
||||||
|
world
|
||||||
|
END OF FILE
|
||||||
|
|
||||||
cat << \EOF
|
cat << \EOF
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
@ -220,6 +225,7 @@ EOF
|
||||||
(program
|
(program
|
||||||
(redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body)
|
(redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body)
|
||||||
(redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body (simple_expansion (variable_name)))
|
(redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body (simple_expansion (variable_name)))
|
||||||
|
(redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body)
|
||||||
(redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body))
|
(redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body))
|
||||||
|
|
||||||
==========================================
|
==========================================
|
||||||
|
|
|
@ -74,7 +74,7 @@ struct Scanner {
|
||||||
advance(lexer);
|
advance(lexer);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (iswalpha(lexer->lookahead)) {
|
while (iswalpha(lexer->lookahead) || (quote != 0 && iswspace(lexer->lookahead))) {
|
||||||
heredoc_delimiter += lexer->lookahead;
|
heredoc_delimiter += lexer->lookahead;
|
||||||
advance(lexer);
|
advance(lexer);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,12 @@ struct Scanner {
|
||||||
|
|
||||||
bool scan_heredoc_end_identifier(TSLexer *lexer) {
|
bool scan_heredoc_end_identifier(TSLexer *lexer) {
|
||||||
current_leading_word.clear();
|
current_leading_word.clear();
|
||||||
while (iswalpha(lexer->lookahead)) {
|
// Scan the first 'n' characters on this line, to see if they match the heredoc delimiter
|
||||||
|
while (
|
||||||
|
lexer->lookahead != '\0' &&
|
||||||
|
lexer->lookahead != '\n' &&
|
||||||
|
current_leading_word.length() < heredoc_delimiter.length()
|
||||||
|
) {
|
||||||
current_leading_word += lexer->lookahead;
|
current_leading_word += lexer->lookahead;
|
||||||
advance(lexer);
|
advance(lexer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue