Skip to content
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

Highlight improvements #69

Merged
merged 10 commits into from
Nov 10, 2023
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 @@ -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

Expand Down
47 changes: 40 additions & 7 deletions syntax/rescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ 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 constraint import export
syntax keyword resInclude open include
syntax keyword resRepeat for to downto while in
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 list array option ref exn format
syntax keyword resType bool int float char string unit promise
syntax keyword resType array option ref exn format
syntax match resType "list{\@!"

" Operators
syntax keyword resOperator mod land lor lxor lsl lsr asr
Expand All @@ -44,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\:\="

Expand All @@ -56,6 +60,9 @@ syntax match resArrowPipe "\v\-\>"
syntax match resArrowPipe "\v\|\>"
syntax match resArrowPipe "\v\@\@"

" Builtin functions
syntax match resFunction "list{\@="

" Comment
syntax region resSingleLineComment start="//" end="$" contains=resTodo,@Spell
syntax region resMultiLineComment start="/\*\s*" end="\*/" contains=@Spell,resTodo,resMultiLineComment
Expand All @@ -76,7 +83,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
Expand All @@ -85,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
Expand All @@ -97,11 +110,27 @@ 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 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
highlight default link resDelimiter Operator
highlight default link resSingleLineComment Comment
highlight default link resMultiLineComment Comment
highlight default link resTodo TODO
Expand All @@ -118,5 +147,9 @@ 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
highlight default link resCustomOperator String

let b:current_syntax = "rescript"
77 changes: 55 additions & 22 deletions test/syntax/expected/highlight.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,7 +22,10 @@
}, {
col = 9,
row = 8,
syntax = {}
syntax = { {
hl_group = "resExtension",
hl_group_link = "PreProc"
} }
}, {
col = 1,
row = 11,
Expand Down Expand Up @@ -76,7 +82,10 @@
}, {
col = 8,
row = 32,
syntax = {}
syntax = { {
hl_group = "resExtension",
hl_group_link = "PreProc"
} }
}, {
col = 12,
row = 34,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -159,64 +180,70 @@
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"
} }
}, {
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,
Expand All @@ -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,
Expand All @@ -251,7 +284,7 @@
col = 5,
row = 128,
syntax = { {
hl_group = "resKeyword",
hl_group = "resException",
hl_group_link = "Statement"
} }
}, {
Expand Down
Loading