@@ -14,7 +14,23 @@ variables:
14
14
constantIdentifier : ' [[:upper:]][_$[:digit:][:upper:]]*'
15
15
quotedStrings : (\'([^\'\\]|\\\'|\\)*\')|(\"([^\"\\]|\\\"|\\)*\")
16
16
nonIdentifierPropertyName : ' {{quotedStrings}}|(\[([^\[\]]|\[[^\[\]]*\])+\])'
17
- propertyName : (({{identifier}})|{{nonIdentifierPropertyName}})
17
+ hexNumber : \b(?<!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$)
18
+ binaryNumber : \b(?<!\$)0(b|B)[01][01_]*\b(?!\$)
19
+ octalNumber : \b(?<!\$)0(o|O)?[0-7][0-7_]*\b(?!\$)
20
+ decimalNumber : |-
21
+ (?<!\$)(?:
22
+ (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
23
+ (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
24
+ (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
25
+ (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
26
+ (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
27
+ (?:\b[0-9][0-9_]*(\.)\B)| # 1.
28
+ (?:\B(\.)[0-9][0-9_]*\b)| # .1
29
+ (?:\b[0-9][0-9_]*\b(?!\.)) # 1
30
+ )(?!\$)
31
+ anyNumber : ({{hexNumber}})|({{binaryNumber}})|({{octalNumber}})|({{decimalNumber}})
32
+ # any use of property name needs to ignore line breaks in regular expression because of decimal number regex (maintained for readability)
33
+ propertyName : ({{anyNumber}}|({{identifier}})|{{nonIdentifierPropertyName}})
18
34
constantVar : ({{constantIdentifier}})(?![_$[:alnum:]])
19
35
endOfStatement : ' ;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b'
20
36
nonPropertyLookBehind : ' [^\._$[:alnum:]]'
@@ -269,7 +285,7 @@ repository:
269
285
object-binding-element :
270
286
patterns :
271
287
- include : ' #comment'
272
- - begin : (?={{propertyName}}\s*(:))
288
+ - begin : (?x)(? ={{propertyName}}\s*(:))
273
289
end : (?=,|\})
274
290
patterns :
275
291
- include : ' #object-binding-element-propertyName'
@@ -280,13 +296,14 @@ repository:
280
296
- include : ' #punctuation-comma'
281
297
282
298
object-binding-element-propertyName :
283
- begin : (?={{propertyName}}\s*(:))
299
+ begin : (?x)(? ={{propertyName}}\s*(:))
284
300
end : (:)
285
301
endCaptures :
286
302
' 0 ' : { name: punctuation.destructuring.ts }
287
303
patterns :
288
304
- include : ' #string'
289
305
- include : ' #array-literal'
306
+ - include : ' #numeric-literal'
290
307
- name : variable.object.property.ts
291
308
match : ({{identifier}})
292
309
@@ -374,7 +391,7 @@ repository:
374
391
parameter-object-binding-element :
375
392
patterns :
376
393
- include : ' #comment'
377
- - begin : (?={{propertyName}}\s*(:))
394
+ - begin : (?x)(? ={{propertyName}}\s*(:))
378
395
end : (?=,|\})
379
396
patterns :
380
397
- include : ' #object-binding-element-propertyName'
@@ -423,18 +440,19 @@ repository:
423
440
424
441
field-declaration :
425
442
name : meta.field.declaration.ts
426
- begin : (?<!\()(?:{{startOfIdentifier}}(readonly)\s+)?(?={{propertyName}}\s*(\?\s*)?(=|:))
443
+ begin : (?x)(? <!\()(?:{{startOfIdentifier}}(readonly)\s+)?(?={{propertyName}}\s*(\?\s*)?(=|:))
427
444
beginCaptures :
428
445
' 1 ' : { name: storage.modifier.ts }
429
- end : (?=\}|;|,|$|(^(?!{{propertyName}}\s*(\?\s*)?(=|:))))|(?<=\})
446
+ end : (?x)(? =\}|;|,|$|(^(?!{{propertyName}}\s*(\?\s*)?(=|:))))|(?<=\})
430
447
patterns :
431
448
- include : ' #variable-initializer'
432
- - begin : (?={{propertyName}}\s*(\?\s*)?(=|:))
433
- end : (?=[};,=]|$|(^(?!{{propertyName}}\s*(\?\s*)?(=|:))))|(?<=\})
449
+ - begin : (?x)(? ={{propertyName}}\s*(\?\s*)?(=|:))
450
+ end : (?x)(? =[};,=]|$|(^(?!{{propertyName}}\s*(\?\s*)?(=|:))))|(?<=\})
434
451
patterns :
435
452
- include : ' #type-annotation'
436
453
- include : ' #string'
437
454
- include : ' #array-literal'
455
+ - include : ' #numeric-literal'
438
456
- include : ' #comment'
439
457
# function assignment |
440
458
# typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
@@ -511,7 +529,7 @@ repository:
511
529
patterns :
512
530
# method, accessor
513
531
- name : meta.method.declaration.ts
514
- begin : ' {{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)(?:(\*)\s*)?(?=({{propertyName}}\s*(\??))\s*[\(\<])'
532
+ begin : ' (?x) {{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)(?:(\*)\s*)?(?=({{propertyName}}\s*(\??))\s*[\(\<])'
515
533
beginCaptures :
516
534
' 1 ' : { name: storage.modifier.ts } # captures keyword (public or private or protected)
517
535
' 2 ' : { name: storage.modifier.ts } # captures keyword (abstract)
@@ -524,7 +542,7 @@ repository:
524
542
- include : ' #function-body'
525
543
# new, constructor or call signature
526
544
- name : meta.method.declaration.ts
527
- begin : ' {{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!:){{endOfIdentifier}})|(?:(\*)\s*)?(?=({{propertyName}}\s*(\??))?\s*[\(\<]))'
545
+ begin : ' (?x) {{startOfIdentifier}}(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!:){{endOfIdentifier}})|(?:(\*)\s*)?(?=({{propertyName}}\s*(\??))?\s*[\(\<]))'
528
546
beginCaptures :
529
547
' 1 ' : { name: storage.modifier.ts } # captures keyword (public or private or protected)
530
548
' 2 ' : { name: storage.modifier.ts } # captures keyword (abstract)
@@ -539,7 +557,7 @@ repository:
539
557
540
558
object-literal-method-declaration :
541
559
name : meta.method.declaration.ts
542
- begin : ' {{startOfIdentifier}}(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=({{propertyName}}\s*(\??))\s*[\(\<])'
560
+ begin : ' (?x) {{startOfIdentifier}}(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=({{propertyName}}\s*(\??))\s*[\(\<])'
543
561
beginCaptures :
544
562
' 1 ' : { name: storage.modifier.async.ts } # captures keyword (async)
545
563
' 2 ' : { name: storage.type.property.ts } # captures keyword (get|set)
@@ -548,7 +566,7 @@ repository:
548
566
patterns :
549
567
- include : ' #method-declaration-name'
550
568
- include : ' #function-body'
551
- - begin : ' {{startOfIdentifier}}(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=({{propertyName}}\s*(\??))\s*[\(\<])'
569
+ - begin : ' (?x) {{startOfIdentifier}}(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=({{propertyName}}\s*(\??))\s*[\(\<])'
552
570
beginCaptures :
553
571
' 1 ' : { name: storage.modifier.async.ts } # captures keyword (async)
554
572
' 2 ' : { name: storage.type.property.ts } # captures keyword (get|set)
@@ -558,11 +576,12 @@ repository:
558
576
- include : ' #method-declaration-name'
559
577
560
578
method-declaration-name :
561
- begin : (?={{propertyName}}\s*(\??)\s*[\(\<])
579
+ begin : (?x)(? ={{propertyName}}\s*(\??)\s*[\(\<])
562
580
end : (?=\(|\<)
563
581
patterns :
564
582
- include : ' #string'
565
583
- include : ' #array-literal'
584
+ - include : ' #numeric-literal'
566
585
- name : meta.definition.method.ts entity.name.function.ts
567
586
match : ' {{identifier}}'
568
587
- name : keyword.operator.optional.ts
@@ -1390,23 +1409,14 @@ repository:
1390
1409
numeric-literal :
1391
1410
patterns :
1392
1411
- name : constant.numeric.hex.ts
1393
- match : \b(?<!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$)
1412
+ match : ' {{hexNumber}} '
1394
1413
- name : constant.numeric.binary.ts
1395
- match : \b(?<!\$)0(b|B)[01][01_]*\b(?!\$)
1414
+ match : ' {{binaryNumber}} '
1396
1415
- name : constant.numeric.octal.ts
1397
- match : \b(?<!\$)0(o|O)?[0-7][0-7_]*\b(?!\$)
1416
+ match : ' {{octalNumber}} '
1398
1417
- match : |-
1399
1418
(?x)
1400
- (?<!\$)(?:
1401
- (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
1402
- (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
1403
- (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
1404
- (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
1405
- (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
1406
- (?:\b[0-9][0-9_]*(\.)\B)| # 1.
1407
- (?:\B(\.)[0-9][0-9_]*\b)| # .1
1408
- (?:\b[0-9][0-9_]*\b(?!\.)) # 1
1409
- )(?!\$)
1419
+ {{decimalNumber}}
1410
1420
captures:
1411
1421
'0': {name: constant.numeric.decimal.ts}
1412
1422
'1': {name: meta.delimiter.decimal.period.ts}
0 commit comments