From 5d5183ebe4647e3ccdf140af8d0ca055e627a23c Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 24 Apr 2023 22:42:51 -0300 Subject: [PATCH 1/9] improv highlights --- syntax/rescript.vim | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/syntax/rescript.vim b/syntax/rescript.vim index 0df542e..e182a7f 100644 --- a/syntax/rescript.vim +++ b/syntax/rescript.vim @@ -18,7 +18,8 @@ syntax keyword resKeyword async await " Types syntax keyword resType bool int float char string unit -syntax keyword resType list array option ref exn format +syntax keyword resType array option ref exn format +syntax match resType "list{\@!" " Operators syntax keyword resOperator mod land lor lxor lsl lsr asr @@ -56,6 +57,9 @@ syntax match resArrowPipe "\v\-\>" syntax match resArrowPipe "\v\|\>" syntax match resArrowPipe "\v\@\@" +" Builtion fucntions +syntax match resFunction "list{\@=" + " Comment syntax region resSingleLineComment start="//" end="$" contains=resTodo,@Spell syntax region resMultiLineComment start="/\*\s*" end="\*/" contains=@Spell,resTodo,resMultiLineComment @@ -76,7 +80,10 @@ syntax match resModuleOrVariant "\v<[A-Z][A-Za-z0-9_'$]*" syntax match resModuleChain "\v<[A-Z][A-Za-z0-9_'$]*\." " Attribute -syntax match resAttribute "\v\@([a-zA-z][A-Za-z0-9_']*)(\.([a-zA-z])[A-Za-z0-9_']*)*" +syntax match resAttribute "\v(\@|\@\@)([a-zA-z][A-Za-z0-9_']*)(\.([a-zA-z])[A-Za-z0-9_']*)*" + +" Extension +syntax match resExtension "\v(\%|\%\%)([a-zA-z][A-Za-z0-9_']*)(\.([a-zA-z])[A-Za-z0-9_']*)*" " String syntax match resUnicodeChar "\v\\u[A-Fa-f0-9]\{4}" contained @@ -97,6 +104,18 @@ syntax match resPolyVariant "\v#[0-9]+" syntax match resPolyVariant "\v#\".*\"" syntax match resPolyVariant "\v#\\\".*\"" +" Errors +syn match resBraceErr "}" +syn match resBrackErr "\]" +syn match resParenErr ")" +syn match resArrErr "|]" + +" Enclosing delimiters +syn region resNone transparent matchgroup=resEncl start="(" matchgroup=resEncl end=")" contains=ALLBUT,resParenErr +syn region resNone transparent matchgroup=resEncl start="{" matchgroup=resEncl end="}" contains=ALLBUT,resBraceErr +syn region resNone transparent matchgroup=resEncl start="\[" matchgroup=resEncl end="\]" contains=ALLBUT,resBrackErr +syn region resNone transparent matchgroup=resEncl start="\[|" matchgroup=resEncl end="|\]" contains=ALLBUT,resArrErr + highlight default link resBoolean Boolean highlight default link resKeyword Keyword highlight default link resType Type @@ -118,5 +137,8 @@ highlight default link resString String highlight default link resInterpolationDelimiters Macro highlight default link resInterpolationVariable Macro highlight default link resAttribute PreProc +highlight default link resExtension PreProc +highlight default link resEncl Keyword +highlight default link resFunction Function let b:current_syntax = "rescript" From 21e2447ddab6bb0645ad47e51ab09138c1b67302 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 24 Apr 2023 23:39:42 -0300 Subject: [PATCH 2/9] rename group names --- syntax/rescript.vim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/syntax/rescript.vim b/syntax/rescript.vim index e182a7f..d4d6230 100644 --- a/syntax/rescript.vim +++ b/syntax/rescript.vim @@ -11,9 +11,10 @@ syntax keyword resBoolean true false " Keywords syntax keyword resKeyword let rec type external mutable lazy private of with syntax keyword resKeyword if else switch when -syntax keyword resKeyword and as open include module in constraint import export -syntax keyword resKeyword for to downto while -syntax keyword resKeyword try catch exception assert +syntax keyword resKeyword and as module in constraint import export +syntax keyword resInclude open include +syntax keyword resRepeat for to downto while +syntax keyword resException try catch exception assert syntax keyword resKeyword async await " Types @@ -118,6 +119,9 @@ syn region resNone transparent matchgroup=resEncl start="\[|" matchgroup=resEn highlight default link resBoolean Boolean highlight default link resKeyword Keyword +highlight default link resInclude Include +highlight default link resException Exception +highlight default link resRepeat Repeat highlight default link resType Type highlight default link resOperator Operator highlight default link resArrowPipe Operator From 2d203a347c55627eb712b223149c01c3654fcd1c Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 24 Apr 2023 23:45:56 -0300 Subject: [PATCH 3/9] add promise type --- syntax/rescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/rescript.vim b/syntax/rescript.vim index d4d6230..dcb7f3d 100644 --- a/syntax/rescript.vim +++ b/syntax/rescript.vim @@ -18,7 +18,7 @@ syntax keyword resException try catch exception assert syntax keyword resKeyword async await " Types -syntax keyword resType bool int float char string unit +syntax keyword resType bool int float char string unit promise syntax keyword resType array option ref exn format syntax match resType "list{\@!" From f32f87ea58da05dfa84269aaa8ba406ef0f8c479 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 24 Apr 2023 23:47:18 -0300 Subject: [PATCH 4/9] add resDelimiter --- syntax/rescript.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/syntax/rescript.vim b/syntax/rescript.vim index dcb7f3d..a08468d 100644 --- a/syntax/rescript.vim +++ b/syntax/rescript.vim @@ -46,9 +46,11 @@ syntax match resOperator "\v\>\=" syntax match resOperator "\v\@" syntax match resOperator "\v\!" -syntax match resOperator "\v\|" syntax match resOperator "\v\&" +" Delimiter +syntax match resDelimiter "\v\|" + " Refs syntax match resOperator "\v\:\=" @@ -125,6 +127,7 @@ highlight default link resRepeat Repeat highlight default link resType Type highlight default link resOperator Operator highlight default link resArrowPipe Operator +highlight default link resDelimiter Operator highlight default link resSingleLineComment Comment highlight default link resMultiLineComment Comment highlight default link resTodo TODO From 78b15c02bd649e5794f639234e417b4950548cc8 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Tue, 25 Apr 2023 18:30:15 -0300 Subject: [PATCH 5/9] fix typo --- syntax/rescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/rescript.vim b/syntax/rescript.vim index a08468d..c143f5d 100644 --- a/syntax/rescript.vim +++ b/syntax/rescript.vim @@ -60,7 +60,7 @@ syntax match resArrowPipe "\v\-\>" syntax match resArrowPipe "\v\|\>" syntax match resArrowPipe "\v\@\@" -" Builtion fucntions +" Builtin functions syntax match resFunction "list{\@=" " Comment From ab611f1a221917160c013666cad8cd18191ac31b Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Fri, 28 Apr 2023 18:18:15 -0300 Subject: [PATCH 6/9] add test --- syntax/rescript.vim | 4 ++-- test/fixtures/highlights.res | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/highlights.res diff --git a/syntax/rescript.vim b/syntax/rescript.vim index c143f5d..ba70fc2 100644 --- a/syntax/rescript.vim +++ b/syntax/rescript.vim @@ -11,9 +11,9 @@ syntax keyword resBoolean true false " Keywords syntax keyword resKeyword let rec type external mutable lazy private of with syntax keyword resKeyword if else switch when -syntax keyword resKeyword and as module in constraint import export +syntax keyword resKeyword and as module constraint import export syntax keyword resInclude open include -syntax keyword resRepeat for to downto while +syntax keyword resRepeat for to downto while in syntax keyword resException try catch exception assert syntax keyword resKeyword async await diff --git a/test/fixtures/highlights.res b/test/fixtures/highlights.res new file mode 100644 index 0000000..a9b1cd7 --- /dev/null +++ b/test/fixtures/highlights.res @@ -0,0 +1,42 @@ +@@warning("-27") + +%%raw(`console.log("Hello")`) + +let a = %re("/b/g") + +@deprecated +let a = %raw(`1`) + +type t = {a: list, b: promise} + +let a = list{1, 2, 3} + +let arr = [1, 2, 3] + +open Js + +if true { + "Good morning!" +} else { + "Hello!" +} + +for i in 1 to 10 { + Js.log(i) +} + +for x in 3 downto 1 { + Js.log(x) +} + +while true { + Js.log(true) +} + +exception InputClosed(string) + +try { + someJSFunctionThatThrows() +} catch { +| Not_found => assert false +} From f0369909611fbe776e92b5796487b4d8bdb6f69c Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Thu, 9 Nov 2023 20:38:38 -0300 Subject: [PATCH 7/9] add custom operators --- syntax/rescript.vim | 4 ++++ test/fixtures/highlights.res | 42 ------------------------------------ 2 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 test/fixtures/highlights.res diff --git a/syntax/rescript.vim b/syntax/rescript.vim index ba70fc2..4cfdfd0 100644 --- a/syntax/rescript.vim +++ b/syntax/rescript.vim @@ -95,6 +95,9 @@ syntax match resInterpolatedStringEscapeSeq "\v\\[\\`ntbrf]" contained syntax region resString start="\v\"" end="\v\"" contains=resStringEscapeSeq,resUnicodeChar +" Custom Operator +syntax region resCustomOperator start="\v\\\"" end="\v\"" + " Interpolation syntax match resInterpolationVariable "\v\$[a-z_][A-Za-z0-0_'$]*" contained syntax region resInterpolationBlock matchgroup=resInterpolationDelimiters start="\v\$\{" end="\v\}" contained contains=TOP @@ -147,5 +150,6 @@ highlight default link resAttribute PreProc highlight default link resExtension PreProc highlight default link resEncl Keyword highlight default link resFunction Function +highlight default link resCustomOperator String let b:current_syntax = "rescript" diff --git a/test/fixtures/highlights.res b/test/fixtures/highlights.res deleted file mode 100644 index a9b1cd7..0000000 --- a/test/fixtures/highlights.res +++ /dev/null @@ -1,42 +0,0 @@ -@@warning("-27") - -%%raw(`console.log("Hello")`) - -let a = %re("/b/g") - -@deprecated -let a = %raw(`1`) - -type t = {a: list, b: promise} - -let a = list{1, 2, 3} - -let arr = [1, 2, 3] - -open Js - -if true { - "Good morning!" -} else { - "Hello!" -} - -for i in 1 to 10 { - Js.log(i) -} - -for x in 3 downto 1 { - Js.log(x) -} - -while true { - Js.log(true) -} - -exception InputClosed(string) - -try { - someJSFunctionThatThrows() -} catch { -| Not_found => assert false -} From fe9747ebd4abd849c58162e29907c19a7031a6ba Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Thu, 9 Nov 2023 20:41:19 -0300 Subject: [PATCH 8/9] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f27f238..262b8ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ **Improvements:** - Improve syntax highlighting for escaped backticks in interpolated strings ([#55](https://github.com/rescript-lang/vim-rescript/pull/55)) +- Highlight improvements ([#69](https://github.com/rescript-lang/vim-rescript/pull/69)) ## 2.1.0 From ed462bbad53d0eb4ae2183ae3202e69fd02fe02c Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Fri, 10 Nov 2023 12:13:46 -0300 Subject: [PATCH 9/9] update tests --- test/syntax/expected/highlight.res.txt | 77 ++++++++++++++++++-------- 1 file changed, 55 insertions(+), 22 deletions(-) diff --git a/test/syntax/expected/highlight.res.txt b/test/syntax/expected/highlight.res.txt index 3446a6e..29e93cc 100644 --- a/test/syntax/expected/highlight.res.txt +++ b/test/syntax/expected/highlight.res.txt @@ -2,13 +2,16 @@ col = 1, row = 0, syntax = { { - hl_group = "resArrowPipe", - hl_group_link = "Statement" + hl_group = "resAttribute", + hl_group_link = "PreProc" } } }, { col = 1, row = 3, - syntax = {} + syntax = { { + hl_group = "resExtension", + hl_group_link = "PreProc" + } } }, { col = 1, row = 6, @@ -19,7 +22,10 @@ }, { col = 9, row = 8, - syntax = {} + syntax = { { + hl_group = "resExtension", + hl_group_link = "PreProc" + } } }, { col = 1, row = 11, @@ -76,7 +82,10 @@ }, { col = 8, row = 32, - syntax = {} + syntax = { { + hl_group = "resExtension", + hl_group_link = "PreProc" + } } }, { col = 12, row = 34, @@ -112,24 +121,36 @@ col = 7, row = 56, syntax = { { + hl_group = "resNone", + hl_group_link = "resNone" + }, { hl_group = "resType", hl_group_link = "Type" } } }, { col = 7, row = 61, - syntax = {} + syntax = { { + hl_group = "resNone", + hl_group_link = "resNone" + }, { + hl_group = "resType", + hl_group_link = "Type" + } } }, { col = 9, row = 65, syntax = { { - hl_group = "resType", - hl_group_link = "Type" + hl_group = "resFunction", + hl_group_link = "Identifier" } } }, { col = 11, row = 68, - syntax = {} + syntax = { { + hl_group = "resNone", + hl_group_link = "resNone" + } } }, { col = 9, row = 71, @@ -159,13 +180,16 @@ col = 1, row = 85, syntax = { { - hl_group = "resKeyword", + hl_group = "resRepeat", hl_group_link = "Statement" } } }, { col = 2, row = 87, syntax = { { + hl_group = "resNone", + hl_group_link = "resNone" + }, { hl_group = "resModuleChain", hl_group_link = "PreProc" } } @@ -173,50 +197,53 @@ col = 1, row = 91, syntax = { { - hl_group = "resKeyword", + hl_group = "resRepeat", hl_group_link = "Statement" } } }, { col = 1, row = 96, syntax = { { - hl_group = "resKeyword", + hl_group = "resException", hl_group_link = "Statement" } } }, { col = 1, row = 100, syntax = { { - hl_group = "resKeyword", + hl_group = "resException", hl_group_link = "Statement" } } }, { col = 3, row = 103, syntax = { { - hl_group = "resKeyword", + hl_group = "resException", hl_group_link = "Statement" } } }, { col = 17, row = 105, syntax = { { - hl_group = "resKeyword", + hl_group = "resNone", + hl_group_link = "resNone" + }, { + hl_group = "resException", hl_group_link = "Statement" } } }, { col = 1, row = 109, syntax = { { - hl_group = "resKeyword", - hl_group_link = "Statement" + hl_group = "resInclude", + hl_group_link = "PreProc" } } }, { col = 1, row = 112, syntax = { { - hl_group = "resKeyword", - hl_group_link = "Statement" + hl_group = "resInclude", + hl_group_link = "PreProc" } } }, { col = 1, @@ -228,11 +255,17 @@ }, { col = 1, row = 118, - syntax = {} + syntax = { { + hl_group = "resNone", + hl_group_link = "resNone" + } } }, { col = 5, row = 120, - syntax = {} + syntax = { { + hl_group = "resNone", + hl_group_link = "resNone" + } } }, { col = 5, row = 124, @@ -251,7 +284,7 @@ col = 5, row = 128, syntax = { { - hl_group = "resKeyword", + hl_group = "resException", hl_group_link = "Statement" } } }, {