@@ -14,6 +14,8 @@ variables:
14
14
escaped_char : ' \\([nrt0\"'' \\]|x[0-7]\h|u\{(?:\h_*){1,6}\})'
15
15
int_suffixes : ' [iu](?:8|16|32|64|128|size)'
16
16
float_suffixes : ' f(32|64)'
17
+ dec_literal : ' [0-9](?:[0-9_])*'
18
+ float_exponent : ' [eE][+-]?[0-9_]*[0-9][0-9_]*'
17
19
contexts :
18
20
main :
19
21
- include : statements
@@ -309,6 +311,74 @@ contexts:
309
311
- match : ' (?=\S)'
310
312
pop : true
311
313
314
+ pattern-param :
315
+ - include : comments
316
+ - match : ' &'
317
+ scope : keyword.operator.rust
318
+ - match : \b(mut|ref)\b
319
+ scope : storage.modifier.rust
320
+ - match : ' @'
321
+ scope : keyword.operator.rust
322
+ - match : ' \b{{identifier}}\b(?!\s*(?:::|\{|\[|\())'
323
+ scope : variable.parameter.rust
324
+
325
+ - match : ' \{'
326
+ # Struct pattern.
327
+ scope : punctuation.section.block.begin.rust
328
+ push :
329
+ - meta_scope : meta.block.rust
330
+ - match : ' \}'
331
+ scope : punctuation.section.block.end.rust
332
+ pop : true
333
+ - match : ' (\d+)\s*(:)'
334
+ # Tuple struct field specifier.
335
+ captures :
336
+ 1 : constant.numeric.integer.decimal.rust
337
+ 2 : punctuation.separator.rust
338
+ - match : ' {{identifier}}\s*(:)'
339
+ # Struct field specifier.
340
+ captures :
341
+ 1 : punctuation.separator.rust
342
+ - match : ' \.\.'
343
+ scope : keyword.operator.rust
344
+ - include : pattern-param
345
+
346
+ - match : ' \('
347
+ # Tuple or tuple struct pattern.
348
+ scope : punctuation.section.group.begin.rust
349
+ push :
350
+ - meta_scope : meta.group.rust
351
+ - match : ' \)'
352
+ scope : punctuation.section.group.end.rust
353
+ pop : true
354
+ - match : ' \.\.'
355
+ scope : keyword.operator.rust
356
+ - include : pattern-param
357
+
358
+ - match : ' \['
359
+ # Slice pattern.
360
+ scope : punctuation.section.brackets.begin.rust
361
+ push :
362
+ - meta_scope : meta.brackets.rust
363
+ - match : ' \]'
364
+ scope : punctuation.section.brackets.end.rust
365
+ pop : true
366
+ - include : pattern-param
367
+
368
+ # Path for struct patterns.
369
+ - match : ' \bself\b|\bsuper\b'
370
+ scope : keyword.other.rust
371
+ - match : ' \b{{identifier}}\b'
372
+ - match : ' ::'
373
+
374
+ - match : ' :(?!:)'
375
+ # Type
376
+ scope : punctuation.separator.rust
377
+ push :
378
+ - match : ' (?=,|\)|\]|\}|\|)'
379
+ pop : true
380
+ - include : type-any-identifier
381
+
312
382
closure :
313
383
- meta_content_scope : meta.function.closure.rust
314
384
- match : ' \|'
@@ -317,33 +387,16 @@ contexts:
317
387
318
388
closure-parameters :
319
389
- meta_scope : meta.function.parameters.rust
390
+ - match : ' \|'
391
+ scope : punctuation.definition.parameters.end.rust
392
+ pop : true
393
+ - include : pattern-param
320
394
# If the user has just typed a |, exit the params
321
395
# scope as soon as we hit something that it not a
322
396
# valid part so the whole rest of the document isn't
323
397
# highlighted using the params scope
324
- - include : comments
325
- - match : ' (?=\()'
326
- push : group
327
- - match : ' (?=[};)\]])'
328
- pop : true
329
- - match : ' \|'
330
- scope : punctuation.definition.parameters.end.rust
398
+ - match : ' (?=[=};)\]])'
331
399
pop : true
332
- - match : \bself\b
333
- scope : variable.parameter.rust
334
- - match : ' ({{identifier}})\s*(?:(:(?!:))|(?=\||,))'
335
- captures :
336
- 1 : variable.parameter.rust
337
- 2 : punctuation.separator.rust
338
- push :
339
- - match : (?=,|\|)
340
- pop : true
341
- - include : type-any-identifier
342
- - match : ' &'
343
- scope : keyword.operator.rust
344
- - match : \b(mut|ref)\b
345
- scope : storage.modifier.rust
346
- - include : lifetime
347
400
348
401
closure-return :
349
402
- meta_content_scope : meta.function.closure.rust
@@ -432,7 +485,7 @@ contexts:
432
485
- include : raw-pointer
433
486
- match : \b(mut|ref|const|unsafe)\b
434
487
scope : storage.modifier.rust
435
- - match : \b(fn)\b(\()
488
+ - match : \b(fn)\b\s* (\()
436
489
captures :
437
490
1 : storage.type.function.rust
438
491
2 : meta.group.rust punctuation.definition.group.begin.rust
@@ -765,7 +818,7 @@ contexts:
765
818
pop : true
766
819
- include : macro-matchers
767
820
768
- - match : ' (\$\s*{{identifier}})\s*(:)\s*(ident|path|expr|ty|pat|stmt|block|item|meta|tt|lifetime)'
821
+ - match : ' (\$\s*{{identifier}})\s*(:)\s*(ident|path|expr|ty|pat|stmt|block|item|meta|tt|lifetime|vis )'
769
822
captures :
770
823
1 : variable.parameter.rust
771
824
2 : punctuation.separator.rust
@@ -944,13 +997,7 @@ contexts:
944
997
- include : comments
945
998
- match : ' (?=\))'
946
999
pop : true
947
- - match : \bself\b
948
- scope : variable.parameter.rust
949
- - match : ' ({{identifier}})\s*(:(?!:))'
950
- captures :
951
- 1 : variable.parameter.rust
952
- 2 : punctuation.separator.rust
953
- - include : type-any-identifier
1000
+ - include : pattern-param
954
1001
955
1002
fn-return :
956
1003
- meta_scope : meta.function.rust
@@ -1197,22 +1244,18 @@ contexts:
1197
1244
scope: constant.other.placeholder.rust
1198
1245
1199
1246
numbers :
1200
- - match : ' \b((?:\d[\d_]*)?\.)(\d[\d_]*(?:[eE][+-]?[\d_]+)?)({{float_suffixes}})?'
1201
- captures :
1202
- 1 : constant.numeric.float.rust
1203
- 2 : constant.numeric.float.rust
1204
- 3 : storage.type.numeric.rust
1205
- - match : ' \b(\d[\d_]*\.)(?!\.)'
1206
- scope : constant.numeric.float.rust
1207
- - match : ' \b(\d[\d_]*)({{float_suffixes}})\b'
1208
- captures :
1209
- 1 : constant.numeric.float.rust
1210
- 2 : storage.type.numeric.rust
1211
- - match : ' \b(\d[\d_]*(?:\.[\d_]+)?[eE][-+]?[\d_]+)({{float_suffixes}})?\b'
1247
+ - match : ' \b({{dec_literal}}(?:\.{{dec_literal}})?(?:{{float_exponent}})?)({{float_suffixes}})'
1212
1248
captures :
1213
1249
1 : constant.numeric.float.rust
1214
1250
2 : storage.type.numeric.rust
1215
- - match : ' \b(\d[\d_]*)({{int_suffixes}})?\b'
1251
+ - match : ' \b{{dec_literal}}\.{{dec_literal}}(?:{{float_exponent}})?'
1252
+ scope : constant.numeric.float.rust
1253
+ - match : ' \b{{dec_literal}}{{float_exponent}}'
1254
+ scope : constant.numeric.float.rust
1255
+ - match : ' \b{{dec_literal}}\.(?![A-Za-z._'' ])'
1256
+ scope : constant.numeric.float.rust
1257
+
1258
+ - match : ' \b({{dec_literal}})({{int_suffixes}})?\b'
1216
1259
captures :
1217
1260
1 : constant.numeric.integer.decimal.rust
1218
1261
2 : storage.type.numeric.rust
0 commit comments