@@ -683,19 +683,7 @@ _zsh_highlight_highlighter_main_paint()
683
683
; |
684
684
' --' * ) style=double-hyphen-option;;
685
685
' -' * ) style=single-hyphen-option;;
686
- " '" * ) _zsh_highlight_main_highlighter_highlight_single_quote 1
687
- already_added=1
688
- ;;
689
- ' "' * ) _zsh_highlight_main_highlighter_highlight_double_quote
690
- already_added=1
691
- ;;
692
- \$\' * ) _zsh_highlight_main_highlighter_highlight_dollar_quote
693
- already_added=1
694
- ;;
695
686
' `' * ) style=back-quoted-argument;;
696
- [$][* ]) style=default;;
697
- [*? ]* |* [^\\ ][*? ]* )
698
- $highlight_glob && style=globbing || style=default;;
699
687
* ) if false ; then
700
688
elif [[ $arg = $' \x7d ' ]] && $right_brace_is_recognised_everywhere ; then
701
689
# was handled by the $'\x7d' case above
@@ -713,7 +701,8 @@ _zsh_highlight_highlighter_main_paint()
713
701
if _zsh_highlight_main_highlighter_check_path; then
714
702
style=$REPLY
715
703
else
716
- style=default
704
+ _zsh_highlight_main_highlighter_highlight_argument
705
+ already_added=1
717
706
fi
718
707
fi
719
708
;;
@@ -812,6 +801,41 @@ _zsh_highlight_main_highlighter_check_path()
812
801
return 1
813
802
}
814
803
804
+ # Highlight an argument and possibly special chars in quotes
805
+ _zsh_highlight_main_highlighter_highlight_argument ()
806
+ {
807
+ local i
808
+
809
+ _zsh_highlight_main_add_region_highlight $start_pos $end_pos default
810
+ for (( i = 1 ; i <= end_pos - start_pos ; i += 1 )) ; do
811
+ case " $arg [$i ]" in
812
+ " \\ " ) (( i += 1 )) ; continue ;;
813
+ " '" ) _zsh_highlight_main_highlighter_highlight_single_quote $i ; (( i = REPLY )) ;;
814
+ ' "' ) _zsh_highlight_main_highlighter_highlight_double_quote $i ; (( i = REPLY )) ;;
815
+ ' $' )
816
+ if [[ $arg [i+1] == " '" ]]; then
817
+ _zsh_highlight_main_highlighter_highlight_dollar_quote $i
818
+ (( i = REPLY ))
819
+ elif [[ $arg [i+1] == [\^ =~ # +] ]]; then
820
+ while [[ $arg [i+1] == [\^ =~ # +] ]]; do
821
+ (( i += 1 ))
822
+ done
823
+ if [[ $arg [i+1] == [* @# ?-$!] ]]; then
824
+ (( i += 1 ))
825
+ fi
826
+ elif [[ $arg [i+1] == [* @# ?-$!] ]]; then
827
+ (( i += 1 ))
828
+ fi ;;
829
+ [*? ])
830
+ if $highlight_glob ; then
831
+ _zsh_highlight_main_add_region_highlight $start_pos $end_pos globbing
832
+ break
833
+ fi ;;
834
+ * ) continue ;;
835
+ esac
836
+ done
837
+ }
838
+
815
839
# Highlight single-quoted strings
816
840
_zsh_highlight_main_highlighter_highlight_single_quote ()
817
841
{
@@ -838,11 +862,11 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
838
862
local MATCH; integer MBEGIN MEND
839
863
local i j k style
840
864
841
- # Starting quote is at 1, so start parsing at offset 2 in the string.
842
- for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do
865
+ for (( i = $1 + 1 ; i < end_pos - start_pos ; i += 1 )) ; do
843
866
(( j = i + start_pos - 1 ))
844
867
(( k = j + 1 ))
845
868
case " $arg [$i ]" in
869
+ ' "' ) break ;;
846
870
' $' ) style=dollar-double-quoted-argument
847
871
# Look for an alphanumeric parameter name.
848
872
if [[ ${arg: $i } =~ ^([A-Za-z_][A-Za-z0-9_]* | [0-9]+) ]] ; then
@@ -886,8 +910,9 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
886
910
highlights+=($j $k $style )
887
911
done
888
912
889
- highlights=($start_pos $end_pos double-quoted-argument $highlights )
913
+ highlights=($(( start_pos + $1 - 1 )) $(( start_pos + i )) double-quoted-argument $highlights )
890
914
_zsh_highlight_main_add_region_highlights $highlights
915
+ REPLY=$i
891
916
}
892
917
893
918
# Highlight special chars inside dollar-quoted strings
@@ -899,11 +924,11 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote()
899
924
local AA
900
925
integer c
901
926
902
- # Starting dollar-quote is at 1:2, so start parsing at offset 3 in the string.
903
- for (( i = 3 ; i < end_pos - start_pos ; i += 1 )) ; do
927
+ for (( i = $1 + 2 ; i < end_pos - start_pos ; i += 1 )) ; do
904
928
(( j = i + start_pos - 1 ))
905
929
(( k = j + 1 ))
906
930
case " $arg [$i ]" in
931
+ " '" ) break ;;
907
932
" \\ " ) style=back-dollar-quoted-argument
908
933
for (( c = i + 1 ; c <= end_pos - start_pos ; c += 1 )) ; do
909
934
[[ " $arg [$c ]" != ([0-9xXuUa-fA-F]) ]] && break
@@ -932,8 +957,9 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote()
932
957
highlights+=($j $k $style )
933
958
done
934
959
935
- highlights+=($start_pos $end_pos dollar-quoted-argument $highlights )
960
+ highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) dollar-quoted-argument $highlights )
936
961
_zsh_highlight_main_add_region_highlights $highlights
962
+ REPLY=$i
937
963
}
938
964
939
965
# Called with a single positional argument.
0 commit comments