mirror of
				https://github.com/zsh-users/zsh-syntax-highlighting.git
				synced 2025-10-31 18:15:49 +00:00 
			
		
		
		
	states work: Convert $new_expression parsing.
This commit is contained in:
		
							parent
							
								
									10b1da64e6
								
							
						
					
					
						commit
						0aa6a5db78
					
				| @ -84,7 +84,7 @@ _zsh_highlight_main_highlighter() | |||||||
| { | { | ||||||
|   emulate -L zsh |   emulate -L zsh | ||||||
|   setopt localoptions extendedglob bareglobqual |   setopt localoptions extendedglob bareglobqual | ||||||
|   local start_pos=0 end_pos highlight_glob=true new_expression=true arg style |   local start_pos=0 end_pos highlight_glob=true arg style | ||||||
|   local redirection=false # true when we've seen a redirection operator before seeing the command word |   local redirection=false # true when we've seen a redirection operator before seeing the command word | ||||||
|   typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR |   typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR | ||||||
|   typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS |   typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS | ||||||
| @ -112,7 +112,7 @@ _zsh_highlight_main_highlighter() | |||||||
|     # the string's color. |     # the string's color. | ||||||
|     integer already_added=0 |     integer already_added=0 | ||||||
|     local style_override="" |     local style_override="" | ||||||
|     if $new_expression && [[ $arg = 'noglob' ]]; then |     if [[ $this_word == *':start:'* ]] && [[ $arg = 'noglob' ]]; then | ||||||
|       highlight_glob=false |       highlight_glob=false | ||||||
|     fi |     fi | ||||||
| 
 | 
 | ||||||
| @ -142,13 +142,12 @@ _zsh_highlight_main_highlighter() | |||||||
|         '-'[Cgprtu]) next_word=':sudo_arg:';; |         '-'[Cgprtu]) next_word=':sudo_arg:';; | ||||||
|         # This prevents misbehavior with sudo -u -otherargument |         # This prevents misbehavior with sudo -u -otherargument | ||||||
|         '-'*)        next_word+=':sudo_opt:';; |         '-'*)        next_word+=':sudo_opt:';; | ||||||
|         *)           this_word+=':start:'; new_expression=true;; |         *)           this_word+=':start:';; | ||||||
|       esac |       esac | ||||||
|     elif [[ $this_word == *':sudo_arg:'* ]]; then |     elif [[ $this_word == *':sudo_arg:'* ]]; then | ||||||
|       next_word+=':sudo_opt:' |       next_word+=':sudo_opt:' | ||||||
|     fi |     fi | ||||||
|     if $new_expression && ! $redirection; then # $arg is the command word |     if [[ $this_word == *':start:'* ]] && ! $redirection; then # $arg is the command word | ||||||
|       new_expression=false |  | ||||||
|      if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then |      if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then | ||||||
|       style=$ZSH_HIGHLIGHT_STYLES[precommand] |       style=$ZSH_HIGHLIGHT_STYLES[precommand] | ||||||
|      elif [[ "$arg" = "sudo" ]]; then |      elif [[ "$arg" = "sudo" ]]; then | ||||||
| @ -176,7 +175,7 @@ _zsh_highlight_main_highlighter() | |||||||
|                           if [[ $arg[-1] != '(' ]]; then |                           if [[ $arg[-1] != '(' ]]; then | ||||||
|                             # assignment to a scalar parameter. |                             # assignment to a scalar parameter. | ||||||
|                             # (For array assignments, the command doesn't start until the ")" token.) |                             # (For array assignments, the command doesn't start until the ")" token.) | ||||||
|                             new_expression=true |                             next_word+=':start:' | ||||||
|                           fi |                           fi | ||||||
|                         elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then |                         elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then | ||||||
|                           style=$ZSH_HIGHLIGHT_STYLES[history-expansion] |                           style=$ZSH_HIGHLIGHT_STYLES[history-expansion] | ||||||
| @ -209,7 +208,7 @@ _zsh_highlight_main_highlighter() | |||||||
|     else # $arg is the file target of a prefix redirection, or a non-command word |     else # $arg is the file target of a prefix redirection, or a non-command word | ||||||
|       if $redirection; then |       if $redirection; then | ||||||
|         redirection=false |         redirection=false | ||||||
|         new_expression=true |         next_word+=':start:' | ||||||
|       fi |       fi | ||||||
|       case $arg in |       case $arg in | ||||||
|         '--'*)   style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; |         '--'*)   style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; | ||||||
| @ -248,7 +247,7 @@ _zsh_highlight_main_highlighter() | |||||||
|     # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it |     # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it | ||||||
|     [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] |     [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] | ||||||
|     (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style |     (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style | ||||||
|     [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && new_expression=true |     [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && next_word+=':start:' | ||||||
|     [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true |     [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true | ||||||
|     start_pos=$end_pos |     start_pos=$end_pos | ||||||
|     this_word=$next_word |     this_word=$next_word | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Daniel Shahaf
						Daniel Shahaf