Support "$(cmd)" command substitution without line splitting

This adds a hack to the parser. Given a command

	echo "x$()y z"

we virtually insert double quotes before and after the command
substitution, so the command internally looks like

	echo "x"$()"y z"

This hack allows to reuse the existing logic for handling (recursive)
command substitutions.

This makes the quoting syntax more complex; external highlighters
should consider adding this if possible.

The upside (more Bash compatibility) seems worth it.

Closes #159
This commit is contained in:
Johannes Altmanninger
2021-07-02 23:11:03 +02:00
parent 4437a0d02a
commit ec3d3a481b
9 changed files with 201 additions and 28 deletions

View File

@@ -5103,8 +5103,7 @@ static void test_error_messages() {
{L"echo foo\"$\"bar", ERROR_NO_VAR_NAME},
{L"echo \"foo\"$\"bar\"", ERROR_NO_VAR_NAME},
{L"echo foo $ bar", ERROR_NO_VAR_NAME},
{L"echo foo$(foo)bar", ERROR_BAD_VAR_SUBCOMMAND1},
{L"echo \"foo$(foo)bar\"", ERROR_BAD_VAR_SUBCOMMAND1}};
{L"echo foo$(foo)bar", ERROR_BAD_VAR_SUBCOMMAND1}};
parse_error_list_t errors;
for (const auto &test : error_tests) {
@@ -5194,6 +5193,16 @@ static void test_highlighting() {
{L"|", highlight_role_t::statement_terminator},
{L"cat", highlight_role_t::command},
});
highlight_tests.push_back({
{L"true", highlight_role_t::command},
{L"\"before", highlight_role_t::quote},
{L"$(", highlight_role_t::operat},
{L"true", highlight_role_t::command},
{L"param1", highlight_role_t::param},
{L")", highlight_role_t::operat},
{L"after\"", highlight_role_t::quote},
{L"param2", highlight_role_t::param},
});
// Redirections substitutions.
highlight_tests.push_back({