From a4525a0826a3e1b0fc3def19a0a4a527c7045f3d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 14:17:51 +0000 Subject: [PATCH] 'main': Add infrastructure for treating literal newlines differently to semicolons. Used by the next commit. --- highlighters/main/main-highlighter.zsh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d01c129..7b9fbd3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -359,6 +359,7 @@ _zsh_highlight_highlighter_main_paint() ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=( '|' '||' ';' '&' '&&' + $'\n' # ${(z)} returns ';' but we convert it to $'\n' '|&' '&!' '&|' # ### 'case' syntax, but followed by a pattern, not by a command @@ -535,12 +536,17 @@ _zsh_highlight_main_highlighter_highlight_list() if (( in_alias == 0 && in_param == 0 )); then # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. - [[ "$proc_buf" = (#b)(#s)(([ $'\t']|\\$'\n')#)* ]] + [[ "$proc_buf" = (#b)(#s)(([ $'\t']|[\\]$'\n')#)(?|)* ]] # The first, outer parenthesis integer offset="${#match[1]}" (( start_pos = end_pos + offset )) (( end_pos = start_pos + $#arg )) + # The zsh lexer considers ';' and newline to be the same token, so + # ${(z)} converts all newlines to semicolons. Convert them back here to + # make later processing simplier. + [[ $arg == ';' && ${match[3]} == $'\n' ]] && arg=$'\n' + # Compute the new $proc_buf. We advance it # (chop off characters from the beginning) # beyond what end_pos points to, by skipping @@ -731,7 +737,7 @@ _zsh_highlight_main_highlighter_highlight_list() else style=unknown-token fi - if [[ $arg == ';' ]] && $in_array_assignment; then + if [[ $arg == (';'|$'\n') ]] && $in_array_assignment; then # literal newline inside an array assignment next_word=':regular:' else