Skip to content

Commit

Permalink
runtime(vim): Highlight string interpolation
Browse files Browse the repository at this point in the history
closes: #13923

Signed-off-by: thinca <thinca@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
  • Loading branch information
thinca authored and chrisbra committed Jan 28, 2024
1 parent 21ce159 commit cf8695d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 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|
20 changes: 20 additions & 0 deletions 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|
14 changes: 14 additions & 0 deletions 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} }}" } }}"
7 changes: 7 additions & 0 deletions runtime/syntax/vim.vim
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cf8695d

Please sign in to comment.