fix: concatenations where the last item is a command substitution with backticks

pull/504/merge
Amaan Qureshi 2023-08-23 00:16:59 +07:00
parent ce1c91528d
commit ef162f7402
2 changed files with 41 additions and 2 deletions

16
src/scanner.c vendored

@ -276,10 +276,24 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
lexer->lookahead == '<' || lexer->lookahead == ')' ||
lexer->lookahead == '(' || lexer->lookahead == ';' ||
lexer->lookahead == '&' || lexer->lookahead == '|' ||
lexer->lookahead == '`' ||
(lexer->lookahead == '}' && valid_symbols[CLOSING_BRACE]) ||
(lexer->lookahead == ']' && valid_symbols[CLOSING_BRACKET]))) {
lexer->result_symbol = CONCAT;
// This sucks
if (lexer->lookahead == '`') {
lexer->mark_end(lexer);
advance(lexer);
while (lexer->lookahead != '`' && !lexer->eof(lexer)) {
advance(lexer);
}
if (lexer->eof(lexer)) {
return false;
}
if (lexer->lookahead == '`') {
advance(lexer);
}
return iswspace(lexer->lookahead) || lexer->eof(lexer);
}
return true;
}
}

@ -390,6 +390,10 @@ echo `echo hi; echo there`
echo $(echo $(echo hi))
echo $(< some-file)
# both of these are concatenations!
echo `echo otherword`word
echo word`echo otherword`
--------------------------------------------------------------------------------
(program
@ -430,7 +434,28 @@ echo $(< some-file)
(word))
(command_substitution
(file_redirect
(word)))))
(word))))
(comment)
(command
(command_name
(word))
(concatenation
(command_substitution
(command
(command_name
(word))
(word)))
(word)))
(command
(command_name
(word))
(concatenation
(word)
(command_substitution
(command
(command_name
(word))
(word))))))
================================================================================
Process substitutions