runtime(sh): Update syntax, highlight escaped chars in test expressions Commit: https://github.com/vim/vim/commit/f57c065e7572beb2b551d1278bf794f4af0fb0c0 Author: Doug Kearns <dougkea...@gmail.com> Date: Wed Apr 30 20:04:28 2025 +0200
runtime(sh): Update syntax, highlight escaped chars in test expressions Highlight escape characters in unquoted test expression operands. E.g., [[ foo == \[bar\] ]] fixes #17221 Signed-off-by: Doug Kearns <dougkea...@gmail.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/runtime/syntax/sh.vim b/runtime/syntax/sh.vim index 9e5320f1c..f0a6685b6 100644 --- a/runtime/syntax/sh.vim +++ b/runtime/syntax/sh.vim @@ -10,6 +10,7 @@ " 2025 Mar 21 update shell capability detection (#16939) " 2025 Apr 03 command substitution opening paren at EOL (#17026) " 2025 Apr 10 improve shell detection (#17084) +" 2025 Apr 29 match escaped chars in test operands (#17221) " Version: 208 " Former URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH " For options and settings, please use: :help ft-sh-syntax @@ -306,7 +307,7 @@ syn region shSubSh transparent matchgroup=shSubShRegion start="[^(]\zs(" end=")" "======= syn region shExpr matchgroup=shRange start="\[\s\@=" skip=+\\\|\$\|\[+ end="\]" contains=@shTestList,shSpecial syn region shTest transparent matchgroup=shStatement start="\<test\s" skip=+\\\|\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=@shExprList1 -syn region shNoQuote start='\S' skip='\%(\\\)*\.' end='\ze\s' end="\ze['"]" contained contains=shBracketExpr,shDerefSimple,shDeref +syn region shNoQuote start='\S' skip='\%(\\\)*\.' end='\ze\s' end="\ze['"]" contained contains=shBracketExpr,shDerefSimple,shDeref,shEscape syn match shAstQuote contained '\*\ze"' nextgroup=shString syn match shTestOpr contained '[^-+/%]\zs=' skipwhite nextgroup=shTestDoubleQuote,shTestSingleQuote,shTestPattern syn match shTestOpr contained "<=\|>=\|!=\|==\|=\~\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!<>]" diff --git a/runtime/syntax/testdir/dumps/sh_14_00.dump b/runtime/syntax/testdir/dumps/sh_14_00.dump new file mode 100644 index 000000000..7538aae9b --- /dev/null +++ b/runtime/syntax/testdir/dumps/sh_14_00.dump @@ -0,0 +1,20 @@ +>#+0#0000e05#ffffff0|!|/|b|i|n|/|b|a|s|h| +0#0000000&@63 +|#+0#0000e05&| |I|s@1|u|e| |#|1|7|2@1|1| |(|s|h| |s|y|n|t|a|x|:| |e|s|c|a|p|e|d| |s|q|u|a|r|e| |b|r|a|c|k|e|t|s| |d|o|n|'|t| |w|o|r|k| |i|n| |[@1| |]@1|)| +0#0000000&@3 +@75 +|[+0#e000e06&@1| +0#0000000&|f+0#e000002&|o@1| +0#0000000&|=+0#af5f00255&@1| +0#0000000&|[+0#e000e06&|b+0#0000000&|a|r|]+0#e000e06&| +0#0000000&|]+0#e000e06&@1| +0#0000000&@56 +|[+0#e000e06&@1| +0#0000000&|f+0#e000002&|o@1| +0#0000000&|=+0#af5f00255&@1| +0#0000000&|\+0#e000e06&|[|b+0#e000002&|a|r|\+0#e000e06&|]| +0#0000000&|]+0#e000e06&@1| +0#0000000&@54 +@75 +|e+0#af5f00255&|c|h|o| +0#e000002&|[+0#e000e06&|f+0#0000000&|o@1|]+0#e000e06&| +0#0000000&@64 +|e+0#af5f00255&|c|h|o| +0#e000002&|\+0#e000e06&|[|f+0#e000002&|o@1|\+0#e000e06&|]| +0#0000000&@62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|i+0#0000000&|s|_|b|a|s|h|:| |1|,| @45|1|,|1| @10|A|l@1| diff --git a/runtime/syntax/testdir/input/sh_14.sh b/runtime/syntax/testdir/input/sh_14.sh new file mode 100644 index 000000000..bfa3d93a4 --- /dev/null +++ b/runtime/syntax/testdir/input/sh_14.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# Issue #17221 (sh syntax: escaped square brackets don't work in [[ ]]) + +[[ foo == [bar] ]] +[[ foo == \[bar\] ]] + +echo [foo] +echo \[foo\] -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1uABxX-00HWUZ-QB%40256bit.org.