From cf8695d48cdded63043430af5a84185e9614e84c Mon Sep 17 00:00:00 2001 From: thinca Date: Sun, 28 Jan 2024 18:57:23 +0100 Subject: [PATCH] runtime(vim): Highlight string interpolation closes: #13923 Signed-off-by: thinca Signed-off-by: Christian Brabandt --- runtime/syntax/testdir/dumps/vim_expr_00.dump | 20 +++++++++++++++++++ runtime/syntax/testdir/dumps/vim_expr_99.dump | 20 +++++++++++++++++++ runtime/syntax/testdir/input/vim_expr.vim | 14 +++++++++++++ runtime/syntax/vim.vim | 7 +++++++ 4 files changed, 61 insertions(+) create mode 100644 runtime/syntax/testdir/dumps/vim_expr_00.dump create mode 100644 runtime/syntax/testdir/dumps/vim_expr_99.dump create mode 100644 runtime/syntax/testdir/input/vim_expr.vim diff --git a/runtime/syntax/testdir/dumps/vim_expr_00.dump b/runtime/syntax/testdir/dumps/vim_expr_00.dump new file mode 100644 index 0000000000000..6330599d79fe1 --- /dev/null +++ b/runtime/syntax/testdir/dumps/vim_expr_00.dump @@ -0,0 +1,20 @@ +>"+0#0000e05#ffffff0| |S|t|r|i|n|g| +0#0000000&@66 +@75 +|e+0#af5f00255&|c|h|o| +0#0000000&|'+0#e000002&|I|t|'@1|s| |a| |s|t|r|i|n|g|'| +0#0000000&@53 +|e+0#af5f00255&|c|h|o| +0#0000000&|'+0#e000002&|t|a|b|:| |\|t|,| |n|e|w| |l|i|n|e|:| |\|n|,| |b|a|c|k|s|l|a|s|h|:| |\@1|'| +0#0000000&@31 +|e+0#af5f00255&|c|h|o| +0#0000000&|"+0#e000002&|t|a|b|:| |\+0#e000e06&|t|,+0#e000002&| |n|e|w| |l|i|n|e|:| |\+0#e000e06&|n|,+0#e000002&| |b|a|c|k|s|l|a|s|h|:| |\+0#e000e06&@1|"+0#e000002&| +0#0000000&@31 +@75 +|"+0#0000e05&| |S|t|r|i|n|g| |i|n|t|e|r|p|o|l|a|t|i|o|n| +0#0000000&@52 +@75 +|e+0#af5f00255&|c|h|o| +0#0000000&|'+0#e000002&|D|o|n|'@1|t| |h|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:| |{@1| |{|1| |+| |2|}| |}@1|'| +0#0000000&@22 +|e+0#af5f00255&|c|h|o| +0#0000000&|"+0#e000002&|D|o|n|'|t| |h|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:| |{@1| |{|1| |+| |2|}| |}@1|"| +0#0000000&@23 +|e+0#af5f00255&|c|h|o| +0#0000000&|$+0#e000002&|'|H|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:|\|t|{+0#e000e06&@1| +0#e000002&|{+0#0000000&| |s+0#00e0e07&|t|r|i|n|g|(+0#e000e06&|{|'+0#e000002&|f|o@1|'|:+0#0000000&| |'+0#e000002&|b|a|r|'|}+0#e000e06&|)| +0#0000000&|}| +0#e000002&|}+0#e000e06&@1|'+0#e000002&| +0#0000000&@8 +|e+0#af5f00255&|c|h|o| +0#0000000&|$+0#e000002&|'|H|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:|\|t|{+0#e000e06&@1| +0#e000002&|{+0#0000000&| |$+0#e000002&|'|n|e|s|t|e|d|:| |{+0#e000e06&@1| +0#e000002&|{+0#0000000&|1| |++0#af5f00255&| +0#0000000&|2|}| +0#e000002&|}+0#e000e06&@1|'+0#e000002&| +0#0000000&|}| +0#e000002&|}+0#e000e06&@1|'+0#e000002&| +0#0000000&@6 +|e+0#af5f00255&|c|h|o| +0#0000000&|$+0#e000002&|"|H|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:|\+0#e000e06&|t|{@1| +0#e000002&|{+0#0000000&| |s+0#00e0e07&|t|r|i|n|g|(+0#e000e06&|{|"+0#e000002&|f|o@1|"|:+0#0000000&| |"+0#e000002&|b|a|r|"|}+0#e000e06&|)| +0#0000000&|}| +0#e000002&|}+0#e000e06&@1|"+0#e000002&| +0#0000000&@8 +|e+0#af5f00255&|c|h|o| +0#0000000&|$+0#e000002&|"|H|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:|\+0#e000e06&|t|{@1| +0#e000002&|{+0#0000000&| |$+0#e000002&|"|n|e|s|t|e|d|:| |{+0#e000e06&@1| +0#e000002&|{+0#0000000&|1| |++0#af5f00255&| +0#0000000&|2|}| +0#e000002&|}+0#e000e06&@1|"+0#e000002&| +0#0000000&|}| +0#e000002&|}+0#e000e06&@1|"+0#e000002&| +0#0000000&@6 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|"+0#0000000&|i|n|p|u|t|/|v|i|m|_|e|x|p|r|.|v|i|m|"| |1|4|L|,| |5|2@1|B| @26|1|,|1| @10|A|l@1| diff --git a/runtime/syntax/testdir/dumps/vim_expr_99.dump b/runtime/syntax/testdir/dumps/vim_expr_99.dump new file mode 100644 index 0000000000000..10447b8c35a0c --- /dev/null +++ b/runtime/syntax/testdir/dumps/vim_expr_99.dump @@ -0,0 +1,20 @@ +|"+0#0000e05#ffffff0| |S|t|r|i|n|g| +0#0000000&@66 +@75 +|e+0#af5f00255&|c|h|o| +0#0000000&|'+0#e000002&|I|t|'@1|s| |a| |s|t|r|i|n|g|'| +0#0000000&@53 +|e+0#af5f00255&|c|h|o| +0#0000000&|'+0#e000002&|t|a|b|:| |\|t|,| |n|e|w| |l|i|n|e|:| |\|n|,| |b|a|c|k|s|l|a|s|h|:| |\@1|'| +0#0000000&@31 +|e+0#af5f00255&|c|h|o| +0#0000000&|"+0#e000002&|t|a|b|:| |\+0#e000e06&|t|,+0#e000002&| |n|e|w| |l|i|n|e|:| |\+0#e000e06&|n|,+0#e000002&| |b|a|c|k|s|l|a|s|h|:| |\+0#e000e06&@1|"+0#e000002&| +0#0000000&@31 +@75 +|"+0#0000e05&| |S|t|r|i|n|g| |i|n|t|e|r|p|o|l|a|t|i|o|n| +0#0000000&@52 +@75 +|e+0#af5f00255&|c|h|o| +0#0000000&|'+0#e000002&|D|o|n|'@1|t| |h|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:| |{@1| |{|1| |+| |2|}| |}@1|'| +0#0000000&@22 +|e+0#af5f00255&|c|h|o| +0#0000000&|"+0#e000002&|D|o|n|'|t| |h|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:| |{@1| |{|1| |+| |2|}| |}@1|"| +0#0000000&@23 +|e+0#af5f00255&|c|h|o| +0#0000000&|$+0#e000002&|'|H|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:|\|t|{+0#e000e06&@1| +0#e000002&|{+0#0000000&| |s+0#00e0e07&|t|r|i|n|g|(+0#e000e06&|{|'+0#e000002&|f|o@1|'|:+0#0000000&| |'+0#e000002&|b|a|r|'|}+0#e000e06&|)| +0#0000000&|}| +0#e000002&|}+0#e000e06&@1|'+0#e000002&| +0#0000000&@8 +|e+0#af5f00255&|c|h|o| +0#0000000&|$+0#e000002&|'|H|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:|\|t|{+0#e000e06&@1| +0#e000002&|{+0#0000000&| |$+0#e000002&|'|n|e|s|t|e|d|:| |{+0#e000e06&@1| +0#e000002&|{+0#0000000&|1| |++0#af5f00255&| +0#0000000&|2|}| +0#e000002&|}+0#e000e06&@1|'+0#e000002&| +0#0000000&|}| +0#e000002&|}+0#e000e06&@1|'+0#e000002&| +0#0000000&@6 +|e+0#af5f00255&|c|h|o| +0#0000000&|$+0#e000002&|"|H|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:|\+0#e000e06&|t|{@1| +0#e000002&|{+0#0000000&| |s+0#00e0e07&|t|r|i|n|g|(+0#e000e06&|{|"+0#e000002&|f|o@1|"|:+0#0000000&| |"+0#e000002&|b|a|r|"|}+0#e000e06&|)| +0#0000000&|}| +0#e000002&|}+0#e000e06&@1|"+0#e000002&| +0#0000000&@8 +>e+0#af5f00255&|c|h|o| +0#0000000&|$+0#e000002&|"|H|i|g|h|l|i|g|h|t| |i|n|t|e|r|p|o|l|a|t|i|o|n|:|\+0#e000e06&|t|{@1| +0#e000002&|{+0#0000000&| |$+0#e000002&|"|n|e|s|t|e|d|:| |{+0#e000e06&@1| +0#e000002&|{+0#0000000&|1| |++0#af5f00255&| +0#0000000&|2|}| +0#e000002&|}+0#e000e06&@1|"+0#e000002&| +0#0000000&|}| +0#e000002&|}+0#e000e06&@1|"+0#e000002&| +0#0000000&@6 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|"+0#0000000&|i|n|p|u|t|/|v|i|m|_|e|x|p|r|.|v|i|m|"| |1|4|L|,| |5|2@1|B| @26|1|4|,|1| @9|A|l@1| diff --git a/runtime/syntax/testdir/input/vim_expr.vim b/runtime/syntax/testdir/input/vim_expr.vim new file mode 100644 index 0000000000000..0547e9bd435ea --- /dev/null +++ b/runtime/syntax/testdir/input/vim_expr.vim @@ -0,0 +1,14 @@ +" String + +echo 'It''s a string' +echo 'tab: \t, new line: \n, backslash: \\' +echo "tab: \t, new line: \n, backslash: \\" + +" String interpolation + +echo 'Don''t highlight interpolation: {{ {1 + 2} }}' +echo "Don't highlight interpolation: {{ {1 + 2} }}" +echo $'Highlight interpolation:\t{{ { string({'foo': 'bar'}) } }}' +echo $'Highlight interpolation:\t{{ { $'nested: {{ {1 + 2} }}' } }}' +echo $"Highlight interpolation:\t{{ { string({"foo": "bar"}) } }}" +echo $"Highlight interpolation:\t{{ { $"nested: {{ {1 + 2} }}" } }}" diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim index ccbc20aa63d1b..f1944cab8aa2a 100644 --- a/runtime/syntax/vim.vim +++ b/runtime/syntax/vim.vim @@ -370,6 +370,12 @@ syn match vimString contained +"[^"]*\\$+ skipnl nextgroup=vimStringCont syn match vimStringCont contained +\(\\\\\|.\)\{-}[^\\]"+ syn match vimEscape contained "\\." +syn region vimString start=+$'+ end=+'+ skip=+''+ oneline contains=vimStringInterpolationBrace,vimStringInterpolationExpr +syn region vimString start=+$"+ end=+"+ oneline contains=@vimStringGroup,vimStringInterpolationBrace,vimStringInterpolationExpr +syn region vimStringInterpolationExpr matchgroup=vimOperParen start=+{+ end=+}+ oneline contains=vimFunc,vimFuncVar,vimOper,vimNotation,vimOperParen,vimString,vimVar +syn match vimStringInterpolationBrace "{{" +syn match vimStringInterpolationBrace "}}" + " Substitutions: {{{2 " ============= syn cluster vimSubstList contains=vimPatSep,vimPatRegion,vimPatSepErr,vimSubstTwoBS,vimSubstRange,vimNotation @@ -1049,6 +1055,7 @@ if !exists("skip_vim_syntax_inits") hi def link vimStringCont vimString hi def link vimString String hi def link vimStringEnd vimString + hi def link vimStringInterpolationBrace vimEscape hi def link vimSubst1 vimSubst hi def link vimSubstDelim Delimiter hi def link vimSubstFlags Special