'main': Don't highlight arithmetic expansions as command substitutions.
This is not perfect: we don't try to detect cases such as «$((ls); (ls))», which look like arithmetic expansions but are in fact command substitutions. Fixes part of #607. Introduces #704.
This commit is contained in:
parent
2e65bb6d7d
commit
d237a60c9b
@ -38,6 +38,13 @@
|
|||||||
- Fix `echo >&2` highlighting the `2` as a filename if a file by that name happened to exist
|
- Fix `echo >&2` highlighting the `2` as a filename if a file by that name happened to exist
|
||||||
[#694]
|
[#694]
|
||||||
|
|
||||||
|
- Fix `: $((42))` being highlighted as a subshell.
|
||||||
|
[part of #607]
|
||||||
|
|
||||||
|
- Regress highlighting of `: $((ls); (ls))`: is a subshell, but will now be
|
||||||
|
incorrectly highlighted as an arithmetic expansion.
|
||||||
|
[#704]
|
||||||
|
|
||||||
# Changes in version 0.7.1
|
# Changes in version 0.7.1
|
||||||
|
|
||||||
- Remove out-of-date information from the 0.7.0 changelog.
|
- Remove out-of-date information from the 0.7.0 changelog.
|
||||||
|
@ -1222,7 +1222,8 @@ _zsh_highlight_main_highlighter_highlight_argument()
|
|||||||
(( i = REPLY ))
|
(( i = REPLY ))
|
||||||
highlights+=($reply)
|
highlights+=($reply)
|
||||||
continue
|
continue
|
||||||
elif [[ $arg[i+1] == $'\x28' ]]; then
|
elif [[ $arg[i+1] == $'\x28' && ${arg:$i} != $'\x28\x28'*$'\x29\x29'* ]]; then
|
||||||
|
# command substitution that doesn't look like an arithmetic expansion
|
||||||
start=$i
|
start=$i
|
||||||
(( i += 2 ))
|
(( i += 2 ))
|
||||||
_zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1]
|
_zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1]
|
||||||
@ -1237,6 +1238,10 @@ _zsh_highlight_main_highlighter_highlight_argument()
|
|||||||
highlights+=($(( start_pos + i - 1)) $(( start_pos + i )) command-substitution-delimiter-unquoted)
|
highlights+=($(( start_pos + i - 1)) $(( start_pos + i )) command-substitution-delimiter-unquoted)
|
||||||
fi
|
fi
|
||||||
continue
|
continue
|
||||||
|
else
|
||||||
|
# TODO: if it's an arithmetic expansion, skip past it, to prevent
|
||||||
|
# multiplications from being highlighted as globbing (issue #607,
|
||||||
|
# test-data/arith1.zsh)
|
||||||
fi
|
fi
|
||||||
while [[ $arg[i+1] == [\^=~#+] ]]; do
|
while [[ $arg[i+1] == [\^=~#+] ]]; do
|
||||||
(( i += 1 ))
|
(( i += 1 ))
|
||||||
@ -1359,7 +1364,8 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
|
|||||||
# $#, $*, $@, $?, $- - like $$ above
|
# $#, $*, $@, $?, $- - like $$ above
|
||||||
(( k += 1 )) # highlight both dollar signs
|
(( k += 1 )) # highlight both dollar signs
|
||||||
(( i += 1 )) # don't consider the second one as introducing another parameter expansion
|
(( i += 1 )) # don't consider the second one as introducing another parameter expansion
|
||||||
elif [[ $arg[i+1] == $'\x28' ]]; then
|
elif [[ $arg[i+1] == $'\x28' && ${arg:$i} != $'\x28\x28'*$'\x29\x29'* ]]; then
|
||||||
|
# command substitution that doesn't look like an arithmetic expansion
|
||||||
breaks+=( $last_break $(( start_pos + i - 1 )) )
|
breaks+=( $last_break $(( start_pos + i - 1 )) )
|
||||||
(( i += 2 ))
|
(( i += 2 ))
|
||||||
saved_reply=($reply)
|
saved_reply=($reply)
|
||||||
|
@ -33,14 +33,14 @@ BUFFER=$': $((ls); (ls))'
|
|||||||
expected_region_highlight=(
|
expected_region_highlight=(
|
||||||
'1 1 builtin' # :
|
'1 1 builtin' # :
|
||||||
'3 15 default' # $((ls); (ls))
|
'3 15 default' # $((ls); (ls))
|
||||||
'3 15 command-substitution-unquoted' # $((ls); (ls))
|
'3 15 command-substitution-unquoted "issue #704"' # $((ls); (ls))
|
||||||
'3 4 command-substitution-delimiter-unquoted' # $(
|
'3 4 command-substitution-delimiter-unquoted "issue #704"' # $(
|
||||||
'5 5 reserved-word' # (
|
'5 5 reserved-word "issue #704"' # (
|
||||||
'6 7 command' # ls
|
'6 7 command "issue #704"' # ls
|
||||||
'8 8 reserved-word' # )
|
'8 8 reserved-word "issue #704"' # )
|
||||||
'9 9 commandseparator' # ;
|
'9 9 commandseparator "issue #704"' # ;
|
||||||
'11 11 reserved-word' # (
|
'11 11 reserved-word "issue #704"' # (
|
||||||
'12 13 command' # ls
|
'12 13 command "issue #704"' # ls
|
||||||
'14 14 reserved-word' # )
|
'14 14 reserved-word "issue #704"' # )
|
||||||
'15 15 command-substitution-delimiter-unquoted' # )
|
'15 15 command-substitution-delimiter-unquoted "issue #704"' # )
|
||||||
)
|
)
|
||||||
|
37
highlighters/main/test-data/arith1.zsh
Normal file
37
highlighters/main/test-data/arith1.zsh
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2020 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=$': $(( 6 * 9 ))'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
'1 1 builtin' # :
|
||||||
|
'3 14 default' # $(( 6 * 9 ))
|
||||||
|
)
|
||||||
|
expected_mismatch="currently the actual highlighting has one superfluous group that highlights the asterisk is highlighted as 'globbing'"
|
37
highlighters/main/test-data/arith2.zsh
Normal file
37
highlighters/main/test-data/arith2.zsh
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2020 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=$': "$(( 6 * 9 ))"'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
'1 1 builtin' # :
|
||||||
|
'3 16 default' # "$(( 6 * 9 ))"
|
||||||
|
'3 16 double-quoted-argument' # "$(( 6 * 9 ))"
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user