runtime(vim): Highlight string interpolation

Commit: 
https://github.com/vim/vim/commit/cf8695d48cdded63043430af5a84185e9614e84c
Author: thinca <[email protected]>
Date:   Sun Jan 28 18:57:23 2024 +0100

    runtime(vim): Highlight string interpolation
    
    closes: https://github.com/vim/vim/issues/13923
    
    Signed-off-by: thinca <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

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 000000000..6330599d7
--- /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 000000000..10447b8c3
--- /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 000000000..0547e9bd4
--- /dev/null
+++ b/runtime/syntax/testdir/input/vim_expr.vim
@@ -0,0 +1,14 @@
+" String
+
+echo 'It''s a string'
+echo 'tab:     , new line: 
, backslash: \'
+echo "tab:     , new line: 
, backslash: \"
+
+" String interpolation
+
+echo 'Don''t highlight interpolation: {{ {1 + 2} }}'
+echo "Don't highlight interpolation: {{ {1 + 2} }}"
+echo $'Highlight interpolation:        {{ { string({'foo': 'bar'}) } }}'
+echo $'Highlight interpolation:        {{ { $'nested: {{ {1 + 2} }}' } }}'
+echo $"Highlight interpolation:        {{ { string({"foo": "bar"}) } }}"
+echo $"Highlight interpolation:        {{ { $"nested: {{ {1 + 2} }}" } }}"
diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim
index ccbc20aa6..f1944cab8 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

-- 
-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1rU9Ry-000FoU-A7%40256bit.org.

Raspunde prin e-mail lui