From bdbe214453c40908006f1bc53bf0562e93fe957d Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 15 Nov 2017 22:38:19 -0600 Subject: [PATCH] main: Add *-quoted-argument-unclosed styles Closes #277. --- docs/highlighters/main.md | 3 +++ highlighters/main/main-highlighter.zsh | 27 ++++++++++++++++--- .../main/test-data/dollar-quoted3.zsh | 2 +- .../main/test-data/double-quoted2.zsh | 2 +- .../main/test-data/multiline-string2.zsh | 4 +-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 19912ab..7fddebc 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -36,8 +36,11 @@ This highlighter defines the following styles: * `double-hyphen-option` - double hyphen options (`--option`) * `back-quoted-argument` - backquoted expressions (`` `foo` ``) * `single-quoted-argument` - single quoted arguments (`` 'foo' ``) +* `single-quoted-argument-unclosed` - unclosed single quoted arguments (`` 'foo ``) * `double-quoted-argument` - double quoted arguments (`` "foo" ``) +* `double-quoted-argument-unclosed` - unclosed double quoted arguments (`` "foo ``) * `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``) +* `dollar-quoted-argument-unclosed` - unclosed dollar quoted arguments (`` $'foo ``) * `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``) * `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`) * `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a0cd600..3d5d9f3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -85,6 +85,10 @@ _zsh_highlight_main_add_region_highlight() { # in _zsh_highlight_main_highlighter_highlight_path_separators(). path_pathseparator path path_prefix_pathseparator path_prefix + + single-quoted-argument{-unclosed,} + double-quoted-argument{-unclosed,} + dollar-single-quoted-argument{-unclosed,} ) local needle=$1 value while [[ -n ${value::=$fallback_of[$needle]} ]]; do @@ -840,7 +844,7 @@ _zsh_highlight_main_highlighter_highlight_argument() # Highlight single-quoted strings _zsh_highlight_main_highlighter_highlight_single_quote() { - local arg1=$1 i q=\' + local arg1=$1 i q=\' style local -a highlights i=$arg[(ib:arg1+1:)$q] @@ -852,7 +856,12 @@ _zsh_highlight_main_highlighter_highlight_single_quote() done fi - highlights=($(( start_pos + $1 - 1 )) $(( start_pos + i )) single-quoted-argument $highlights) + if [[ $arg[i] == "'" ]]; then + style=single-quoted-argument + else + style=single-quoted-argument-unclosed + fi + highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights) _zsh_highlight_main_add_many_region_highlights $highlights REPLY=$i } @@ -912,7 +921,12 @@ _zsh_highlight_main_highlighter_highlight_double_quote() highlights+=($j $k $style) done - highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) double-quoted-argument $highlights) + if [[ $arg[i] == '"' ]]; then + style=double-quoted-argument + else + style=double-quoted-argument-unclosed + fi + highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $highlights) _zsh_highlight_main_add_many_region_highlights $highlights REPLY=$i } @@ -959,7 +973,12 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() highlights+=($j $k $style) done - highlights=($(( start_pos + $1 - 1 )) $(( start_pos + i )) dollar-quoted-argument $highlights) + if [[ $arg[i] == "'" ]]; then + style=dollar-quoted-argument + else + style=dollar-quoted-argument-unclosed + fi + highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights) _zsh_highlight_main_add_many_region_highlights $highlights REPLY=$i } diff --git a/highlighters/main/test-data/dollar-quoted3.zsh b/highlighters/main/test-data/dollar-quoted3.zsh index 320cd94..2872f7f 100644 --- a/highlighters/main/test-data/dollar-quoted3.zsh +++ b/highlighters/main/test-data/dollar-quoted3.zsh @@ -32,6 +32,6 @@ BUFFER=": \$'\xa1" expected_region_highlight=( - "3 4 dollar-quoted-argument" # $' + "3 4 dollar-quoted-argument-unclosed" # $' "5 8 back-dollar-quoted-argument" # \xa1 ) diff --git a/highlighters/main/test-data/double-quoted2.zsh b/highlighters/main/test-data/double-quoted2.zsh index 1538423..ecd79ea 100644 --- a/highlighters/main/test-data/double-quoted2.zsh +++ b/highlighters/main/test-data/double-quoted2.zsh @@ -32,6 +32,6 @@ BUFFER=': "foo$bar' expected_region_highlight=( - "3 6 double-quoted-argument" # "foo + "3 6 double-quoted-argument-unclosed" # "foo "7 10 dollar-double-quoted-argument" # $bar ) diff --git a/highlighters/main/test-data/multiline-string2.zsh b/highlighters/main/test-data/multiline-string2.zsh index 8ecce5b..7c5845e 100644 --- a/highlighters/main/test-data/multiline-string2.zsh +++ b/highlighters/main/test-data/multiline-string2.zsh @@ -27,8 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER=$'echo "foo1\n' +BUFFER=$'echo \'foo1\n' expected_region_highlight=( - "6 10 double-quoted-argument" # 'foo2"' + "6 10 single-quoted-argument-unclosed" # 'foo1 )