runtime(sh): Update syntax, match KornShell compound arrays Commit: https://github.com/vim/vim/commit/87947a9a769ad43216beae7946c8b0bda9f8024a Author: Doug Kearns <dougkea...@gmail.com> Date: Tue May 6 17:59:25 2025 +0200
runtime(sh): Update syntax, match KornShell compound arrays closes: https://github.com/vim/vim/issues/17268 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 4add7921f..c04b16fa0 100644 --- a/runtime/syntax/sh.vim +++ b/runtime/syntax/sh.vim @@ -12,6 +12,7 @@ " 2025 Apr 10 improve shell detection (#17084) " 2025 Apr 29 match escaped chars in test operands (#17221) " 2025 May 06 improve single-quote string matching in parameter expansions +" 2025 May 06 match KornShell compound arrays " Version: 208 " Former URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH " For options and settings, please use: :help ft-sh-syntax @@ -511,13 +512,18 @@ syn match shSetOption "\s\zs[-+][a-zA-Z0-9]\+\>" contained syn match shVariable "\<\h\w*\ze=" nextgroup=shVarAssign if exists("b:is_bash") " The subscript form for array values, e.g. "foo=([2]=10 [4]=100)". - syn region shArrayValue contained start="\[\%(..\{-}\]=\)\@=" end="\]=\@=" contains=@shArrayValueList nextgroup=shVarAssign + syn region shArrayValue contained start="\[\%(..\{-}\]=\)\@=" end="\]=\@=" contains=@shArrayValueList nextgroup=shVarAssign syn cluster shArrayValueList contains=shArithmetic,shArithParen,shCommandSub,shDeref,shDerefSimple,shExpr,shNumber,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shSpecial,shParen,bashSpecialVariables,shParenError + syn region shArrayRegion contained matchgroup=shShellVariables start="(" skip='\\\|\.' end=")" contains=@shArrayValueList,shArrayValue,shComment +elseif exists("b:is_kornshell") + " The subscript form for array values, e.g. "foo=([2]=10 [4]=100)". + syn region shArrayValue contained start="\[\%(..\{-}\]=\)\@=" end="\]=\@=" contains=@shArrayValueList nextgroup=shVarAssign + syn cluster shArrayValueList contains=shArithmetic,shArithParen,shCommandSub,shDeref,shDerefSimple,shExpr,shNumber,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shSpecial,shParen,kshSpecialVariables,shParenError + syn region shArrayRegion contained matchgroup=shShellVariables start="(" skip='\\\|\.' end=")" contains=@shArrayValueList,shArrayValue,shComment,shArrayRegion endif if exists("b:is_bash") || exists("b:is_kornshell") syn match shVariable "\<\h\w*\%(\[..\{-}\]\)\=\ze\%([|^&*/%+-]\|[<^]<\|[>^]>\)\==" contains=shDerefVarArray nextgroup=shVarAssign syn match shVarAssign contained "\%([|^&*/%+-]\|[<^]<\|[>^]>\)\==" nextgroup=shArrayRegion,shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote,shVar - syn region shArrayRegion contained matchgroup=shShellVariables start="(" skip='\\\|\.' end=")" contains=@shArrayValueList,shArrayValue,shComment else syn match shVarAssign contained "=" nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote,shVar endif diff --git a/runtime/syntax/testdir/dumps/sh_ksh_array_00.dump b/runtime/syntax/testdir/dumps/sh_ksh_array_00.dump new file mode 100644 index 000000000..7d3855dc6 --- /dev/null +++ b/runtime/syntax/testdir/dumps/sh_ksh_array_00.dump @@ -0,0 +1,20 @@ +>#+0#0000e05#ffffff0|!|/|b|i|n|/|k|s|h| +0#0000000&@64 +@75 +|f+0#00e0e07&|o@1|=+0#0000000&|(+0#e000e06&| +0#0000000&@69 +@2|(+0#e000e06&| |0+0#e000002&@1| +0#e000e06&|0+0#e000002&|1| +0#e000e06&|)| +0#0000000&@63 +@2|(+0#e000e06&| |1+0#e000002&|0| +0#e000e06&|1+0#e000002&@1| +0#e000e06&|)| +0#0000000&@63 +|)+0#e000e06&| +0#0000000&@73 +@75 +|b+0#00e0e07&|a|r|=+0#0000000&|(+0#e000e06&| +0#0000000&@69 +@2|[+0#e000e06&|0+0#e000002&|]+0#e000e06&|=+0#0000000&|(+0#e000e06&| +0#0000000&@67 +@4|[+0#e000e06&|0+0#e000002&|]+0#e000e06&|=+0#0000000&|0+0#e000002&@1| +0#0000000&@64 +@4|[+0#e000e06&|1+0#e000002&|]+0#e000e06&|=+0#0000000&|0+0#e000002&|1| +0#0000000&@64 +@2|)+0#e000e06&| +0#0000000&@71 +@2|[+0#e000e06&|1+0#e000002&|]+0#e000e06&|=+0#0000000&|(+0#e000e06&| +0#0000000&@67 +@4|[+0#e000e06&|0+0#e000002&|]+0#e000e06&|=+0#0000000&|1+0#e000002&|0| +0#0000000&@64 +@4|[+0#e000e06&|1+0#e000002&|]+0#e000e06&|=+0#0000000&|1+0#e000002&@1| +0#0000000&@64 +@2|)+0#e000e06&| +0#0000000&@71 +|)+0#e000e06&| +0#0000000&@73 +@75 +@75 +|i|s|_|k|o|r|n|s|h|e|l@1|:| |1|,| @40|1|,|1| @10|T|o|p| diff --git a/runtime/syntax/testdir/dumps/sh_ksh_array_01.dump b/runtime/syntax/testdir/dumps/sh_ksh_array_01.dump new file mode 100644 index 000000000..af895cfcf --- /dev/null +++ b/runtime/syntax/testdir/dumps/sh_ksh_array_01.dump @@ -0,0 +1,20 @@ +| +0&#ffffff0@3|[+0#e000e06&|0+0#e000002&|]+0#e000e06&|=+0#0000000&|1+0#e000002&|0| +0#0000000&@64 +@4|[+0#e000e06&|1+0#e000002&|]+0#e000e06&|=+0#0000000&|1+0#e000002&@1| +0#0000000&@64 +@2|)+0#e000e06&| +0#0000000&@71 +|)+0#e000e06&| +0#0000000&@73 +@75 +> @74 +|e+0#af5f00255&|c|h|o| +0#e000002&|$+0#e000e06&|{|f|o@1|[|1+0#e000002&|]+0#e000e06&|[|1+0#e000002&|]+0#e000e06&|}| +0#e000002&|#+0#0000e05&| |=|>| |1@1| +0#0000000&@49 +|e+0#af5f00255&|c|h|o| +0#e000002&|$+0#e000e06&|{|b|a|r|[|1+0#e000002&|]+0#e000e06&|[|1+0#e000002&|]+0#e000e06&|}| +0#e000002&|#+0#0000e05&| |=|>| |1@1| +0#0000000&@49 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +| +0#0000000&@56|1|9|,|0|-|1| @7|B|o|t| diff --git a/runtime/syntax/testdir/input/sh_ksh_array.sh b/runtime/syntax/testdir/input/sh_ksh_array.sh new file mode 100755 index 000000000..22806ffc5 --- /dev/null +++ b/runtime/syntax/testdir/input/sh_ksh_array.sh @@ -0,0 +1,21 @@ +#!/bin/ksh + +foo=( + ( 00 01 ) + ( 10 11 ) +) + +bar=( + [0]=( + [0]=00 + [1]=01 + ) + [1]=( + [0]=10 + [1]=11 + ) +) + + +echo ${foo[1][1]} # => 11 +echo ${bar[1][1]} # => 11 -- -- 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/E1uCKiC-00Bi3I-GY%40256bit.org.