Skip to content

Commit b328986

Browse files
authored
Merge pull request #44 from rescript-lang/add-interpolation
Add string interpolation syntax
2 parents b8714ed + 0ad64ea commit b328986

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Updated vendored rescript-vscode server to `1.1.2` (see changes [here](https://github.com/rescript-lang/rescript-vscode/blob/master/CHANGELOG.md#112))
88
- Rename support for let-binding, types, record labels, module names etc
99
- **Important:** If you are using coc.nvim, make sure to upgrade to the latest `release` version first, otherwise renaming will not work across files!
10+
- Improved syntax highlighting for string interpolation ([#44](https://github.com/rescript-lang/vim-rescript/pull/44))
1011

1112
## 2.0.1
1213

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let name = "Amirali"
2+
3+
let var = `hello ${name} how you doin?`
4+
5+
let var2 = j`hello ${name} how you doin?`
6+
7+
let var3 = j`hello $name how you doin?`
8+
9+
let varInvalid = `hello $name how you doin?`
10+
11+
let expr = `2 + 2 is ${Int.toString(2 + 2)}`

syntax/rescript.vim

+5-2
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ syntax match resUnicodeChar "\v\\u[A-Fa-f0-9]\{4}" contained
8282
syntax match resEscapedChar "\v\\[\\"'ntbrf]" contained
8383
syntax region resString start="\v\"" end="\v\"" contains=resEscapedQuote,resEscapedChar,resUnicodeChar
8484

85+
" Interpolation
8586
syntax match resInterpolationVariable "\v\$[a-z_][A-Za-z0-0_'$]*" contained
86-
syntax region resString start="\v`" end="\v`" contains=resInterpolationVariable
87-
syntax region resString start="\v[a-z]`" end="\v`" contains=resInterpolationVariable
87+
syntax region resInterpolationBlock matchgroup=resInterpolationDelimiters start="\v\$\{" end="\v\}" contained contains=TOP
88+
syntax region resString start="\v`" end="\v`" contains=resInterpolationBlock
89+
syntax region resString start="\v[a-z]`" end="\v`" contains=resInterpolationBlock,resInterpolationVariable
8890

8991
" Polymorphic variants
9092
syntax match resPolyVariant "\v#[A-za-z][A-Za-z0-9_'$]*"
@@ -109,6 +111,7 @@ highlight default link resModuleChain Macro
109111
highlight default link resUnicodeChar Character
110112
highlight default link resEscapedChar Character
111113
highlight default link resString String
114+
highlight default link resInterpolationDelimiters Macro
112115
highlight default link resInterpolationVariable Macro
113116
highlight default link resAttribute PreProc
114117

0 commit comments

Comments
 (0)