From 81267ca3130c420f65164730f0585630ac5bbe40 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <danielsh@apache.org>
Date: Sun, 15 Mar 2020 14:25:49 +0000
Subject: [PATCH] 'main': Highlight pipes inside array assignments as errors

Fixes #651.
---
 highlighters/main/main-highlighter.zsh        | 16 +++++++++++-----
 highlighters/main/test-data/array-cmdsep1.zsh |  2 +-
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh
index 3986e56..1402669 100644
--- a/highlighters/main/main-highlighter.zsh
+++ b/highlighters/main/main-highlighter.zsh
@@ -732,6 +732,17 @@ _zsh_highlight_main_highlighter_highlight_list()
      if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then
        # Missing closing square bracket(s)
        style=unknown-token
+     elif $in_array_assignment; then
+       case $arg in
+         # Literal newlines are just fine.
+         ($'\n') style=commandseparator;;
+         # Semicolons are parsed the same way as literal newlines.  Nevertheless,
+         # highlight them as errors since they're probably unintended.  Compare
+         # issue #691.
+         (';') style=unknown-token;;
+         # Other command separators aren't allowed.
+         (*) style=unknown-token;;
+       esac
      elif [[ $this_word == *':regular:'* ]]; then
        # This highlights empty commands (semicolon follows nothing) as an error.
        # Zsh accepts them, though.
@@ -746,12 +757,7 @@ _zsh_highlight_main_highlighter_highlight_list()
        next_word=':regular:'
      elif [[ $arg == ';' ]] && $in_array_assignment; then
        # literal semicolon inside an array assignment
-       #
-       # This is parsed the same way as a literal newline.  Nevertheless,
-       # highlight it as an error since it's probably unintended.  Compare
-       # issue #691.
        next_word=':regular:'
-       style=unknown-token
      else
        next_word=':start:'
        highlight_glob=true
diff --git a/highlighters/main/test-data/array-cmdsep1.zsh b/highlighters/main/test-data/array-cmdsep1.zsh
index 38ff6d9..3ffe43d 100644
--- a/highlighters/main/test-data/array-cmdsep1.zsh
+++ b/highlighters/main/test-data/array-cmdsep1.zsh
@@ -33,7 +33,7 @@ BUFFER=$'a=( foo | bar )'
 expected_region_highlight=(
   '1 3 assign' # a=(
   '5 7 default' # foo
-  '9 9 unknown-token "issue #651"' # |
+  '9 9 unknown-token' # |
   '11 13 unknown-token' # bar
   '15 15 unknown-token' # )
 )