Merge branch 'i511-bang-pipeline'
* i511-bang-pipeline: main: Fold '!' handling in to the 'case'. No functional change. Fix indentation. No functional change. main: Fix highlighting of the ! precommand after array assignments. Add tests. main: Highlight the ! precommand as an error when not at the start of a pipeline.
This commit is contained in:
commit
4ce56a821e
@ -398,6 +398,8 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
#
|
||||
# The states are:
|
||||
# - :start: Command word
|
||||
# - :start_of_pipeline: Start of a 'pipeline' as defined in zshmisc(1).
|
||||
# Only valid when :start: is present
|
||||
# - :sudo_opt: A leading-dash option to a precommand, whether it takes an
|
||||
# argument or not. (Example: sudo's "-u" or "-i".)
|
||||
# - :sudo_arg: The argument to a precommand's leading-dash option,
|
||||
@ -431,7 +433,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
# $in_redirection. The value of $next_word from the iteration that processed
|
||||
# the operator is discarded.
|
||||
#
|
||||
local this_word next_word=':start:'
|
||||
local this_word next_word=':start::start_of_pipeline:'
|
||||
integer in_redirection
|
||||
# Processing buffer
|
||||
local proc_buf="$buf"
|
||||
@ -667,11 +669,14 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
else
|
||||
next_word=':start:'
|
||||
highlight_glob=true
|
||||
if [[ $arg != '|' && $arg != '|&' ]]; then
|
||||
next_word+=':start_of_pipeline:'
|
||||
fi
|
||||
fi
|
||||
elif ! (( in_redirection)) && [[ $this_word == *':always:'* && $arg == 'always' ]]; then
|
||||
# try-always construct
|
||||
style=reserved-word # de facto a reserved word, although not de jure
|
||||
next_word=':start:'
|
||||
next_word=':start:' # only left brace is allowed, apparently
|
||||
elif ! (( in_redirection)) && [[ $this_word == *':start:'* ]]; then # $arg is the command word
|
||||
if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then
|
||||
style=precommand
|
||||
@ -684,8 +689,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
case $res in
|
||||
reserved) # reserved word
|
||||
style=reserved-word
|
||||
#
|
||||
# Match braces.
|
||||
# Match braces and handle special cases.
|
||||
case $arg in
|
||||
($'\x7b')
|
||||
braces_stack='Y'"$braces_stack"
|
||||
@ -746,6 +750,14 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
#
|
||||
# The repeat-count word will be handled like a redirection target.
|
||||
this_word=':start::regular:'
|
||||
;;
|
||||
('!')
|
||||
if [[ $this_word != *':start_of_pipeline:'* ]]; then
|
||||
style=unknown-token
|
||||
else
|
||||
# '!' reserved word at start of pipeline; style already set above
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
'suffix alias') style=suffix-alias;;
|
||||
@ -764,6 +776,9 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
else
|
||||
# assignment to a scalar parameter.
|
||||
# (For array assignments, the command doesn't start until the ")" token.)
|
||||
#
|
||||
# Discard :start_of_pipeline:, if present, as '!' is not valid
|
||||
# after assignments.
|
||||
next_word+=':start:'
|
||||
if (( start_pos + i <= end_pos )); then
|
||||
() {
|
||||
@ -822,7 +837,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
esac
|
||||
fi
|
||||
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} ]]; then
|
||||
next_word=':start:'
|
||||
next_word=':start::start_of_pipeline:'
|
||||
fi
|
||||
else # $arg is a non-command word
|
||||
case $arg in
|
||||
@ -847,7 +862,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
else
|
||||
if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word
|
||||
then
|
||||
next_word+=':start:'
|
||||
next_word+=':start::start_of_pipeline:'
|
||||
fi
|
||||
style=reserved-word
|
||||
fi
|
||||
|
40
highlighters/main/test-data/bang-assign-array.zsh
Normal file
40
highlighters/main/test-data/bang-assign-array.zsh
Normal file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env zsh
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2018 zsh-syntax-highlighting contributors
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
# provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
||||
# and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software without specific prior
|
||||
# written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
||||
# vim: ft=zsh sw=2 ts=2 et
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
BUFFER=$'foo=(bar abaz) \! ls'
|
||||
|
||||
expected_region_highlight=(
|
||||
'1 5 assign' # foo=(
|
||||
'6 8 default' # bar
|
||||
'10 13 default' # abaz
|
||||
'14 14 assign' # )
|
||||
'16 16 unknown-token' # \!
|
||||
'18 19 command' # ls
|
||||
)
|
38
highlighters/main/test-data/bang-assign-scalar.zsh
Normal file
38
highlighters/main/test-data/bang-assign-scalar.zsh
Normal file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env zsh
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2018 zsh-syntax-highlighting contributors
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
# provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
||||
# and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software without specific prior
|
||||
# written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
||||
# vim: ft=zsh sw=2 ts=2 et
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
BUFFER=$'foo=bar \! ls'
|
||||
|
||||
expected_region_highlight=(
|
||||
'1 7 assign' # foo=bar
|
||||
'5 7 default' # bar
|
||||
'9 9 unknown-token' # \!
|
||||
'11 12 command' # ls
|
||||
)
|
39
highlighters/main/test-data/bang-pipeline.zsh
Normal file
39
highlighters/main/test-data/bang-pipeline.zsh
Normal file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env zsh
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2018 zsh-syntax-highlighting contributors
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
# provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
||||
# and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software without specific prior
|
||||
# written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
||||
# vim: ft=zsh sw=2 ts=2 et
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
BUFFER=$'\! ls | \! ls'
|
||||
|
||||
expected_region_highlight=(
|
||||
'1 1 reserved-word' # \!
|
||||
'3 4 command' # ls
|
||||
'6 6 commandseparator' # |
|
||||
'8 8 unknown-token' # \!
|
||||
'10 11 command' # ls
|
||||
)
|
Loading…
Reference in New Issue
Block a user