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

@@ -494,6 +494,9 @@ static size_t color_variable(const wchar_t *in, size_t in_len,
wchar_t next = in[idx + 1];
if (next == L'$' || valid_var_name_char(next)) {
colors[idx] = highlight_role_t::operat;
} else if (next == L'(') {
colors[idx] = highlight_role_t::operat;
return idx + 1;
} else {
colors[idx] = highlight_role_t::error;
}