Skip to content

Commit

Permalink
Improve TextMate syntax performance
Browse files Browse the repository at this point in the history
  • Loading branch information
RedCMD committed Dec 7, 2024
1 parent b2ecc87 commit ca75bcc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
],
"configurationDefaults": {
"[json-textmate]": {
"editor.maxTokenizationLineLength": 500000,
"editor.maxTokenizationLineLength": 600000,
"editor.suggest.insertMode": "replace",
"editor.suggest.preview": true,
"editor.quickSuggestions": {
Expand Down
16 changes: 12 additions & 4 deletions syntaxes/json.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -785,15 +785,15 @@
{ "match": "\\w+" },
{
"comment": "An invalid capture group number does not convert, nor becomes null",
"match": "(\\$)(0*)(\\d{1,3})(?!\\d)",
"match": "(\\$)(0*)(\\d{3,1})(?!\\d)",
"captures": {
"1": { "name": "meta.embedded constant.character.escape.json.tm markup.italic" },
"2": { "name": "punctuation.definition.tag.json.tm" },
"3": { "name": "constant.numeric.json.tm" }
}
},
{
"match": "(\\$)({)(0*)(\\d{1,3})(:/)(upcase|downcase)(})",
"match": "(\\$)({)(0*)(\\d{3,1})(:/)(upcase|downcase)(})",
"captures": {
"1": { "name": "meta.embedded constant.character.escape.json.tm markup.italic.tm" },
"2": { "name": "meta.embedded constant.character.escape.json.tm" },
Expand Down Expand Up @@ -1246,7 +1246,7 @@
"name": "constant.character.escape.json.tm"
},
{
"match": "(\\\\u)(?>(\\h{4})|([^\"].{,3}))",
"match": "(\\\\u)(\\h{4,0})",
"captures": {
"1": { "name": "constant.character.escape.tm" },
"2": { "name": "constant.numeric.json.tm" },
Expand Down Expand Up @@ -1423,7 +1423,15 @@
]
},
{
"match": "\\b(?>true|false|null)\\b",
"match": "\\btrue\\b",
"name": "constant.language.json.tm"
},
{
"match": "\\bfalse\\b",
"name": "constant.language.json.tm"
},
{
"match": "\\bnull\\b",
"name": "constant.language.json.tm"
},
{
Expand Down
57 changes: 43 additions & 14 deletions syntaxes/regex.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@
},
{
"comment": "(?y{g}-imxWDSP) (?y{w}imxWDSP-x: ...)",
"begin": "(?>(\\((?=[^:)]+:))|(\\())(\\?)(?=[-IimxWDSPy])(?=[^x:)]++[:)]|[^-:)]*+-[^x:)]*+x[^:)]*+[:)])",
"begin": "(?=\\(\\?[-IimxWDSPy])(?>(\\((?=[^:)]++:))|(\\())(\\?)(?=[^x:)]++[:)]|[^-:)]*+-[^x:)]*+x[^:)]*+[:)])",
"end": "(?((?!\\1))\\)|(?=[\")]))(?#Condition is true only when Backreference \\1 from capture group 1 in \"begin\" is *not* empty.)|(?=\")",
"beginCaptures": {
"1": { "name": "constant.character.set.regexp.tm" },
Expand All @@ -451,12 +451,12 @@
"capture-group-modify-extended": {
"patterns": [
{
"match": "\\(\\?-+:?\\)",
"match": "\\(\\?-++:?+\\)",
"name": "punctuation.definition.tag.tm"
},
{
"comment": "(?y{g}imxWDSP-) (?y{w}x-imWDSP:...)",
"begin": "(?>(\\((?=[^:)]++:))|(\\())(\\?)(?=[-IimxWDSPy])(?=[^-:)]*+[^x:)]*+[:)])",
"begin": "(?=\\(\\?[-IimxWDSPy])(?>(\\((?=[^:)]++:))|(\\())(\\?)(?=[^-:)]*+[^x:)]*+[:)])",
"end": "(?((?!\\1))\\)|(?=[\")]))(?#Condition is true only when Backreference \\1 from capture group 1 in \"begin\" is *not* empty.)|(?=\")",
"beginCaptures": {
"1": { "name": "constant.character.set.regexp.tm" },
Expand Down Expand Up @@ -670,7 +670,7 @@
},
"absent": {
"comment": "(?~|...|...) (?~|...) (?~...) (?~|)",
"begin": "(\\()(\\?~\\|?)",
"begin": "(\\()(\\?~\\|?+)",
"end": "\\)|(?=\")",
"beginCaptures": {
"1": { "name": "constant.character.set.regexp.tm" },
Expand Down Expand Up @@ -788,7 +788,7 @@
},
{
"comment": "(*name[tag]{args...})",
"match": "(\\()(\\*)([A-Za-z_]\\w*)([^\\[{)]*)(?>(\\[)([^]]*)(]))?([^{)]*)(?>({)([^}]*)(}))?([^)]*)(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?",
"match": "(\\()(\\*)([A-Za-z_]\\w*+)([^\\[{)]*+)(?>(\\[)([^]]*+)(]))?+([^{)]*+)(?>({)([^}]*+)(}))?+([^)]*+)(\\))([+*?]|(?D){(?>\\d++,?+\\d*+|,\\d++)})?+",
"captures": {
"1": { "name": "constant.character.set.regexp.tm markup.italic" },
"2": { "name": "support.function.tm" },
Expand Down Expand Up @@ -941,7 +941,7 @@
}
},
{
"match": "(\\*(-)\\+)(\\\\{2}(?=-))?",
"match": "(\\*(-)\\+)(\\\\{2}(?=-))?+",
"captures": {
"1": { "name": "character-class-range.tm support.class.tm" },
"2": { "name": "punctuation.definition.tag.tm strong" },
Expand Down Expand Up @@ -1231,7 +1231,8 @@
"comment": "\\777 \\xFF \\cZ \\o{0 4777777} \\x{0 13FFFF} \\u0000 \\p{L} \\C-\\M-]",
"patterns": [
{
"match": "(\\\\{2})([Ppox])(\\\\{2})({)",
"comment": "The look-ahead increases performance. No clue why :shrug:",
"match": "(\\\\{2})([Ppox])(?=\\\\\\\\{)(\\\\{2})({)",
"captures": {
"1": { "name": "punctuation.definition.tag.tm" },
"2": { "name": "entity.name.label.tm strong" },
Expand Down Expand Up @@ -1280,21 +1281,21 @@
]
},
{
"match": "(\\\\{2})([0-7]{1,3})",
"match": "(\\\\{2})([0-7]{3,1})",
"captures": {
"1": { "name": "punctuation.definition.list.begin.markdown.tm" },
"2": { "name": "constant.numeric.tm" }
}
},
{
"match": "(\\\\{2}x)(?!{|\")(\\h{,2})",
"match": "(\\\\{2}x)(?!{|\")(\\h{2,0})",
"captures": {
"1": { "name": "punctuation.definition.list.begin.markdown.tm" },
"2": { "name": "constant.numeric.tm" }
}
},
{
"match": "(?>(\\\\{2}u)|(\\\\u))(?>(\\h{4})|([^\"].{3,}))",
"match": "(?>(\\\\{2}u)|(\\\\u))(?>(\\h{4})|([^\"].{3,0}))",
"captures": {
"1": { "name": "variable.language.tm" },
"2": { "name": "constant.character.escape.tm" },
Expand All @@ -1311,7 +1312,7 @@
}
},
{
"match": "\\\\{2}(?>c|[CM](?>-|(.))?+)(?>(\\\\{3})(\\\\)|\\g<0>|(\\\\{2})?+(\\\\u.{4,}|\\\\?+.))?+",
"match": "\\\\{2}(?>c|[CM](?>-|(.))?+)(?>(\\\\{3})(\\\\)|\\g<0>|(\\\\{2})?+(\\\\u.{4,0}|\\\\?+.))?+",
"captures": {
"0": { "name": "punctuation.definition.list.begin.markdown.tm" },
"1": { "name": "invalid.illegal.tm markup.underline regex" },
Expand All @@ -1325,8 +1326,35 @@
}
},
{
"//": "[pP] degrades performance :shrug:",
"comment": "https://github.com/kkos/oniguruma/blob/v6.9.8/doc/UNICODE_PROPERTIES",
"begin": "(\\\\{2}p{)(\\^)?+",
"end": "}|$|(?=[(){|\"])",
"beginCaptures": {
"1": { "name": "variable.language.tm" },
"2": { "name": "support.function.tm" }
},
"endCaptures": { "0": { "name": "variable.language.tm" } },
"name": "unicode.properties.tm",
"patterns": [
{
"match": "[a-zA-Z1]+",
"name": "variable.other.enummember.tm"
},
{
"match": "[ _-]+",
"name": "comment.tm"
},
{
"match": "[^\"(){}|a-zA-Z1 _-]+",
"name": "invalid.illegal.regex.tm"
}
]
},
{
"//": "[pP] degrades performance :shrug:",
"comment": "https://github.com/kkos/oniguruma/blob/v6.9.8/doc/UNICODE_PROPERTIES",
"begin": "(\\\\{2}[pP]{)(\\^)?",
"begin": "(\\\\{2}P{)(\\^)?+",
"end": "}|$|(?=[(){|\"])",
"beginCaptures": {
"1": { "name": "variable.language.tm" },
Expand Down Expand Up @@ -1396,7 +1424,7 @@
"patterns": [
{
"comment": "\\1",
"match": "(\\\\{2})([1-9][0-9]{2,})([0-9]*+)",
"match": "(\\\\{2})([1-9][0-9]{2,0})([0-9]*+)",
"captures": {
"1": { "name": "string.regexp.tm" },
"2": { "name": "constant.numeric.tm" },
Expand Down Expand Up @@ -1433,7 +1461,8 @@
"name": "invalid.illegal.tm markup.underline"
},
{
"match": "^(?>[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})",
"comment": "For some reason it isn't very performant using ^",
"match": "\\A(?>[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})",
"name": "invalid.illegal.tm markup.underline"
},
{
Expand Down

0 comments on commit ca75bcc

Please sign in to comment.