*highlight: Correctly highlight complex [[ conditions

This commit is contained in:
Sebastian Gniazdowski 2018-03-17 07:49:00 +01:00
parent 6763e91914
commit 517ae74172

View file

@ -415,6 +415,8 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
braces_stack[1]="" braces_stack[1]=""
style=reserved-word style=reserved-word
(( next_word = next_word | 16 )) (( next_word = next_word | 16 ))
elif [[ $arg == "[[" ]]; then
braces_stack='A'"$braces_stack"
fi fi
;; ;;
'suffix alias') style=suffix-alias;; 'suffix alias') style=suffix-alias;;
@ -500,10 +502,16 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
case $arg in case $arg in
']]') ']]')
style=reserved-word style=reserved-word
[[ $braces_stack[1] == "A" ]] && braces_stack[1]=""
;; ;;
']') ']')
style=builtin style=builtin
;; ;;
$'\x28')
# '(' inside [[
style=reserved-word
braces_stack='R'"$braces_stack"
;;
$'\x29') # subshell or end of array assignment $'\x29') # subshell or end of array assignment
if (( in_array_assignment )); then if (( in_array_assignment )); then
style=assign style=assign
@ -584,6 +592,8 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
if [[ $arg == ';' ]] && (( in_array_assignment )); then if [[ $arg == ';' ]] && (( in_array_assignment )); then
# literal newline inside an array assignment # literal newline inside an array assignment
(( next_word = 2 )) (( next_word = 2 ))
elif [[ -n "${braces_stack[(r)A]}" ]]; then
(( next_word = 2 ))
else else
(( next_word = 1 )) (( next_word = 1 ))
highlight_glob=1 highlight_glob=1
@ -606,6 +616,8 @@ __HSMW_HIGHLIGHT_TOKENS_TYPES=(
# This is the default/common codepath. # This is the default/common codepath.
(( in_redirection == 0 )) && (( this_word = next_word )) #else # Stall $this_word. (( in_redirection == 0 )) && (( this_word = next_word )) #else # Stall $this_word.
done done
return 0
} }
# Check if $arg is a path. # Check if $arg is a path.