From 284d508ebcfabec8796e1a07afd7f9b2e0d2eb19 Mon Sep 17 00:00:00 2001 From: Amirali Esmaeili Date: Tue, 15 Jun 2021 06:21:22 +0430 Subject: [PATCH 1/3] Add string interpolation syntax --- examples/rescript-project/src/interpolationSyntax.res | 5 +++++ syntax/rescript.vim | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 examples/rescript-project/src/interpolationSyntax.res diff --git a/examples/rescript-project/src/interpolationSyntax.res b/examples/rescript-project/src/interpolationSyntax.res new file mode 100644 index 0000000..b0b27d9 --- /dev/null +++ b/examples/rescript-project/src/interpolationSyntax.res @@ -0,0 +1,5 @@ +let name = "Amirali" + +let var = `hello ${name} how you doin?` + +let expr = `2 + 2 is ${Int.toString(2 + 2)}` diff --git a/syntax/rescript.vim b/syntax/rescript.vim index bf11b29..db03a1c 100644 --- a/syntax/rescript.vim +++ b/syntax/rescript.vim @@ -82,9 +82,9 @@ 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 -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 " Polymorphic variants syntax match resPolyVariant "\v#[A-za-z][A-Za-z0-9_'$]*" @@ -109,7 +109,7 @@ highlight default link resModuleChain Macro highlight default link resUnicodeChar Character highlight default link resEscapedChar Character highlight default link resString String -highlight default link resInterpolationVariable Macro +highlight default link resInterpolationDelimiters Macro highlight default link resAttribute PreProc let b:current_syntax = "rescript" From c5f4fb18988c4fedbb57c0d46e26db05d98e955f Mon Sep 17 00:00:00 2001 From: Amirali Esmaeili Date: Wed, 7 Jul 2021 22:43:53 +0430 Subject: [PATCH 2/3] Update interpolation syntaxes --- examples/rescript-project/src/interpolationSyntax.res | 6 ++++++ syntax/rescript.vim | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/rescript-project/src/interpolationSyntax.res b/examples/rescript-project/src/interpolationSyntax.res index b0b27d9..4691fe4 100644 --- a/examples/rescript-project/src/interpolationSyntax.res +++ b/examples/rescript-project/src/interpolationSyntax.res @@ -2,4 +2,10 @@ 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)}` diff --git a/syntax/rescript.vim b/syntax/rescript.vim index db03a1c..ca2ac6c 100644 --- a/syntax/rescript.vim +++ b/syntax/rescript.vim @@ -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 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 +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_'$]*" @@ -110,6 +112,7 @@ 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 let b:current_syntax = "rescript" From 0ad64ea35158775dd60a20fd12cb59bd893352d4 Mon Sep 17 00:00:00 2001 From: Patrick Stapfer Date: Mon, 19 Jul 2021 09:07:54 +0200 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c99e577..458fb21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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