Skip to content

Commit ca75bcc

Browse files
committed
Improve TextMate syntax performance
1 parent b2ecc87 commit ca75bcc

File tree

3 files changed

+56
-19
lines changed

3 files changed

+56
-19
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
],
159159
"configurationDefaults": {
160160
"[json-textmate]": {
161-
"editor.maxTokenizationLineLength": 500000,
161+
"editor.maxTokenizationLineLength": 600000,
162162
"editor.suggest.insertMode": "replace",
163163
"editor.suggest.preview": true,
164164
"editor.quickSuggestions": {

syntaxes/json.tmLanguage.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,15 +785,15 @@
785785
{ "match": "\\w+" },
786786
{
787787
"comment": "An invalid capture group number does not convert, nor becomes null",
788-
"match": "(\\$)(0*)(\\d{1,3})(?!\\d)",
788+
"match": "(\\$)(0*)(\\d{3,1})(?!\\d)",
789789
"captures": {
790790
"1": { "name": "meta.embedded constant.character.escape.json.tm markup.italic" },
791791
"2": { "name": "punctuation.definition.tag.json.tm" },
792792
"3": { "name": "constant.numeric.json.tm" }
793793
}
794794
},
795795
{
796-
"match": "(\\$)({)(0*)(\\d{1,3})(:/)(upcase|downcase)(})",
796+
"match": "(\\$)({)(0*)(\\d{3,1})(:/)(upcase|downcase)(})",
797797
"captures": {
798798
"1": { "name": "meta.embedded constant.character.escape.json.tm markup.italic.tm" },
799799
"2": { "name": "meta.embedded constant.character.escape.json.tm" },
@@ -1246,7 +1246,7 @@
12461246
"name": "constant.character.escape.json.tm"
12471247
},
12481248
{
1249-
"match": "(\\\\u)(?>(\\h{4})|([^\"].{,3}))",
1249+
"match": "(\\\\u)(\\h{4,0})",
12501250
"captures": {
12511251
"1": { "name": "constant.character.escape.tm" },
12521252
"2": { "name": "constant.numeric.json.tm" },
@@ -1423,7 +1423,15 @@
14231423
]
14241424
},
14251425
{
1426-
"match": "\\b(?>true|false|null)\\b",
1426+
"match": "\\btrue\\b",
1427+
"name": "constant.language.json.tm"
1428+
},
1429+
{
1430+
"match": "\\bfalse\\b",
1431+
"name": "constant.language.json.tm"
1432+
},
1433+
{
1434+
"match": "\\bnull\\b",
14271435
"name": "constant.language.json.tm"
14281436
},
14291437
{

syntaxes/regex.tmLanguage.json

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@
424424
},
425425
{
426426
"comment": "(?y{g}-imxWDSP) (?y{w}imxWDSP-x: ...)",
427-
"begin": "(?>(\\((?=[^:)]+:))|(\\())(\\?)(?=[-IimxWDSPy])(?=[^x:)]++[:)]|[^-:)]*+-[^x:)]*+x[^:)]*+[:)])",
427+
"begin": "(?=\\(\\?[-IimxWDSPy])(?>(\\((?=[^:)]++:))|(\\())(\\?)(?=[^x:)]++[:)]|[^-:)]*+-[^x:)]*+x[^:)]*+[:)])",
428428
"end": "(?((?!\\1))\\)|(?=[\")]))(?#Condition is true only when Backreference \\1 from capture group 1 in \"begin\" is *not* empty.)|(?=\")",
429429
"beginCaptures": {
430430
"1": { "name": "constant.character.set.regexp.tm" },
@@ -451,12 +451,12 @@
451451
"capture-group-modify-extended": {
452452
"patterns": [
453453
{
454-
"match": "\\(\\?-+:?\\)",
454+
"match": "\\(\\?-++:?+\\)",
455455
"name": "punctuation.definition.tag.tm"
456456
},
457457
{
458458
"comment": "(?y{g}imxWDSP-) (?y{w}x-imWDSP:...)",
459-
"begin": "(?>(\\((?=[^:)]++:))|(\\())(\\?)(?=[-IimxWDSPy])(?=[^-:)]*+[^x:)]*+[:)])",
459+
"begin": "(?=\\(\\?[-IimxWDSPy])(?>(\\((?=[^:)]++:))|(\\())(\\?)(?=[^-:)]*+[^x:)]*+[:)])",
460460
"end": "(?((?!\\1))\\)|(?=[\")]))(?#Condition is true only when Backreference \\1 from capture group 1 in \"begin\" is *not* empty.)|(?=\")",
461461
"beginCaptures": {
462462
"1": { "name": "constant.character.set.regexp.tm" },
@@ -670,7 +670,7 @@
670670
},
671671
"absent": {
672672
"comment": "(?~|...|...) (?~|...) (?~...) (?~|)",
673-
"begin": "(\\()(\\?~\\|?)",
673+
"begin": "(\\()(\\?~\\|?+)",
674674
"end": "\\)|(?=\")",
675675
"beginCaptures": {
676676
"1": { "name": "constant.character.set.regexp.tm" },
@@ -788,7 +788,7 @@
788788
},
789789
{
790790
"comment": "(*name[tag]{args...})",
791-
"match": "(\\()(\\*)([A-Za-z_]\\w*)([^\\[{)]*)(?>(\\[)([^]]*)(]))?([^{)]*)(?>({)([^}]*)(}))?([^)]*)(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?",
791+
"match": "(\\()(\\*)([A-Za-z_]\\w*+)([^\\[{)]*+)(?>(\\[)([^]]*+)(]))?+([^{)]*+)(?>({)([^}]*+)(}))?+([^)]*+)(\\))([+*?]|(?D){(?>\\d++,?+\\d*+|,\\d++)})?+",
792792
"captures": {
793793
"1": { "name": "constant.character.set.regexp.tm markup.italic" },
794794
"2": { "name": "support.function.tm" },
@@ -941,7 +941,7 @@
941941
}
942942
},
943943
{
944-
"match": "(\\*(-)\\+)(\\\\{2}(?=-))?",
944+
"match": "(\\*(-)\\+)(\\\\{2}(?=-))?+",
945945
"captures": {
946946
"1": { "name": "character-class-range.tm support.class.tm" },
947947
"2": { "name": "punctuation.definition.tag.tm strong" },
@@ -1231,7 +1231,8 @@
12311231
"comment": "\\777 \\xFF \\cZ \\o{0 4777777} \\x{0 13FFFF} \\u0000 \\p{L} \\C-\\M-]",
12321232
"patterns": [
12331233
{
1234-
"match": "(\\\\{2})([Ppox])(\\\\{2})({)",
1234+
"comment": "The look-ahead increases performance. No clue why :shrug:",
1235+
"match": "(\\\\{2})([Ppox])(?=\\\\\\\\{)(\\\\{2})({)",
12351236
"captures": {
12361237
"1": { "name": "punctuation.definition.tag.tm" },
12371238
"2": { "name": "entity.name.label.tm strong" },
@@ -1280,21 +1281,21 @@
12801281
]
12811282
},
12821283
{
1283-
"match": "(\\\\{2})([0-7]{1,3})",
1284+
"match": "(\\\\{2})([0-7]{3,1})",
12841285
"captures": {
12851286
"1": { "name": "punctuation.definition.list.begin.markdown.tm" },
12861287
"2": { "name": "constant.numeric.tm" }
12871288
}
12881289
},
12891290
{
1290-
"match": "(\\\\{2}x)(?!{|\")(\\h{,2})",
1291+
"match": "(\\\\{2}x)(?!{|\")(\\h{2,0})",
12911292
"captures": {
12921293
"1": { "name": "punctuation.definition.list.begin.markdown.tm" },
12931294
"2": { "name": "constant.numeric.tm" }
12941295
}
12951296
},
12961297
{
1297-
"match": "(?>(\\\\{2}u)|(\\\\u))(?>(\\h{4})|([^\"].{3,}))",
1298+
"match": "(?>(\\\\{2}u)|(\\\\u))(?>(\\h{4})|([^\"].{3,0}))",
12981299
"captures": {
12991300
"1": { "name": "variable.language.tm" },
13001301
"2": { "name": "constant.character.escape.tm" },
@@ -1311,7 +1312,7 @@
13111312
}
13121313
},
13131314
{
1314-
"match": "\\\\{2}(?>c|[CM](?>-|(.))?+)(?>(\\\\{3})(\\\\)|\\g<0>|(\\\\{2})?+(\\\\u.{4,}|\\\\?+.))?+",
1315+
"match": "\\\\{2}(?>c|[CM](?>-|(.))?+)(?>(\\\\{3})(\\\\)|\\g<0>|(\\\\{2})?+(\\\\u.{4,0}|\\\\?+.))?+",
13151316
"captures": {
13161317
"0": { "name": "punctuation.definition.list.begin.markdown.tm" },
13171318
"1": { "name": "invalid.illegal.tm markup.underline regex" },
@@ -1325,8 +1326,35 @@
13251326
}
13261327
},
13271328
{
1329+
"//": "[pP] degrades performance :shrug:",
1330+
"comment": "https://github.com/kkos/oniguruma/blob/v6.9.8/doc/UNICODE_PROPERTIES",
1331+
"begin": "(\\\\{2}p{)(\\^)?+",
1332+
"end": "}|$|(?=[(){|\"])",
1333+
"beginCaptures": {
1334+
"1": { "name": "variable.language.tm" },
1335+
"2": { "name": "support.function.tm" }
1336+
},
1337+
"endCaptures": { "0": { "name": "variable.language.tm" } },
1338+
"name": "unicode.properties.tm",
1339+
"patterns": [
1340+
{
1341+
"match": "[a-zA-Z1]+",
1342+
"name": "variable.other.enummember.tm"
1343+
},
1344+
{
1345+
"match": "[ _-]+",
1346+
"name": "comment.tm"
1347+
},
1348+
{
1349+
"match": "[^\"(){}|a-zA-Z1 _-]+",
1350+
"name": "invalid.illegal.regex.tm"
1351+
}
1352+
]
1353+
},
1354+
{
1355+
"//": "[pP] degrades performance :shrug:",
13281356
"comment": "https://github.com/kkos/oniguruma/blob/v6.9.8/doc/UNICODE_PROPERTIES",
1329-
"begin": "(\\\\{2}[pP]{)(\\^)?",
1357+
"begin": "(\\\\{2}P{)(\\^)?+",
13301358
"end": "}|$|(?=[(){|\"])",
13311359
"beginCaptures": {
13321360
"1": { "name": "variable.language.tm" },
@@ -1396,7 +1424,7 @@
13961424
"patterns": [
13971425
{
13981426
"comment": "\\1",
1399-
"match": "(\\\\{2})([1-9][0-9]{2,})([0-9]*+)",
1427+
"match": "(\\\\{2})([1-9][0-9]{2,0})([0-9]*+)",
14001428
"captures": {
14011429
"1": { "name": "string.regexp.tm" },
14021430
"2": { "name": "constant.numeric.tm" },
@@ -1433,7 +1461,8 @@
14331461
"name": "invalid.illegal.tm markup.underline"
14341462
},
14351463
{
1436-
"match": "^(?>[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})",
1464+
"comment": "For some reason it isn't very performant using ^",
1465+
"match": "\\A(?>[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})",
14371466
"name": "invalid.illegal.tm markup.underline"
14381467
},
14391468
{

0 commit comments

Comments
 (0)