-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfe.tmLanguage.json
378 lines (378 loc) · 19.9 KB
/
fe.tmLanguage.json
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Fe",
"scopeName": "source.fe",
"comment": "Included patterns are listed in descending order of matching precedence. In general, each element of the grammar is given one or two names: if necessary, a 'meta' name that describes the element in terms of this grammar file, and a non-'meta', conventional TextMate grammar name, which informs tools such as VS Code on how to color the element. If the conventional TextMate name describes the matched token perfectly, the meta name is obviated.",
"patterns": [
{ "include": "#line-comment" },
{ "include": "#block-comment" },
{ "include": "#has-abilities" },
{ "include": "#type-address" },
{ "include": "#keyword" },
{ "include": "#type" },
{ "include": "#function" },
{ "include": "#value" },
{ "include": "#identifier" },
{ "include": "#punctuation" }
],
"repository": {
"line-comment": {
"comment": "Single-line comments such as `// ...` and `/// ...`.",
"patterns": [
{
"name": "meta.comment.line.documentation.fe comment.block.documentation.fe",
"comment": "A single-line comment of the form `/// ...`. fe considers this to be a documentation comment. TextMate's naming conventions don't include single-line documentation comments, so this is named 'comment.block.documentation' instead.",
"begin": "(///)",
"beginCaptures": { "1": { "name": "meta.punctuation.slash-slash-slash.fe" } },
"end": "(\u000a)$",
"endCaptures": { "1": { "name": "meta.punctuation.line-feed.fe" } },
"patterns": [{ "include": "#comment-ambiguous-character" }]
},
{
"name": "comment.line.fe",
"comment": "A single-line comment of the form `// ...`.",
"begin": "(//)",
"beginCaptures": { "1": { "name": "meta.punctuation.slash-slash.fe" } },
"end": "(\u000a)$",
"endCaptures": { "1": { "name": "meta.punctuation.line-feed.fe" } },
"patterns": [{ "include": "#comment-ambiguous-character" }]
}
]
},
"block-comment": {
"comment": "Block comments such as `/* ... */` and `/** ... */`. These need special handling because they can be nested, creating a stack of block of comments that are closed by `*/` in LIFO order.",
"patterns": [
{
"name": "comment.block.documentation.fe",
"comment": "A block comment of the form `/** ... */`. fe considers this to be a documentation comment.",
"begin": "/\\*\\*(?!/)",
"end": "\\*/",
"patterns": [
{ "include": "#comment-ambiguous-character" },
{ "include": "#block-comment" }
]
},
{
"name": "comment.block.fe",
"comment": "A block comment of the form `/* ... */`.",
"begin": "/\\*",
"end": "\\*/",
"patterns": [
{ "include": "#comment-ambiguous-character" },
{ "include": "#block-comment" }
]
}
]
},
"comment-ambiguous-character": {
"comment": "Characters that may be considered confusing when used in comments.",
"patterns": [
{
"name": "meta.comment.ambiguous-character.isolated-carriage-return.fe invalid.illegal.fe",
"match": "[\r][^\n]"
},
{
"name": "meta.comment.ambiguous-character.whitespace.fe invalid.illegal.fe",
"comment": "Unicode code points that represent esoteric white space characters. Most of these come from the 'White_Space' property list from https://www.unicode.org/Public/UCD/latest/ucd/PropList.txt.",
"match": "(?:\u000b|\u000c|\u0085|\u00a0|\u1680|\u180e|[\u2000-\u200d]|\u2028|\u2029|\u202f|\u205f|\u2060|\u3000|\ufeff)"
},
{
"name": "meta.comment.ambiguous-character.asterisk-lookalike.fe invalid.illegal.fe",
"comment": "Unicode code points that represent characters that appear similar to an asterisk '*', which fe uses to delimit comments.",
"match": "(?:\u066d|\u204e|\u2217|\u26b9|\u2731)"
},
{
"name": "meta.comment.ambiguous-character.slash-lookalike.fe invalid.illegal.fe",
"comment": "Unicode code points that represent characters that appear similar to a forward slash '/', which fe uses to delimit comments.",
"match": "(?:\u01c0|\u0338|\u2044|\u2215|\u2e4a)"
}
]
},
"has-abilities": {
"comment": "`copy` is an operator in fe, as well as a struct ability. To disambiguate, preferentially match abilities that appear after the `has` keyword.",
"begin": "\\b(has)\\b",
"beginCaptures": { "1": { "name": "keyword.other.fe" } },
"end": "(?:(\\{)|(;))",
"endCaptures": {
"1": { "name": "meta.punctuation.left-brace.fe" },
"2": { "name": "meta.punctuation.semicolon.fe" }
},
"patterns": [
{ "include": "#line-comment" },
{ "include": "#block-comment" },
{ "include": "#ability" }
]
},
"type-address": {
"name": "meta.type-address.fe",
"comment": "`address` is both a keyword (`address 0x1 { ... }`) and a type (`a: &address`). Make a simple attempt to disambiguate, by matching the most common usages of the type. This is a best-effort and is easily foiled with block comments such as `a: /**/ address`.",
"match": "(\\:)\\s*(&)?(address)\\b",
"captures": {
"1": { "name": "meta.punctuation.colon.fe" },
"2": { "name": "meta.punctuation.ampersand.fe" },
"3": { "name": "meta.type.builtin.address.fe entity.name.type.fe" }
}
},
"keyword": {
"comment": "Keywords such as 'if' or 'let', operator keywords such as 'fe' or 'copy', contextual keywords such as 'invariant' or 'phantom', or builtin functions such as 'borrow_global_mut'.",
"patterns": [
{
"name": "keyword.control.fe",
"match": "\\b(?:abort|break|continue|else|if|loop|return|while)\\b"
},
{
"name": "keyword.operator.fe",
"match": "\\b(?:copy|fe)\\b"
},
{
"name": "keyword.other.fe",
"match": "\\b(?:acquires|as|friend|has|invariant|Self|spec|use)\\b"
},
{
"name": "keyword.other.fe.specification",
"match": "\\b(?:aborts_if|aborts_with|apply|assume|axiom|choose|decreases|emits|ensures|except|forall|global|include|internal|local|min|modifies|pragma|requires|schema|succeeds_if|to|update|with|where)\\b"
},
{
"name": "storage.type.fe",
"match": "\\b(?:address|const|fun|let|module|post|script|struct|phantom)\\b"
},
{
"name": "storage.modifier.fe",
"match": "\\b(?:mut|native|public)\\b"
},
{
"name": "support.function.fe",
"match": "\\b(?:assert|borrow_global|borrow_global_mut|exists|freeze|fe_from|fe_to|old)\\b"
}
]
},
"type": {
"comment": "A type name, such as `u128` or `&mut 0x2::M::S<u8>`.",
"patterns": [
{
"name": "meta.type.builtin.number.fe entity.name.type.fe",
"match": "\\bu(?:8|64|128)\\b"
},
{
"name": "meta.type.builtin.bool.fe entity.name.type.fe",
"match": "\\bbool\\b"
},
{
"name": "meta.type.builtin.address.fe entity.name.type.fe",
"match": "\\baddress\\b"
},
{
"name": "meta.type.builtin.signer.fe entity.name.type.fe",
"match": "\\bsigner\\b"
},
{
"name": "meta.type.builtin.vector.fe",
"begin": "(vector)(<)",
"beginCaptures": {
"1": { "name": "entity.name.type.fe" },
"2": { "name": "meta.punctuation.left-angle-bracket.fe" }
},
"end": "(>)",
"endCaptures": {
"1": { "name": "meta.punctuation.right-angle-bracket.fe" }
},
"patterns": [
{ "include": "#line-comment" },
{ "include": "#block-comment" },
{ "include": "#type" },
{ "include": "#identifier" }
]
}
]
},
"function": {
"comment": "We assume an identifier that does not begin with a capital letter, eventually followed by an open parenthesis `(`, is a function (no distinction is made here between function call expressions and function declarations). This means that parameterized attributes such as `#[expected_failure(abort_code = 1)]` are classified as functions, but that doesn't seem so bad.",
"patterns": [
{
"comment": "A function followed by a type list, for example `spec_none<Element>()`.",
"begin": "([_a-z][_a-zA-Z0-9]*)(<)",
"beginCaptures": {
"1": { "name": "meta.function.fe entity.name.function.fe" },
"2": { "name": "meta.punctuation.less.fe" }
},
"end": "(>)(\\()",
"endCaptures": {
"1": { "name": "meta.punctuation.greater.fe" },
"2": { "name": "meta.punctuation.left-parenthesis.fe" }
},
"patterns": [
{ "include": "#line-comment" },
{ "include": "#block-comment" },
{ "include": "#type" },
{ "include": "#ability" },
{ "include": "#identifier" }
]
},
{
"comment": "A function immediately followed by an open parenthesis, for example `len(vec)`.",
"match": "([_a-z][_a-zA-Z0-9]*)(\\()",
"captures": {
"1": { "name": "meta.function.fe entity.name.function.fe" },
"2": { "name": "meta.punctuation.left-parenthesis.fe" }
}
}
]
},
"value": {
"name": "meta.value.fe",
"patterns": [
{
"comment": "An address value with a hexadecimal constant, for example `@0x1bEeF`.",
"name": "meta.value.address.hexadecimal.fe variable.other.fe",
"match": "@0x[a-fA-F0-9]+(u(8|64|128))?"
},
{
"comment": "An address value with a non-hexadecimal numeric constant, for example `@42u8`.",
"name": "meta.value.address.decimal.fe variable.other.fe",
"match": "@[0-9]+(u(8|64|128))?"
},
{
"comment": "An address value with an identifier, for example `@addr`.",
"name": "meta.value.address.identifier.fe variable.other.fe",
"match": "@[_a-zA-Z][_a-zA-Z0-9]*"
},
{
"comment": "A boolean constant: `true` or `false`.",
"name": "meta.value.boolean.fe constant.language.boolean.fe",
"match": "\\b(true|false)\\b"
},
{
"comment": "A hexadecimal constant number, for example `0x11Eeu64`.",
"name": "meta.value.number.hexadecimal.fe constant.numeric.fe",
"match": "\\b0x[a-fA-F0-9]+(u(8|64|128))?\\b"
},
{
"comment": "A non-hexadecimal constant number, for example `42u128`.",
"name": "meta.value.number.decimal.fe constant.numeric.fe",
"match": "\\b[0-9]+(u(8|64|128))?\\b"
},
{
"comment": "A byte string, for example b\"hel\tlo\".",
"name": "meta.value.bytestring.fe string.quoted.double.fe",
"begin": "(b\")",
"beginCaptures": { "1": { "name": "meta.value.bytestring.prefix.fe" } },
"end": "(\")",
"endCaptures": { "1": { "name": "meta.value.bytestring.suffix.fe" } },
"patterns": [{
"comment": "An escaped character within a string.",
"name": "constant.character.escape.fe",
"match": "\\\\."
}]
},
{
"comment": "A hexadecimal string, for example x\"01dF\".",
"name": "meta.value.hexadecimal-string.fe string.quoted.double.fe",
"begin": "(x\")",
"beginCaptures": { "1": { "name": "meta.value.hexadecimal-string.prefix.fe" } },
"end": "(\")",
"endCaptures": { "1": { "name": "meta.value.hexadecimal-string.suffix.fe" } },
"patterns": [{
"comment": "Invalid hexadecimal character within a string.",
"name": "meta.value.hexadecimal-string.invalid.fe invalid.illegal.fe",
"match": "[^a-fA-F0-9]"
}]
}
]
},
"identifier": {
"patterns": [
{
"name": "meta.identifier.all-capitals.fe constant.other.fe",
"comment": "We assume any identifier composed of two or more capital letters is a constant.",
"match": "\\b[A-Z][_A-Z0-9]+\\b"
},
{
"name": "meta.identifier.camel-case-type-list.fe",
"comment": "We assume any identifier beginning with a capital letter is a type. This pattern matches such a type followed by angle brackets `<...>`.",
"begin": "\\b([A-Z][_a-zA-Z0-9]*)(<)",
"beginCaptures": {
"1": { "name": "entity.name.type.fe" },
"2": { "name": "meta.punctuation.less.fe" }
},
"end": "(>)",
"endCaptures": { "1": { "name": "meta.punctuation.greater.fe" } },
"patterns": [
{ "include": "#type" },
{ "include": "#ability" },
{ "include": "#identifier" }
]
},
{
"name": "meta.identifier.camel-case.fe entity.name.type.fe",
"comment": "We assume any identifier beginning with a capital letter is a type.",
"match": "\\b[A-Z][_a-zA-Z0-9]*\\b"
},
{
"name": "meta.identifier.type-list.fe",
"comment": "This pattern matches an identifier followed by angle brackets `<...>`.",
"begin": "\\b([_a-zA-Z][_a-zA-Z0-9]*)(<)",
"beginCaptures": {
"1": { "name": "variable.other.fe" },
"2": { "name": "meta.punctuation.less.fe" }
},
"end": "(>)",
"endCaptures": { "1": { "name": "meta.punctuation.greater.fe" } },
"patterns": [
{ "include": "#type" },
{ "include": "#ability" },
{ "include": "#identifier" }
]
},
{
"name": "meta.identifier.fe variable.other.fe",
"match": "\\b[_a-zA-Z][_a-zA-Z0-9]*\\b"
}
]
},
"ability": {
"name": "meta.ability.fe entity.name.type.fe",
"comment": "This pattern matches any of the built-in type abilities.",
"match": "\\b(copy|drop|key|store)\\b"
},
"punctuation": {
"comment": "Patterns used to capture punctuators such as `{` or `::` as individual tokens.",
"patterns": [
{ "name": "meta.punctuation.exclaim-equal.fe", "match": "!=" },
{ "name": "meta.punctuation.exclaim.fe", "match": "!" },
{ "name": "meta.punctuation.percent.fe", "match": "%" },
{ "name": "meta.punctuation.ampersand-ampersand.fe", "match": "&&" },
{ "name": "meta.punctuation.ampersand.fe", "match": "&" },
{ "name": "meta.punctuation.left-parenthesis.fe", "match": "\\(" },
{ "name": "meta.punctuation.right-parenthesis.fe", "match": "\\)" },
{ "name": "meta.punctuation.hash-left-bracket.fe", "match": "#\\[" },
{ "name": "meta.punctuation.left-bracket.fe", "match": "\\[" },
{ "name": "meta.punctuation.right-bracket.fe", "match": "\\]" },
{ "name": "meta.punctuation.asterisk.fe", "match": "\\*" },
{ "name": "meta.punctuation.plus.fe", "match": "\\+" },
{ "name": "meta.punctuation.comma.fe", "match": "," },
{ "name": "meta.punctuation.minus.fe", "match": "-" },
{ "name": "meta.punctuation.period-period.fe", "match": "\\.\\." },
{ "name": "meta.punctuation.period.fe", "match": "\\." },
{ "name": "meta.punctuation.slash.fe", "match": "/" },
{ "name": "meta.punctuation.colon-colon.fe", "match": "::" },
{ "name": "meta.punctuation.colon.fe", "match": ":" },
{ "name": "meta.punctuation.semicolon.fe", "match": ";" },
{ "name": "meta.punctuation.less-equal-equal-greater.fe", "match": "<==>" },
{ "name": "meta.punctuation.equal-equal-greater.fe", "match": "==>" },
{ "name": "meta.punctuation.equal-equal.fe", "match": "==" },
{ "name": "meta.punctuation.less-less.fe", "match": "<<" },
{ "name": "meta.punctuation.less-equal.fe", "match": "<=" },
{ "name": "meta.punctuation.greater-greater.fe", "match": ">>" },
{ "name": "meta.punctuation.greater-equal.fe", "match": ">=" },
{ "name": "meta.punctuation.equal.fe", "match": "=" },
{ "name": "meta.punctuation.less.fe", "match": "<" },
{ "name": "meta.punctuation.greater.fe", "match": ">" },
{ "name": "meta.punctuation.caret.fe", "match": "\\^" },
{ "name": "meta.punctuation.pipe-pipe.fe", "match": "\\|\\|" },
{ "name": "meta.punctuation.pipe.fe", "match": "\\|" },
{ "name": "meta.punctuation.left-brace.fe", "match": "\\{" },
{ "name": "meta.punctuation.right-brace.fe", "match": "\\}" }
]
}
}
}