@@ -782,75 +782,75 @@ _zsh_highlight_main_highlighter_highlight_list()
782782 next_word+= ' :sudo_opt:'
783783 next_word+= ' :start:'
784784 fi
785- fi
786-
787- # The Great Fork: is this a command word? Is this a non-command word?
788- if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:# " $arg " } ]]; then
789-
790- # First, determine the style of the command separator itself.
791- if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then
792- # Missing closing square bracket(s)
793- style=unknown-token
794- elif $in_array_assignment ; then
795- case $arg in
796- # Literal newlines are just fine.
797- ($' \n ' ) style=commandseparator;;
798- # Semicolons are parsed the same way as literal newlines. Nevertheless,
799- # highlight them as errors since they're probably unintended. Compare
800- # issue #691.
801- (' ;' ) style=unknown-token;;
802- # Other command separators aren't allowed.
803- (* ) style=unknown-token;;
804- esac
805- elif [[ $this_word == * ' :regular:' * ]]; then
806- style=commandseparator
807- elif [[ $this_word == * ' :start:' * ]] && [[ $arg == $' \n ' ]]; then
808- style=commandseparator
809- else
810- # This highlights empty commands (semicolon follows nothing) as an error.
811- # Zsh accepts them, though.
812- style=unknown-token
813- fi
814-
815- # Second, determine the style of next_word.
816- if [[ $arg == $' \n ' ]] && $in_array_assignment ; then
817- # literal newline inside an array assignment
818- next_word=' :regular:'
819- elif [[ $arg == ' ;' ]] && $in_array_assignment ; then
820- # literal semicolon inside an array assignment
821- next_word=' :regular:'
822- else
823- next_word=' :start:'
824- highlight_glob=true
825- if [[ $arg != ' |' && $arg != ' |&' ]]; then
826- next_word+=' :start_of_pipeline:'
827- fi
828- fi
829-
830- elif ! (( in_redirection)) && [[ $this_word == * ' :always:' * && $arg == ' always' ]]; then
831- # try-always construct
832- style=reserved-word # de facto a reserved word, although not de jure
833- highlight_glob=true
834- next_word=' :start::start_of_pipeline:' # only left brace is allowed, apparently
835- elif ! (( in_redirection)) && [[ $this_word == * ' :start:' * ]]; then # $arg is the command word
836- if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg ; then
837- style=precommand
838- () {
839- set -- " ${(@ s.: .)precommand_options[$arg]} "
840- flags_with_argument=$1
841- flags_sans_argument=$2
842- flags_solo=$3
843- }
844- next_word=${next_word//: regular:/ }
845- next_word+=' :sudo_opt:'
846- next_word+=' :start:'
847- if [[ $arg == ' exec' ]]; then
848- # To allow "exec 2>&1;" where there's no command word
849- next_word+=' :regular:'
785+ fi
786+
787+ # The Great Fork: is this a command word? Is this a non-command word?
788+ if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:# " $arg " } ]]; then
789+
790+ # First, determine the style of the command separator itself.
791+ if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then
792+ # Missing closing square bracket(s)
793+ style=unknown-token
794+ elif $in_array_assignment ; then
795+ case $arg in
796+ # Literal newlines are just fine.
797+ ($' \n ' ) style=commandseparator;;
798+ # Semicolons are parsed the same way as literal newlines. Nevertheless,
799+ # highlight them as errors since they're probably unintended. Compare
800+ # issue #691.
801+ (' ;' ) style=unknown-token;;
802+ # Other command separators aren't allowed.
803+ (* ) style=unknown-token;;
804+ esac
805+ elif [[ $this_word == * ' :regular:' * ]]; then
806+ style=commandseparator
807+ elif [[ $this_word == * ' :start:' * ]] && [[ $arg == $' \n ' ]]; then
808+ style=commandseparator
809+ else
810+ # This highlights empty commands (semicolon follows nothing) as an error.
811+ # Zsh accepts them, though.
812+ style=unknown-token
813+ fi
814+
815+ # Second, determine the style of next_word.
816+ if [[ $arg == $' \n ' ]] && $in_array_assignment ; then
817+ # literal newline inside an array assignment
818+ next_word=' :regular:'
819+ elif [[ $arg == ' ;' ]] && $in_array_assignment ; then
820+ # literal semicolon inside an array assignment
821+ next_word=' :regular:'
822+ else
823+ next_word=' :start:'
824+ highlight_glob=true
825+ if [[ $arg != ' |' && $arg != ' |&' ]]; then
826+ next_word+=' :start_of_pipeline:'
827+ fi
850828 fi
851- else
852- case $res in
853- reserved) # reserved word
829+
830+ elif ! (( in_redirection)) && [[ $this_word == * ' :always:' * && $arg == ' always' ]]; then
831+ # try-always construct
832+ style=reserved-word # de facto a reserved word, although not de jure
833+ highlight_glob=true
834+ next_word=' :start::start_of_pipeline:' # only left brace is allowed, apparently
835+ elif ! (( in_redirection)) && [[ $this_word == * ' :start:' * ]]; then # $arg is the command word
836+ if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg ; then
837+ style=precommand
838+ () {
839+ set -- " ${(@ s.: .)precommand_options[$arg]} "
840+ flags_with_argument=$1
841+ flags_sans_argument=$2
842+ flags_solo=$3
843+ }
844+ next_word=${next_word//: regular:/ }
845+ next_word+=' :sudo_opt:'
846+ next_word+=' :start:'
847+ if [[ $arg == ' exec' ]]; then
848+ # To allow "exec 2>&1;" where there's no command word
849+ next_word+=' :regular:'
850+ fi
851+ else
852+ case $res in
853+ (reserved) # reserved word
854854 style=reserved-word
855855 # Match braces and handle special cases.
856856 case $arg in
@@ -927,15 +927,17 @@ _zsh_highlight_main_highlighter_highlight_list()
927927 ;;
928928 esac
929929 ;;
930- ' suffix alias' ) style=suffix-alias;;
931- alias) : ;;
932- builtin) style=builtin
930+ (' suffix alias' )
931+ style=suffix-alias
932+ ;;
933+ (alias) : ;;
934+ (builtin) style=builtin
933935 [[ $arg == $' \x5b ' ]] && braces_stack=' Q' " $braces_stack "
934936 ;;
935- function) style=function;;
936- command) style=command;;
937- hashed) style=hashed-command;;
938- none) if (( ! in_param )) && _zsh_highlight_main_highlighter_check_assign; then
937+ (function) style=function;;
938+ (command) style=command;;
939+ (hashed) style=hashed-command;;
940+ (none) if (( ! in_param )) && _zsh_highlight_main_highlighter_check_assign; then
939941 _zsh_highlight_main_add_region_highlight $start_pos $end_pos assign
940942 local i=$(( arg[(i)= ] + 1 ))
941943 if [[ $arg [i] == ' (' ]]; then
@@ -1004,67 +1006,70 @@ _zsh_highlight_main_highlighter_highlight_list()
10041006 fi
10051007 fi
10061008 ;;
1007- * ) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res
1009+ ( * ) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res
10081010 continue
10091011 ;;
1010- esac
1011- fi
1012- if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:# " $arg " } ]]; then
1013- next_word=' :start::start_of_pipeline:'
1014- fi
1015- else # $arg is a non-command word
1012+ esac
1013+ fi
1014+ if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:# " $arg " } ]]; then
1015+ next_word=' :start::start_of_pipeline:'
1016+ fi
1017+ else # $arg is a non-command word
10161018 case $arg in
1017- $' \x29 ' ) # subshell or end of array assignment
1018- if $in_array_assignment ; then
1019- style=assign
1020- in_array_assignment=false
1021- next_word+=' :start:'
1022- elif (( in_redirection )) ; then
1023- style=unknown-token
1024- else
1025- if _zsh_highlight_main__stack_pop ' S' ; then
1026- REPLY=$start_pos
1027- reply=($list_highlights )
1028- return 0
1029- fi
1030- _zsh_highlight_main__stack_pop ' R' reserved-word
1031- fi ;;
1032- $' \x28\x29 ' ) # possibly a function definition
1033- if (( in_redirection )) || $in_array_assignment ; then
1034- style=unknown-token
1035- else
1036- if [[ $zsyh_user_options [multifuncdef] == on ]] || false # TODO: or if the previous word was a command word
1037- then
1038- next_word+=' :start::start_of_pipeline:'
1039- fi
1040- style=reserved-word
1041- fi
1042- ;;
1043- * ) if false ; then
1044- elif [[ $arg = $' \x7d ' ]] && $right_brace_is_recognised_everywhere ; then
1045- # Parsing rule: {
1046- #
1047- # Additionally, `tt(})' is recognized in any position if neither the
1048- # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set.
1049- if (( in_redirection )) || $in_array_assignment ; then
1050- style=unknown-token
1051- else
1052- _zsh_highlight_main__stack_pop ' Y' reserved-word
1053- if [[ $style == reserved-word ]]; then
1054- next_word+=' :always:'
1055- fi
1056- fi
1057- elif [[ $arg [0,1] = $histchars [0,1] ]] && (( $# arg[0 , 2 ] == 2 )) ; then
1058- style=history-expansion
1059- elif [[ $arg == $' \x5d\x5d ' ]] && _zsh_highlight_main__stack_pop ' T' reserved-word; then
1060- :
1061- elif [[ $arg == $' \x5d ' ]] && _zsh_highlight_main__stack_pop ' Q' builtin ; then
1062- :
1063- else
1064- _zsh_highlight_main_highlighter_highlight_argument 1 $(( 1 != in_redirection ))
1065- continue
1066- fi
1067- ;;
1019+ ($' \x29 ' )
1020+ # subshell or end of array assignment
1021+ if $in_array_assignment ; then
1022+ style=assign
1023+ in_array_assignment=false
1024+ next_word+=' :start:'
1025+ elif (( in_redirection )) ; then
1026+ style=unknown-token
1027+ else
1028+ if _zsh_highlight_main__stack_pop ' S' ; then
1029+ REPLY=$start_pos
1030+ reply=($list_highlights )
1031+ return 0
1032+ fi
1033+ _zsh_highlight_main__stack_pop ' R' reserved-word
1034+ fi
1035+ ;;
1036+ ($' \x28\x29 ' )
1037+ # possibly a function definition
1038+ if (( in_redirection )) || $in_array_assignment ; then
1039+ style=unknown-token
1040+ else
1041+ if [[ $zsyh_user_options [multifuncdef] == on ]] || false # TODO: or if the previous word was a command word
1042+ then
1043+ next_word+=' :start::start_of_pipeline:'
1044+ fi
1045+ style=reserved-word
1046+ fi
1047+ ;;
1048+ (* ) if false ; then
1049+ elif [[ $arg = $' \x7d ' ]] && $right_brace_is_recognised_everywhere ; then
1050+ # Parsing rule: {
1051+ #
1052+ # Additionally, `tt(})' is recognized in any position if neither the
1053+ # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set.
1054+ if (( in_redirection )) || $in_array_assignment ; then
1055+ style=unknown-token
1056+ else
1057+ _zsh_highlight_main__stack_pop ' Y' reserved-word
1058+ if [[ $style == reserved-word ]]; then
1059+ next_word+=' :always:'
1060+ fi
1061+ fi
1062+ elif [[ $arg [0,1] = $histchars [0,1] ]] && (( $# arg[0 , 2 ] == 2 )) ; then
1063+ style=history-expansion
1064+ elif [[ $arg == $' \x5d\x5d ' ]] && _zsh_highlight_main__stack_pop ' T' reserved-word; then
1065+ :
1066+ elif [[ $arg == $' \x5d ' ]] && _zsh_highlight_main__stack_pop ' Q' builtin ; then
1067+ :
1068+ else
1069+ _zsh_highlight_main_highlighter_highlight_argument 1 $(( 1 != in_redirection ))
1070+ continue
1071+ fi
1072+ ;;
10681073 esac
10691074 fi
10701075 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
@@ -1341,14 +1346,14 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
13411346 (( j = i + start_pos - 1 ))
13421347 (( k = j + 1 ))
13431348 case " $arg [$i ]" in
1344- ' "' ) break ;;
1345- ' `' ) saved_reply=($reply )
1346- _zsh_highlight_main_highlighter_highlight_backtick $i
1347- (( i = REPLY ))
1348- reply=($saved_reply $reply )
1349- continue
1350- ;;
1351- ' $' ) style=dollar-double-quoted-argument
1349+ ( ' "' ) break ;;
1350+ ( ' `' ) saved_reply=($reply )
1351+ _zsh_highlight_main_highlighter_highlight_backtick $i
1352+ (( i = REPLY ))
1353+ reply=($saved_reply $reply )
1354+ continue
1355+ ;;
1356+ ( ' $' ) style=dollar-double-quoted-argument
13521357 # Look for an alphanumeric parameter name.
13531358 if [[ ${arg: $i } =~ ^([A-Za-z_][A-Za-z0-9_]* | [0-9]+) ]] ; then
13541359 (( k += $# MATCH )) # highlight the parameter name
0 commit comments