main: Simplify interface to __stack_pop

This commit is contained in:
Matthew Martin 2018-03-10 14:31:15 -06:00
parent b1eb0358fa
commit 49cc5e25b8
1 changed files with 15 additions and 10 deletions

View File

@ -198,13 +198,18 @@ _zsh_highlight_main__resolve_alias() {
# the style according to $2; otherwise, set style=unknown-token. # the style according to $2; otherwise, set style=unknown-token.
# #
# $1: character expected to be at the top of $braces_stack # $1: character expected to be at the top of $braces_stack
# $2: assignment to execute it if matches # $2: optional assignment to style it if matches
# return value is 0 if there is a match else 1
_zsh_highlight_main__stack_pop() { _zsh_highlight_main__stack_pop() {
if [[ $braces_stack[1] == $1 ]]; then if [[ $braces_stack[1] == $1 ]]; then
braces_stack=${braces_stack:1} braces_stack=${braces_stack:1}
eval "$2" if (( $+2 )); then
style=$2
fi
return 0
else else
style=unknown-token style=unknown-token
return 1
fi fi
} }
@ -512,7 +517,7 @@ _zsh_highlight_highlighter_main_paint()
;; ;;
($'\x7d') ($'\x7d')
# We're at command word, so no need to check $right_brace_is_recognised_everywhere # We're at command word, so no need to check $right_brace_is_recognised_everywhere
_zsh_highlight_main__stack_pop 'Y' style=reserved-word _zsh_highlight_main__stack_pop 'Y' reserved-word
if [[ $style == reserved-word ]]; then if [[ $style == reserved-word ]]; then
next_word+=':always:' next_word+=':always:'
fi fi
@ -521,13 +526,13 @@ _zsh_highlight_highlighter_main_paint()
braces_stack='D'"$braces_stack" braces_stack='D'"$braces_stack"
;; ;;
('done') ('done')
_zsh_highlight_main__stack_pop 'D' style=reserved-word _zsh_highlight_main__stack_pop 'D' reserved-word
;; ;;
('if') ('if')
braces_stack=':?'"$braces_stack" braces_stack=':?'"$braces_stack"
;; ;;
('then') ('then')
_zsh_highlight_main__stack_pop ':' style=reserved-word _zsh_highlight_main__stack_pop ':' reserved-word
;; ;;
('elif') ('elif')
if [[ ${braces_stack[1]} == '?' ]]; then if [[ ${braces_stack[1]} == '?' ]]; then
@ -544,13 +549,13 @@ _zsh_highlight_highlighter_main_paint()
fi fi
;; ;;
('fi') ('fi')
_zsh_highlight_main__stack_pop '?' "" _zsh_highlight_main__stack_pop '?'
;; ;;
('foreach') ('foreach')
braces_stack='$'"$braces_stack" braces_stack='$'"$braces_stack"
;; ;;
('end') ('end')
_zsh_highlight_main__stack_pop '$' style=reserved-word _zsh_highlight_main__stack_pop '$' reserved-word
;; ;;
esac esac
;; ;;
@ -633,7 +638,7 @@ _zsh_highlight_highlighter_main_paint()
braces_stack='R'"$braces_stack" braces_stack='R'"$braces_stack"
elif [[ $arg == $'\x29' ]]; then elif [[ $arg == $'\x29' ]]; then
# end of subshell # end of subshell
_zsh_highlight_main__stack_pop 'R' style=reserved-word _zsh_highlight_main__stack_pop 'R' reserved-word
else else
if _zsh_highlight_main_highlighter_check_path; then if _zsh_highlight_main_highlighter_check_path; then
style=$REPLY style=$REPLY
@ -658,7 +663,7 @@ _zsh_highlight_highlighter_main_paint()
in_array_assignment=false in_array_assignment=false
next_word+=':start:' next_word+=':start:'
else else
_zsh_highlight_main__stack_pop 'R' style=reserved-word _zsh_highlight_main__stack_pop 'R' reserved-word
fi;; fi;;
$'\x28\x29') # possibly a function definition $'\x28\x29') # possibly a function definition
if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word
@ -673,7 +678,7 @@ _zsh_highlight_highlighter_main_paint()
# #
# Additionally, `tt(})' is recognized in any position if neither the # Additionally, `tt(})' is recognized in any position if neither the
# tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set. # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set.
_zsh_highlight_main__stack_pop 'Y' style=reserved-word _zsh_highlight_main__stack_pop 'Y' reserved-word
if [[ $style == reserved-word ]]; then if [[ $style == reserved-word ]]; then
next_word+=':always:' next_word+=':always:'
fi fi