Skip to content

Commit 81267ca

Browse files
committed
'main': Highlight pipes inside array assignments as errors
Fixes #651.
1 parent bfd44f5 commit 81267ca

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

highlighters/main/main-highlighter.zsh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,17 @@ _zsh_highlight_main_highlighter_highlight_list()
732732
if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then
733733
# Missing closing square bracket(s)
734734
style=unknown-token
735+
elif $in_array_assignment; then
736+
case $arg in
737+
# Literal newlines are just fine.
738+
($'\n') style=commandseparator;;
739+
# Semicolons are parsed the same way as literal newlines. Nevertheless,
740+
# highlight them as errors since they're probably unintended. Compare
741+
# issue #691.
742+
(';') style=unknown-token;;
743+
# Other command separators aren't allowed.
744+
(*) style=unknown-token;;
745+
esac
735746
elif [[ $this_word == *':regular:'* ]]; then
736747
# This highlights empty commands (semicolon follows nothing) as an error.
737748
# Zsh accepts them, though.
@@ -746,12 +757,7 @@ _zsh_highlight_main_highlighter_highlight_list()
746757
next_word=':regular:'
747758
elif [[ $arg == ';' ]] && $in_array_assignment; then
748759
# literal semicolon inside an array assignment
749-
#
750-
# This is parsed the same way as a literal newline. Nevertheless,
751-
# highlight it as an error since it's probably unintended. Compare
752-
# issue #691.
753760
next_word=':regular:'
754-
style=unknown-token
755761
else
756762
next_word=':start:'
757763
highlight_glob=true

highlighters/main/test-data/array-cmdsep1.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ BUFFER=$'a=( foo | bar )'
3333
expected_region_highlight=(
3434
'1 3 assign' # a=(
3535
'5 7 default' # foo
36-
'9 9 unknown-token "issue #651"' # |
36+
'9 9 unknown-token' # |
3737
'11 13 unknown-token' # bar
3838
'15 15 unknown-token' # )
3939
)

0 commit comments

Comments
 (0)