Merge pull request #123 from Shura0/master

Highlighted dollar variable ver. 2
This commit is contained in:
Julien Nicoulaud 2013-08-09 00:47:32 -07:00
commit 08b80022ca

View file

@ -184,18 +184,36 @@ _zsh_highlight_main_highlighter_check_path()
_zsh_highlight_main_highlighter_highlight_string()
{
setopt localoptions noksharrays
local i j k style
local i j k style varflag
# Starting quote is at 1, so start parsing at offset 2 in the string.
for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do
(( j = i + start_pos - 1 ))
(( k = j + 1 ))
case "$arg[$i]" in
'$') style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument];;
"\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]
(( k += 1 )) # Color following char too.
(( i += 1 )) # Skip parsing the escaped char.
'$' ) style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]
(( varflag = 1))
;;
*) continue;;
"\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]
for (( c = i + 1 ; c < end_pos - start_pos ; c += 1 )); do
[[ "$arg[$c]" != ([0-9,xX,a-f,A-F]) ]] && break
done
AA=$arg[$i+1,$c-1]
# Matching for HEX and OCT values like \0xA6, \xA6 or \012
if [[ "$AA" =~ "^(0*(x|X)[0-9,a-f,A-F]{1,2})" || "$AA" =~ "^(0[0-7]{1,3})" ]];then
(( k += $#MATCH ))
(( i += $#MATCH ))
else
(( k += 1 )) # Color following char too.
(( i += 1 )) # Skip parsing the escaped char.
fi
(( varflag = 0 )) # End of variable
;;
([^a-zA-Z0-9_]))
(( varflag = 0 )) # End of variable
continue
;;
*) [[ $varflag -eq 0 ]] && continue ;;
esac
region_highlight+=("$j $k $style")
done