Skip to content

Add string interpolation syntax #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Updated vendored rescript-vscode server to `1.1.2` (see changes [here](https://github.com/rescript-lang/rescript-vscode/blob/master/CHANGELOG.md#112))
- Rename support for let-binding, types, record labels, module names etc
- **Important:** If you are using coc.nvim, make sure to upgrade to the latest `release` version first, otherwise renaming will not work across files!
- Improved syntax highlighting for string interpolation ([#44](https://github.com/rescript-lang/vim-rescript/pull/44))

## 2.0.1

Expand Down
11 changes: 11 additions & 0 deletions examples/rescript-project/src/interpolationSyntax.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let name = "Amirali"

let var = `hello ${name} how you doin?`

let var2 = j`hello ${name} how you doin?`

let var3 = j`hello $name how you doin?`

let varInvalid = `hello $name how you doin?`

let expr = `2 + 2 is ${Int.toString(2 + 2)}`
7 changes: 5 additions & 2 deletions syntax/rescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ syntax match resUnicodeChar "\v\\u[A-Fa-f0-9]\{4}" contained
syntax match resEscapedChar "\v\\[\\"'ntbrf]" contained
syntax region resString start="\v\"" end="\v\"" contains=resEscapedQuote,resEscapedChar,resUnicodeChar

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

" Polymorphic variants
syntax match resPolyVariant "\v#[A-za-z][A-Za-z0-9_'$]*"
Expand All @@ -109,6 +111,7 @@ highlight default link resModuleChain Macro
highlight default link resUnicodeChar Character
highlight default link resEscapedChar Character
highlight default link resString String
highlight default link resInterpolationDelimiters Macro
highlight default link resInterpolationVariable Macro
highlight default link resAttribute PreProc

Expand Down