From 47c2b7e1851375c3a9d3c1faec5851fc8409da08 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 13 Oct 2018 08:14:42 -0500 Subject: [PATCH] main: Distinguish quoted/unquoted command substitutions Closes #547. --- docs/highlighters/main.md | 4 ++++ highlighters/main/main-highlighter.zsh | 15 +++++++++------ .../command-substitution-in-assignment.zsh | 6 +++--- .../test-data/command-substitution-unclosed.zsh | 4 ++-- highlighters/main/test-data/cthulhu.zsh | 6 +++--- highlighters/main/test-data/dollar-paren.zsh | 6 +++--- .../main/test-data/redirection-in-cmdsubst.zsh | 6 +++--- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 188da07..6ff2bd8 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -33,7 +33,11 @@ This highlighter defines the following styles: * `globbing` - globbing expressions (`*.txt`) * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) * `command-substitution` - command substitutions (`$(echo foo)`) +* `command-substitution-unquoted` - an unquoted command substitution (`$(echo foo)`) +* `command-substitution-quoted` - a quoted command substitution (`"$(echo foo)"`) * `command-substitution-delimiter` - command substitution delimiters (`$(` and `)`) +* `command-substitution-delimiter-unquoted` - an unquoted command substitution delimiters (`$(` and `)`) +* `command-substitution-delimiter-quoted` - a quoted command substitution delimiters (`"$(` and `)"`) * `process-substitution` - process substitutions (`<(echo foo)`) * `process-substitution-delimiter` - process substitution delimiters (`<(` and `)`) * `single-hyphen-option` - single-hyphen options (`-o`) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 41a4fb9..455c21f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -107,6 +107,9 @@ _zsh_highlight_main_calculate_fallback() { dollar-quoted-argument{-unclosed,} back-quoted-argument{-unclosed,} + command-substitution{-quoted,,-unquoted,} + command-substitution-delimiter{-quoted,,-unquoted,} + command-substitution{-delimiter,} process-substitution{-delimiter,} back-quoted-argument{-delimiter,} @@ -1015,12 +1018,12 @@ _zsh_highlight_main_highlighter_highlight_argument() ret=$? (( i += REPLY )) highlights+=( - $(( start_pos + start - 1)) $(( start_pos + i )) command-substitution - $(( start_pos + start - 1)) $(( start_pos + start + 1)) command-substitution-delimiter + $(( start_pos + start - 1)) $(( start_pos + i )) command-substitution-unquoted + $(( start_pos + start - 1)) $(( start_pos + start + 1)) command-substitution-delimiter-unquoted $reply ) if (( ret == 0 )); then - highlights+=($(( start_pos + i - 1)) $(( start_pos + i )) command-substitution-delimiter) + highlights+=($(( start_pos + i - 1)) $(( start_pos + i )) command-substitution-delimiter-unquoted) fi continue fi @@ -1147,12 +1150,12 @@ _zsh_highlight_main_highlighter_highlight_double_quote() (( i += REPLY )) reply=( $saved_reply - $j $(( start_pos + i )) command-substitution - $j $(( j + 2 )) command-substitution-delimiter + $j $(( start_pos + i )) command-substitution-quoted + $j $(( j + 2 )) command-substitution-delimiter-quoted $reply ) if (( ret == 0 )); then - reply+=($(( start_pos + i - 1 )) $(( start_pos + i )) command-substitution-delimiter) + reply+=($(( start_pos + i - 1 )) $(( start_pos + i )) command-substitution-delimiter-quoted) fi continue else diff --git a/highlighters/main/test-data/command-substitution-in-assignment.zsh b/highlighters/main/test-data/command-substitution-in-assignment.zsh index 010df7f..fafda49 100644 --- a/highlighters/main/test-data/command-substitution-in-assignment.zsh +++ b/highlighters/main/test-data/command-substitution-in-assignment.zsh @@ -33,10 +33,10 @@ BUFFER=$'foo=$(echo bar) :' expected_region_highlight=( '1 15 assign' # foo=$(echo bar) '5 15 default' # $(echo bar) - '5 15 command-substitution' # $(echo bar) - '5 6 command-substitution-delimiter' # $( + '5 15 command-substitution-unquoted' # $(echo bar) + '5 6 command-substitution-delimiter-unquoted' # $( '7 10 builtin' # echo '12 14 default' # bar - '15 15 command-substitution-delimiter' # ) + '15 15 command-substitution-delimiter-unquoted' # ) '17 17 builtin' # : ) diff --git a/highlighters/main/test-data/command-substitution-unclosed.zsh b/highlighters/main/test-data/command-substitution-unclosed.zsh index 570471b..bce6863 100644 --- a/highlighters/main/test-data/command-substitution-unclosed.zsh +++ b/highlighters/main/test-data/command-substitution-unclosed.zsh @@ -33,8 +33,8 @@ BUFFER=$': foo$(echo bar' expected_region_highlight=( '1 1 builtin' # : '3 15 default' # foo$(echo bar - '6 15 command-substitution' # $(echo bar - '6 7 command-substitution-delimiter' # $( + '6 15 command-substitution-unquoted' # $(echo bar + '6 7 command-substitution-delimiter-unquoted' # $( '8 11 builtin' # echo '13 15 default' # bar ) diff --git a/highlighters/main/test-data/cthulhu.zsh b/highlighters/main/test-data/cthulhu.zsh index 7a1b7f1..c8119a8 100644 --- a/highlighters/main/test-data/cthulhu.zsh +++ b/highlighters/main/test-data/cthulhu.zsh @@ -53,8 +53,8 @@ expected_region_highlight=( '55 58 double-quoted-argument-unclosed' # "lhu '59 62 back-quoted-argument-delimiter' # \\\` '64 112 default' # R\\'ly$(echo eh wag\\\`echo h\'nag\\\`'l' fht)agn - '70 109 command-substitution' # $(echo eh wag\\\`echo h\'nag\\\`'l' fht) - '70 71 command-substitution-delimiter' # $( + '70 109 command-substitution-unquoted' # $(echo eh wag\\\`echo h\'nag\\\`'l' fht) + '70 71 command-substitution-delimiter-unquoted' # $( '72 75 builtin' # echo '77 78 default' # eh '80 104 default' # wag\\\`echo h\'nag\\\`'l' @@ -65,6 +65,6 @@ expected_region_highlight=( '98 101 back-quoted-argument-delimiter' # \\\` '102 104 single-quoted-argument' # 'l' '106 108 default' # fht - '109 109 command-substitution-delimiter' # ) + '109 109 command-substitution-delimiter-unquoted' # ) '113 113 unknown-token' # ` ) diff --git a/highlighters/main/test-data/dollar-paren.zsh b/highlighters/main/test-data/dollar-paren.zsh index f051e4a..51abddb 100644 --- a/highlighters/main/test-data/dollar-paren.zsh +++ b/highlighters/main/test-data/dollar-paren.zsh @@ -34,8 +34,8 @@ expected_region_highlight=( '1 1 builtin' # : '3 8 default' # "$(:)" '3 8 double-quoted-argument' # "$(:)" - '4 7 command-substitution' # $(:) - '4 5 command-substitution-delimiter' # $( + '4 7 command-substitution-quoted' # $(:) + '4 5 command-substitution-delimiter-quoted' # $( '6 6 builtin' # : - '7 7 command-substitution-delimiter' # ) + '7 7 command-substitution-delimiter-quoted' # ) ) diff --git a/highlighters/main/test-data/redirection-in-cmdsubst.zsh b/highlighters/main/test-data/redirection-in-cmdsubst.zsh index 65c7fbf..ed5eaef 100644 --- a/highlighters/main/test-data/redirection-in-cmdsubst.zsh +++ b/highlighters/main/test-data/redirection-in-cmdsubst.zsh @@ -33,9 +33,9 @@ BUFFER=$': $(