Skip to content

Commit

Permalink
'main': Add infrastructure for treating literal newlines differently …
Browse files Browse the repository at this point in the history
…to semicolons.

Used by the next commit.
  • Loading branch information
danielshahaf committed Mar 15, 2020
1 parent e58e452 commit a4525a0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions highlighters/main/main-highlighter.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a4525a0

Please sign in to comment.