From 02807f1826a512672764a8658de3b8a67f074c44 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 22 Sep 2016 03:38:34 +0000 Subject: [PATCH] 'main': Support the IGNORE_BRACES option. This is related to a future "unbalanced { ( ) }" check for issue #344. --- highlighters/main/main-highlighter.zsh | 20 +++++++++++++++++++- highlighters/main/test-data/braces2.zsh | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6df671e..a010b22 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -162,6 +162,11 @@ _zsh_highlight_highlighter_main_paint() if [[ -o interactive_comments ]]; then local interactive_comments= # set to empty fi + if [[ -o ignore_braces ]] || [[ -o ignore_close_braces ]]; then + local right_brace_is_recognised_everywhere=false + else + local right_brace_is_recognised_everywhere=true + fi if [[ -o path_dirs ]]; then integer path_dirs_was_set=1 else @@ -513,7 +518,18 @@ _zsh_highlight_highlighter_main_paint() else style=reserved-word fi;; - $'\x7d') style=reserved-word;; # block + $'\x7d') # right brace + # + # Parsing rule: # { + # + # Additionally, `tt(})' is recognized in any position if neither the + # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set.""" + if $right_brace_is_recognised_everywhere; then + style=reserved-word + else + # Fall through to the catchall case at the end. + fi + ;| '--'*) style=double-hyphen-option;; '-'*) style=single-hyphen-option;; "'"*) style=single-quoted-argument;; @@ -531,6 +547,8 @@ _zsh_highlight_highlighter_main_paint() [*?]*|*[^\\][*?]*) $highlight_glob && style=globbing || style=default;; *) if false; then + elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then + # was handled by the $'\x7d' case above elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then style=history-expansion elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then diff --git a/highlighters/main/test-data/braces2.zsh b/highlighters/main/test-data/braces2.zsh index 89ba15a..adee00b 100644 --- a/highlighters/main/test-data/braces2.zsh +++ b/highlighters/main/test-data/braces2.zsh @@ -36,7 +36,7 @@ expected_region_highlight=( '1 2 reserved-word' # () '4 4 reserved-word' # { '6 9 builtin' # echo - '11 11 default "ignore_braces; fixed by next commit"' # } + '11 11 default' # } '12 12 commandseparator' # \n '13 13 reserved-word' # } )