'main': Highlight the parentheses of array assignments as reserved words.

Fixes #585.
This commit is contained in:
Daniel Shahaf 2020-06-08 14:23:43 +00:00
parent 00c0c76550
commit 0f11d80968
13 changed files with 28 additions and 1 deletions

View file

@ -85,6 +85,10 @@
- Highlight arithmetic expansions (e.g., `$(( 42 ))`)
[#607 #649 #704]
- Highlight the parentheses of array assignments as reserved words (`foo=( bar )`).
The `assign` style remains supported and has precedence.
[#585]
# Changes in version 0.7.1
- Remove out-of-date information from the 0.7.0 changelog.

View file

@ -1007,6 +1007,7 @@ _zsh_highlight_main_highlighter_highlight_list()
saw_assignment=true
if [[ $arg[i] == '(' ]]; then
in_array_assignment=true
_zsh_highlight_main_add_region_highlight start_pos+i-1 start_pos+i reserved-word
else
# assignment to a scalar parameter.
# (For array assignments, the command doesn't start until the ")" token.)
@ -1088,9 +1089,11 @@ _zsh_highlight_main_highlighter_highlight_list()
($'\x29')
# subshell or end of array assignment
if $in_array_assignment; then
style=assign
_zsh_highlight_main_add_region_highlight $start_pos $end_pos assign
_zsh_highlight_main_add_region_highlight $start_pos $end_pos reserved-word
in_array_assignment=false
next_word+=':start:'
continue
elif (( in_redirection )); then
style=unknown-token
else

View file

@ -33,6 +33,7 @@ bar(){}
expected_region_highlight=(
'1 3 assign' # a=(
'3 3 reserved-word' # (
'5 7 default' # foo
'9 9 unknown-token' # |
# zsh reports a parse error at this point. Nevertheless, we test how we

View file

@ -32,8 +32,10 @@ BUFFER=$'a=( foo ; bar )'
expected_region_highlight=(
'1 3 assign' # a=(
'3 3 reserved-word' # (
'5 7 default' # foo
'9 9 unknown-token' # ; (not commandseparator; see highlighter source code)
'11 13 default' # bar
'15 15 assign' # )
'15 15 reserved-word' # )
)

View file

@ -32,8 +32,10 @@ BUFFER=$'a=( foo \n bar )'
expected_region_highlight=(
'1 3 assign' # a=(
'3 3 reserved-word' # (
'5 7 default' # foo
'9 9 commandseparator' # \n
'11 13 default' # bar
'15 15 assign' # )
'15 15 reserved-word' # )
)

View file

@ -31,7 +31,9 @@ BUFFER='a+=(lorem ipsum)'
expected_region_highlight=(
"1 4 assign" # a+=(
"4 4 reserved-word" # (
"5 9 default" # lorem
"11 15 default" # ipsum
"16 16 assign" # )
"16 16 reserved-word" # )
)

View file

@ -32,8 +32,10 @@ BUFFER='(A=(hello world))'
expected_region_highlight=(
"1 1 reserved-word" # (
"2 4 assign" # A=(
"4 4 reserved-word" # (
"5 9 default" # hello
"11 15 default" # world
"16 16 assign" # )
"16 16 reserved-word" # )
"17 17 reserved-word" # )
)

View file

@ -31,8 +31,10 @@ BUFFER='A=(hello world) ls'
expected_region_highlight=(
"1 3 assign" # A=(
"3 3 reserved-word" # (
"4 8 default" # hello
"10 14 default" # world
"15 15 assign" # )
"15 15 reserved-word" # )
"17 18 command" # ls
)

View file

@ -31,9 +31,11 @@ BUFFER='A=(hello world) b=42'
expected_region_highlight=(
"1 3 assign" # A=(
"3 3 reserved-word" # (
"4 8 default" # hello
"10 14 default" # world
"15 15 assign" # )
"15 15 reserved-word" # )
"17 20 assign" # b=42
"19 20 default" # 42
)

View file

@ -33,8 +33,10 @@ expected_region_highlight=(
"1 3 assign" # A=1
"3 3 default" # 1
"5 7 assign" # b=(
"7 7 reserved-word" # (
"8 12 default" # "foo"
"8 12 double-quoted-argument" # "foo"
"14 16 default" # bar
"17 17 assign" # )
"17 17 reserved-word" # )
)

View file

@ -32,9 +32,11 @@ BUFFER=$'foo=(bar abaz) \! ls'
expected_region_highlight=(
'1 5 assign' # foo=(
'5 5 reserved-word' # (
'6 8 default' # bar
'10 13 default' # abaz
'14 14 assign' # )
'14 14 reserved-word' # )
'16 16 unknown-token' # \!
'18 19 command' # ls
)

View file

@ -32,8 +32,10 @@ BUFFER=$'foo=(\nbar) env'
expected_region_highlight=(
'1 5 assign' # foo=(
'5 5 reserved-word' # (
'6 6 commandseparator' # \n
'7 9 default' # bar
'10 10 assign' # )
'10 10 reserved-word' # )
'12 14 precommand' # env
)

View file

@ -34,5 +34,6 @@ BUFFER=$'l+=( $1'
expected_region_highlight=(
'1 4 assign' # l+=(
'4 4 reserved-word' # (
'6 7 default' # $1
)