Skip to content

Commit 7690aa0

Browse files
authored
Highlight improvements (#69)
* improv highlights * rename group names * add promise type * add resDelimiter * fix typo * add test * add custom operators * update CHANGELOG.md * update tests
1 parent da09408 commit 7690aa0

File tree

3 files changed

+96
-29
lines changed

3 files changed

+96
-29
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
**Improvements:**
66

77
- Improve syntax highlighting for escaped backticks in interpolated strings ([#55](https://github.com/rescript-lang/vim-rescript/pull/55))
8+
- Highlight improvements ([#69](https://github.com/rescript-lang/vim-rescript/pull/69))
89

910
## 2.1.0
1011

syntax/rescript.vim

+40-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ syntax keyword resBoolean true false
1111
" Keywords
1212
syntax keyword resKeyword let rec type external mutable lazy private of with
1313
syntax keyword resKeyword if else switch when
14-
syntax keyword resKeyword and as open include module in constraint import export
15-
syntax keyword resKeyword for to downto while
16-
syntax keyword resKeyword try catch exception assert
14+
syntax keyword resKeyword and as module constraint import export
15+
syntax keyword resInclude open include
16+
syntax keyword resRepeat for to downto while in
17+
syntax keyword resException try catch exception assert
1718
syntax keyword resKeyword async await
1819

1920
" Types
20-
syntax keyword resType bool int float char string unit
21-
syntax keyword resType list array option ref exn format
21+
syntax keyword resType bool int float char string unit promise
22+
syntax keyword resType array option ref exn format
23+
syntax match resType "list{\@!"
2224

2325
" Operators
2426
syntax keyword resOperator mod land lor lxor lsl lsr asr
@@ -44,9 +46,11 @@ syntax match resOperator "\v\>\="
4446
syntax match resOperator "\v\@"
4547

4648
syntax match resOperator "\v\!"
47-
syntax match resOperator "\v\|"
4849
syntax match resOperator "\v\&"
4950

51+
" Delimiter
52+
syntax match resDelimiter "\v\|"
53+
5054
" Refs
5155
syntax match resOperator "\v\:\="
5256

@@ -56,6 +60,9 @@ syntax match resArrowPipe "\v\-\>"
5660
syntax match resArrowPipe "\v\|\>"
5761
syntax match resArrowPipe "\v\@\@"
5862

63+
" Builtin functions
64+
syntax match resFunction "list{\@="
65+
5966
" Comment
6067
syntax region resSingleLineComment start="//" end="$" contains=resTodo,@Spell
6168
syntax region resMultiLineComment start="/\*\s*" end="\*/" contains=@Spell,resTodo,resMultiLineComment
@@ -76,7 +83,10 @@ syntax match resModuleOrVariant "\v<[A-Z][A-Za-z0-9_'$]*"
7683
syntax match resModuleChain "\v<[A-Z][A-Za-z0-9_'$]*\."
7784

7885
" Attribute
79-
syntax match resAttribute "\v\@([a-zA-z][A-Za-z0-9_']*)(\.([a-zA-z])[A-Za-z0-9_']*)*"
86+
syntax match resAttribute "\v(\@|\@\@)([a-zA-z][A-Za-z0-9_']*)(\.([a-zA-z])[A-Za-z0-9_']*)*"
87+
88+
" Extension
89+
syntax match resExtension "\v(\%|\%\%)([a-zA-z][A-Za-z0-9_']*)(\.([a-zA-z])[A-Za-z0-9_']*)*"
8090

8191
" String
8292
syntax match resUnicodeChar "\v\\u[A-Fa-f0-9]\{4}" contained
@@ -85,6 +95,9 @@ syntax match resInterpolatedStringEscapeSeq "\v\\[\\`ntbrf]" contained
8595

8696
syntax region resString start="\v\"" end="\v\"" contains=resStringEscapeSeq,resUnicodeChar
8797

98+
" Custom Operator
99+
syntax region resCustomOperator start="\v\\\"" end="\v\""
100+
88101
" Interpolation
89102
syntax match resInterpolationVariable "\v\$[a-z_][A-Za-z0-0_'$]*" contained
90103
syntax region resInterpolationBlock matchgroup=resInterpolationDelimiters start="\v\$\{" end="\v\}" contained contains=TOP
@@ -97,11 +110,27 @@ syntax match resPolyVariant "\v#[0-9]+"
97110
syntax match resPolyVariant "\v#\".*\""
98111
syntax match resPolyVariant "\v#\\\".*\""
99112

113+
" Errors
114+
syn match resBraceErr "}"
115+
syn match resBrackErr "\]"
116+
syn match resParenErr ")"
117+
syn match resArrErr "|]"
118+
119+
" Enclosing delimiters
120+
syn region resNone transparent matchgroup=resEncl start="(" matchgroup=resEncl end=")" contains=ALLBUT,resParenErr
121+
syn region resNone transparent matchgroup=resEncl start="{" matchgroup=resEncl end="}" contains=ALLBUT,resBraceErr
122+
syn region resNone transparent matchgroup=resEncl start="\[" matchgroup=resEncl end="\]" contains=ALLBUT,resBrackErr
123+
syn region resNone transparent matchgroup=resEncl start="\[|" matchgroup=resEncl end="|\]" contains=ALLBUT,resArrErr
124+
100125
highlight default link resBoolean Boolean
101126
highlight default link resKeyword Keyword
127+
highlight default link resInclude Include
128+
highlight default link resException Exception
129+
highlight default link resRepeat Repeat
102130
highlight default link resType Type
103131
highlight default link resOperator Operator
104132
highlight default link resArrowPipe Operator
133+
highlight default link resDelimiter Operator
105134
highlight default link resSingleLineComment Comment
106135
highlight default link resMultiLineComment Comment
107136
highlight default link resTodo TODO
@@ -118,5 +147,9 @@ highlight default link resString String
118147
highlight default link resInterpolationDelimiters Macro
119148
highlight default link resInterpolationVariable Macro
120149
highlight default link resAttribute PreProc
150+
highlight default link resExtension PreProc
151+
highlight default link resEncl Keyword
152+
highlight default link resFunction Function
153+
highlight default link resCustomOperator String
121154

122155
let b:current_syntax = "rescript"

test/syntax/expected/highlight.res.txt

+55-22
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
col = 1,
33
row = 0,
44
syntax = { {
5-
hl_group = "resArrowPipe",
6-
hl_group_link = "Statement"
5+
hl_group = "resAttribute",
6+
hl_group_link = "PreProc"
77
} }
88
}, {
99
col = 1,
1010
row = 3,
11-
syntax = {}
11+
syntax = { {
12+
hl_group = "resExtension",
13+
hl_group_link = "PreProc"
14+
} }
1215
}, {
1316
col = 1,
1417
row = 6,
@@ -19,7 +22,10 @@
1922
}, {
2023
col = 9,
2124
row = 8,
22-
syntax = {}
25+
syntax = { {
26+
hl_group = "resExtension",
27+
hl_group_link = "PreProc"
28+
} }
2329
}, {
2430
col = 1,
2531
row = 11,
@@ -76,7 +82,10 @@
7682
}, {
7783
col = 8,
7884
row = 32,
79-
syntax = {}
85+
syntax = { {
86+
hl_group = "resExtension",
87+
hl_group_link = "PreProc"
88+
} }
8089
}, {
8190
col = 12,
8291
row = 34,
@@ -112,24 +121,36 @@
112121
col = 7,
113122
row = 56,
114123
syntax = { {
124+
hl_group = "resNone",
125+
hl_group_link = "resNone"
126+
}, {
115127
hl_group = "resType",
116128
hl_group_link = "Type"
117129
} }
118130
}, {
119131
col = 7,
120132
row = 61,
121-
syntax = {}
133+
syntax = { {
134+
hl_group = "resNone",
135+
hl_group_link = "resNone"
136+
}, {
137+
hl_group = "resType",
138+
hl_group_link = "Type"
139+
} }
122140
}, {
123141
col = 9,
124142
row = 65,
125143
syntax = { {
126-
hl_group = "resType",
127-
hl_group_link = "Type"
144+
hl_group = "resFunction",
145+
hl_group_link = "Identifier"
128146
} }
129147
}, {
130148
col = 11,
131149
row = 68,
132-
syntax = {}
150+
syntax = { {
151+
hl_group = "resNone",
152+
hl_group_link = "resNone"
153+
} }
133154
}, {
134155
col = 9,
135156
row = 71,
@@ -159,64 +180,70 @@
159180
col = 1,
160181
row = 85,
161182
syntax = { {
162-
hl_group = "resKeyword",
183+
hl_group = "resRepeat",
163184
hl_group_link = "Statement"
164185
} }
165186
}, {
166187
col = 2,
167188
row = 87,
168189
syntax = { {
190+
hl_group = "resNone",
191+
hl_group_link = "resNone"
192+
}, {
169193
hl_group = "resModuleChain",
170194
hl_group_link = "PreProc"
171195
} }
172196
}, {
173197
col = 1,
174198
row = 91,
175199
syntax = { {
176-
hl_group = "resKeyword",
200+
hl_group = "resRepeat",
177201
hl_group_link = "Statement"
178202
} }
179203
}, {
180204
col = 1,
181205
row = 96,
182206
syntax = { {
183-
hl_group = "resKeyword",
207+
hl_group = "resException",
184208
hl_group_link = "Statement"
185209
} }
186210
}, {
187211
col = 1,
188212
row = 100,
189213
syntax = { {
190-
hl_group = "resKeyword",
214+
hl_group = "resException",
191215
hl_group_link = "Statement"
192216
} }
193217
}, {
194218
col = 3,
195219
row = 103,
196220
syntax = { {
197-
hl_group = "resKeyword",
221+
hl_group = "resException",
198222
hl_group_link = "Statement"
199223
} }
200224
}, {
201225
col = 17,
202226
row = 105,
203227
syntax = { {
204-
hl_group = "resKeyword",
228+
hl_group = "resNone",
229+
hl_group_link = "resNone"
230+
}, {
231+
hl_group = "resException",
205232
hl_group_link = "Statement"
206233
} }
207234
}, {
208235
col = 1,
209236
row = 109,
210237
syntax = { {
211-
hl_group = "resKeyword",
212-
hl_group_link = "Statement"
238+
hl_group = "resInclude",
239+
hl_group_link = "PreProc"
213240
} }
214241
}, {
215242
col = 1,
216243
row = 112,
217244
syntax = { {
218-
hl_group = "resKeyword",
219-
hl_group_link = "Statement"
245+
hl_group = "resInclude",
246+
hl_group_link = "PreProc"
220247
} }
221248
}, {
222249
col = 1,
@@ -228,11 +255,17 @@
228255
}, {
229256
col = 1,
230257
row = 118,
231-
syntax = {}
258+
syntax = { {
259+
hl_group = "resNone",
260+
hl_group_link = "resNone"
261+
} }
232262
}, {
233263
col = 5,
234264
row = 120,
235-
syntax = {}
265+
syntax = { {
266+
hl_group = "resNone",
267+
hl_group_link = "resNone"
268+
} }
236269
}, {
237270
col = 5,
238271
row = 124,
@@ -251,7 +284,7 @@
251284
col = 5,
252285
row = 128,
253286
syntax = { {
254-
hl_group = "resKeyword",
287+
hl_group = "resException",
255288
hl_group_link = "Statement"
256289
} }
257290
}, {

0 commit comments

Comments
 (0)