-
Notifications
You must be signed in to change notification settings - Fork 3
/
ReScript.sublime-syntax
302 lines (273 loc) · 8.26 KB
/
ReScript.sublime-syntax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
%YAML 1.2
---
name: ReScript
file_extensions: [res, resi]
scope: source.res
variables:
# copied over from reason-highlightjs
# TODO: \"foo" ident
RE_IDENT: '[a-z_][0-9a-zA-Z_]*'
RE_ATTRIBUTE: '[A-Za-z_][A-Za-z0-9_\.]*'
RE_MODULE_IDENT: '[A-Z_][0-9a-zA-Z_]*'
# slightly different than reason-highlightjs
RE_KEYWORDS:
\b(and|as|assert|constraint|downto|else|exception|external|false|for|if|in|include|lazy|let|module|mutable|of|open|rec|switch|to|true|try|type|when|while|with)\b
RE_LITERAL: \b(true|false)\b
contexts:
commentLine:
- match: //
scope: punctuation.definition.comment
push:
- meta_scope: comment.line
- match: \n
pop: true
commentBlock:
- match: /\*
scope: punctuation.definition.comment.begin
push:
- meta_scope: comment.block
- include: commentBlock
- match: \*/
scope: punctuation.definition.comment.end
pop: true
punctuations:
- match: \~
scope: punctuation.definition.keyword
- match: ;
scope: punctuation.terminator
- match: \.
scope: punctuation.accessor
- match: \,
scope: punctuation.separator
# covers ternary. Wrong category but whatever
- match: '\?|:'
scope: punctuation.separator
- match: \|(?!\|)
scope: punctuation.separator
- match: \{
scope: punctuation.section.braces.begin
- match: \}
scope: punctuation.section.braces.end
- match: \(
scope: punctuation.section.parens.begin
- match: \)
scope: punctuation.section.parens.end
storage:
- match: \btype\b
scope: storage.type
keyword:
- match: '{{RE_KEYWORDS}}'
scope: keyword
constant:
- match: '{{RE_LITERAL}}'
scope: constant.language
string:
- match: '"'
scope: punctuation.definition.string.begin
push:
- meta_scope: string.quoted.double
- match: \\.
scope: constant.character.escape
- match: '"'
scope: punctuation.definition.string.end
pop: true
- match: '({{RE_IDENT}})?(`)'
captures:
1: variable.annotation
2: punctuation.definition.string.begin
push:
# different than reason-highlightjs, for now
# interpolation
- meta_scope: string.quoted.other
- match: \${
scope: punctuation.section.interpolation.begin
push:
- clear_scopes: 1
- match: \}
scope: punctuation.section.interpolation.end
pop: true
# TODO: will need expression
- include: operator
- include: punctuations
- include: string
- match: '`'
scope: punctuation.definition.string.end
pop: true
function:
- match: =>
# first one is apparently for backward-compat
scope: storage.type.function keyword.declaration.function
character:
- match: '''[\x00-\x7F]'''
scope: string.quoted.single
typeParameter:
- match: '''[A-Za-z][A-Za-z0-9_]*'
scope: support.type
number:
- match:
\b(0[xX][a-fA-F0-9_]+[Lln]?|0[oO][0-7_]+[Lln]?|0[bB][01_]+[Lln]?|[0-9][0-9_]*([Lln]|(\.[0-9_]+)?([eE][-+]?[0-9_]+)?)?)\b
scope: constant.numeric
operator:
- match:
'->|\|\||&&|\+\+|\*\*|\+\.|\+|-\.|-|\*\.|\*|/\.|/|\.\.\.|\.\.|\|===|==|\^|:=|!|>=(?! *\?)|<=|='
# gotta add `keyword` to this scope. This file is synced with our vscode
# textmate grammar too, and many themes there don't highlight
# `keyword.operator`. So we'll highlight them as `keyword`
scope: keyword.operator keyword
- match: '\|>'
scope: invalid.deprecated
# doesn't contain ` unlike reason-highlightjs
constructor:
- match: '\b[A-Z][0-9a-zA-Z_]*\b'
# won't mark and highlight this for now. This often shares the same
# highlighting as entity.name.namespace our module). We don't want
# variant and modules confused
# scope: entity.name.union
scope: variable.function variable.other
- match: '(#)(\.\.\.)?([a-zA-Z][0-9a-zA-Z_]*)\b'
captures:
1: punctuation.definition.keyword
2: punctuation.definition.keyword
# see comment above
3: variable.function variable.other
- match: '(#)'
captures:
1: punctuation.definition.keyword
bracketAccess:
- match: '\['
scope: punctuation.section.brackets.begin
- match: '\]'
scope: punctuation.section.brackets.end
list:
- match: '\b(list)(\{)'
captures:
1: keyword
2: punctuation.section.braces.begin
- match: '\}'
scope: punctuation.section.braces.end
attribute:
- match: '@@?'
scope: storage.modifier punctuation.definition.annotation
push: attributeContent
- match: '%%?'
scope: storage.modifier punctuation.definition.annotation
push: attributeContent
attributeContent:
- meta_scope: meta.annotation
- match: 'bs\.send\.pipe'
scope: invalid.deprecated
pop: true
- match: 'splice'
scope: invalid.illegal
pop: true
- match: '(bs\.)?({{RE_ATTRIBUTE}})'
captures:
1: invalid.deprecated
2: variable.annotation
pop: true
jsx:
- match: '<>|</>|/>'
- match: '</({{RE_MODULE_IDENT}})'
captures:
1: entity.name.namespace
push: moduleAccessEndsWithModuleThenPop
- match: '</({{RE_IDENT}})'
# overloaded: if a <Foo.bar
# fortunately, still the right category
- match: '<({{RE_MODULE_IDENT}})'
captures:
1: entity.name.namespace
push: moduleAccessEndsWithModuleThenPop
openOrIncludeModule:
- match: '\b(open|include)\s+'
scope: keyword
push: moduleAccessEndsWithModuleThenPop
# Foo.Bar.Baz where Baz is actually a module, not a constructor
moduleAccessEndsWithModule:
- match: '{{RE_MODULE_IDENT}}'
scope: entity.name.namespace
- match: '(\.)({{RE_MODULE_IDENT}})'
captures:
1: punctuation.accessor
2: entity.name.namespace
moduleAccessEndsWithModuleThenPop:
- include: moduleAccessEndsWithModule
- match: '(?=\S)'
pop: true
moduleAccess:
- match: '\b({{RE_MODULE_IDENT}})(\.)'
captures:
1: entity.name.namespace
2: punctuation.accessor
functorParameter:
- match: \(
push: functorParameter
scope: punctuation.section.parens.begin
- match: \)
scope: punctuation.section.parens.end
pop: true
- match: \{
scope: punctuation.section.braces.begin
push: moduleInner
- include: moduleAccessEndsWithModule
- include: main
moduleRHS:
- include: functorParameter
# this is what makes us bail out of the current stack
# module Foo = (Bar: Baz) => (Bar: Baz) => List
# Bar Bar
# Bar
# let a = Bar
# ^ bail! Now this is bailing way too late, but that's ok for now
- match: '(?=\S)'
pop: true
moduleDeclaration:
- match: '\b(module)\s+(type\s+)?(of\s+)?({{RE_MODULE_IDENT}})'
captures:
1: keyword
2: keyword
3: keyword
4: entity.name.namespace
push:
# and then an optional type signature is matched. Hopefully this regex
# doesn't accidentally match something else
- match: '\s*:\s*({{RE_MODULE_IDENT}})'
captures:
1: entity.name.namespace
- match: '\s*:\s*(\{)'
captures:
1: punctuation.section.braces.begin
push: moduleInner
- match: '=[^\S]'
scope: keyword.operator keyword
set: moduleRHS
- match: '(?=\S)'
pop: true
moduleInner:
- match: \}
scope: punctuation.section.braces.end
pop: true
- include: main
main:
- include: storage
- include: constant
# these below are basically like reason-highlightjs
- include: commentLine
- include: commentBlock
- include: character
- include: typeParameter
- include: string
- include: attribute
- include: function
- include: list
- include: bracketAccess
- include: jsx
- include: operator
- include: number
- include: openOrIncludeModule
- include: moduleDeclaration
- include: moduleAccess
- include: constructor
# this is different than reason-highlightjs too
- include: keyword
- include: punctuations