Skip to content

Commit

Permalink
feat: properly optimize regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 29, 2024
1 parent f3d0912 commit db6b460
Show file tree
Hide file tree
Showing 53 changed files with 627 additions and 584 deletions.
78 changes: 39 additions & 39 deletions packages/tm-grammars/README.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/tm-grammars/grammars/abap.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/tm-grammars/grammars/angular-ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@
"name": "invalid.illegal.syntax.jsdoc"
}
},
"match": "(\\[)\\s*[\\w$]+(?:(?:\\[\\])?\\.[\\w$]+)*(?:\\s*(=)\\s*((?>\"(?:(?:\\*(?!/))|(?:\\\\(?!\"))|[^*\\\\])*?\"|'(?:(?:\\*(?!/))|(?:\\\\(?!'))|[^*\\\\])*?'|\\[\\s(?:(?:\\*(?!/))|[^*])*?\\]|(?:(?:\\*(?!/))|\\s(?!\\s*\\])|\\[.*?(?:\\]|(?=\\*/))|[^*\\s\\[\\]])*)*))?\\s*(?:(\\])((?:[^*\\s]|\\*[^\\s/])+)?|(?=\\*/))",
"match": "(\\[)\\s*[\\w$]+(?:(?:\\[\\])?\\.[\\w$]+)*(?:\\s*(=)\\s*((?>\"(?:(?:\\*(?!/))|(?:\\\\(?!\"))|[^*\\\\])*?\"|'(?:(?:\\*(?!/))|(?:\\\\(?!'))|[^*\\\\])*?'|\\[(?:(?:\\*(?!/))|[^*])*?\\]|(?:(?:\\*(?!/))|\\s(?!\\s*\\])|\\[.*?(?:\\]|(?=\\*/))|[^*\\s\\[\\]])*)*))?\\s*(?:(\\])((?:[^*\\s]|\\*[^\\s/])+)?|(?=\\*/))",
"name": "variable.other.jsdoc"
}
]
Expand Down
2 changes: 1 addition & 1 deletion packages/tm-grammars/grammars/apl.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
"definition": {
"patterns": [
{
"begin": "^\\s*?(?#1:keyword.operator.nabla.apl)(∇)(?:\\s*(?:(?#2:entity.function.return-value.apl)([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*)|\\s*(?#3:entity.function.return-value.shy.apl)((\\{)(?#4:punctuation.definition.return-value.begin.apl)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\})(?#5:punctuation.definition.return-value.end.apl)|(\\()(?#6:punctuation.definition.return-value.begin.apl)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\))(?#7:punctuation.definition.return-value.end.apl)|(\\(\\s*\\{)(?#8:punctuation.definition.return-value.begin.apl)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\}\\s*\\))(?#9:punctuation.definition.return-value.end.apl)|(\\{\\s*\\()(?#10:punctuation.definition.return-value.begin.apl)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\)\\s*\\})(?#11:punctuation.definition.return-value.end.apl))\\s*)\\s*(?#12:keyword.operator.assignment.apl)(←))?\\s*(?:(?#MONADIC)(?:(?#13:entity.function.name.apl)([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*)\\s*(?#14:entity.function.axis.apl)((?#15:punctuation.definition.axis.begin.apl)(\\[)\\s\\s*\\s(?:\\s\\s*\\s[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*(?#16:invalid.illegal.extra-characters.apl)(.*?)|(?#17:invalid.illegal.apl)([^\\]]*))\\s*(?#18:punctuation.definition.axis.end.apl)(\\]))?\\s*?(?#19:entity.function.arguments.right.apl)((?<=\\s|\\])[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*|(\\()(?#20:punctuation.definition.arguments.begin.apl)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\))(?#21:punctuation.definition.arguments.end.apl))\\s*(?=;|$))|(?#DYADIC/AMBIVALENT)(?#==================)(?:(?#22:entity.function.arguments.left.apl)([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s+)|(?#23:entity.function.arguments.left.optional.apl)((\\{)(?#24:punctuation.definition.arguments.begin.apl)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\})(?#25:punctuation.definition.arguments.end.apl)|(\\(\\s*\\{)(?#26:punctuation.definition.arguments.begin.apl)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\}\\s*\\))(?#27:punctuation.definition.arguments.end.apl)|(\\{\\s*\\()(?#28:punctuation.definition.arguments.begin.apl)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\)\\s*\\})(?#29:punctuation.definition.arguments.end.apl)))?\\s*(?:(?#30:entity.function.name.apl)([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*)\\s*(?#31:entity.function.axis.apl)((?#32:punctuation.definition.axis.begin.apl)(\\[)\\s\\s*\\s(?:\\s\\s*\\s[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*(?#33:invalid.illegal.extra-characters.apl)(.*?)|(?#34:invalid.illegal.apl)([^\\]]*))\\s*(?#35:punctuation.definition.axis.end.apl)(\\]))?|(?#36:entity.function.operands.apl)((?#37:punctuation.definition.operands.begin.apl)(\\()(?#38:entity.function.operands.left.apl)(\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*)?\\s*(?#39:entity.function.name.apl)([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*)\\s*?(?#40:entity.function.axis.apl)((?#41:punctuation.definition.axis.begin.apl)(\\[)\\s\\s*\\s(?:\\s\\s*\\s[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*(?#42:invalid.illegal.extra-characters.apl)(.*?)|(?#43:invalid.illegal.apl)([^\\]]*))\\s*(?#44:punctuation.definition.axis.end.apl)(\\]))?\\s*(?#45:entity.function.operands.right.apl)([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)?(?#46:punctuation.definition.operands.end.apl)(\\))))\\s*(?#47:entity.function.arguments.right.apl)((?<=\\s|\\])[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*|\\s*(\\()(?#48:punctuation.definition.arguments.begin.apl)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\))(?#49:punctuation.definition.arguments.end.apl))?(?#==================))\\s*(?#50:invalid.illegal.arguments.right.apl)([^;]+)?(?#51:entity.function.local-variables.apl)((?#52:Include“;”)((?>\\s*;(?:\\s*[⎕A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)+)+)|(?#53:invalid.illegal.local-variables.apl)([^⍝]+))?\\s*(?#54:comment.line.apl)(⍝.*)?$",
"begin": "^\\s*?(∇)(?:\\s*(?:([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*)|\\s*((\\{)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\})|(\\()(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\))|(\\(\\s*\\{)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\}\\s*\\))|(\\{\\s*\\()(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\)\\s*\\}))\\s*)\\s*(←))?\\s*(?:(?:([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*)\\s*((\\[)\\s*(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*(.*?)|([^\\]]*))\\s*(\\]))?\\s*?((?<=\\s|\\])[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*|(\\()(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\)))\\s*(?=;|$))|(?:([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s+)|((\\{)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\})|(\\(\\s*\\{)(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\}\\s*\\))|(\\{\\s*\\()(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\)\\s*\\})))?\\s*(?:([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*)\\s*((\\[)\\s*(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*(.*?)|([^\\]]*))\\s*(\\]))?|((\\()(\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*)?\\s*([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*)\\s*?((\\[)\\s*(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*(.*?)|([^\\]]*))\\s*(\\]))?\\s*([A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)?(\\))))\\s*((?<=\\s|\\])[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*|\\s*(\\()(?:\\s*[A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)*(\\)))?)\\s*([^;]+)?(((?>\\s*;(?:\\s*[⎕A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ][A-Z_a-zÀ-ÖØ-Ýßà-öø-üþ∆⍙Ⓐ-Ⓩ¯0-9]*\\s*)+)+)|([^⍝]+))?\\s*(⍝.*)?$",
"beginCaptures": {
"0": {
"name": "entity.function.definition.apl"
Expand Down
12 changes: 6 additions & 6 deletions packages/tm-grammars/grammars/applescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
]
},
{
"begin": "^(?x)\n\\s*(to|on)\\s+\n(\\w+)\n(\\()\n((?:[\\s,:\\{\\}]*(?:\\w+)?)*)\n(\\))\n",
"begin": "^\\s*(to|on)\\s+(\\w+)(\\()((?:[\\s,:\\{\\}]*(?:\\w+)?)*)(\\))",
"beginCaptures": {
"1": {
"name": "keyword.control.function.applescript"
Expand Down Expand Up @@ -95,7 +95,7 @@
]
},
{
"begin": "^(?x)\n\\s*(to|on)\\s+\n(\\w+)\n(?:\\s+\n(of|in)\\s+\n(\\w+)\n)?\n(?=\\s+(above|against|apart\\s+from|around|aside\\s+from|at|below|beneath|beside|between|by|for|from|instead\\s+of|into|on|onto|out\\s+of|over|thru|under)\\b)\n",
"begin": "^\\s*(to|on)\\s+(\\w+)(?:\\s+(of|in)\\s+(\\w+))?(?=\\s+(above|against|apart\\s+from|around|aside\\s+from|at|below|beneath|beside|between|by|for|from|instead\\s+of|into|on|onto|out\\s+of|over|thru|under)\\b)",
"beginCaptures": {
"1": {
"name": "keyword.control.function.applescript"
Expand Down Expand Up @@ -136,7 +136,7 @@
]
},
{
"begin": "^(?x)\n\\s*(to|on)\\s+\n(\\w+)\n(?=\\s*(--.*?)?$)\n",
"begin": "^\\s*(to|on)\\s+(\\w+)(?=\\s*(--.*?)?$)",
"beginCaptures": {
"1": {
"name": "keyword.control.function.applescript"
Expand Down Expand Up @@ -860,12 +860,12 @@
"name": "keyword.operator.comparison.applescript"
},
{
"match": "(?ix)\\b\n(and|or|div|mod|as|not\n|(a\\s+)?(ref(\\s+to)?|reference\\s+to)\n|equal(s|\\s+to)|contains?|comes\\s+(after|before)|(start|begin|end)s?\\s+with\n)\n\\b",
"match": "(?ix)\\b\n\t\t\t\t\t\t(and|or|div|mod|as|not\n\t\t\t\t\t\t|(a\\s+)?(ref(\\s+to)?|reference\\s+to)\n\t\t\t\t\t\t|equal(s|\\s+to)|contains?|comes\\s+(after|before)|(start|begin|end)s?\\s+with\n\t\t\t\t\t\t)\n\t\t\t\t\t\\b",
"name": "keyword.operator.word.applescript"
},
{
"comment": "In double quotes so we can use a single quote in the keywords.",
"match": "(?ix)\\b\n(is(n't|\\s+not)?(\\s+(equal(\\s+to)?|(less|greater)\\s+than(\\s+or\\s+equal(\\s+to)?)?|in|contained\\s+by))?\n|does(n't|\\s+not)\\s+(equal|come\\s+(before|after)|contain)\n)\n\\b",
"match": "(?ix)\\b\n\t\t\t\t\t\t(is(n't|\\s+not)?(\\s+(equal(\\s+to)?|(less|greater)\\s+than(\\s+or\\s+equal(\\s+to)?)?|in|contained\\s+by))?\n\t\t\t\t\t\t|does(n't|\\s+not)\\s+(equal|come\\s+(before|after)|contain)\n\t\t\t\t\t\t)\n\t\t\t\t\t\\b",
"name": "keyword.operator.word.applescript"
},
{
Expand Down Expand Up @@ -927,7 +927,7 @@
"name": "support.class.built-in.applescript"
},
{
"match": "(?ix)\\b\n(\t(cubic\\s+(centi)?|square\\s+(kilo)?|centi|kilo)met(er|re)s\n|\tsquare\\s+(yards|feet|miles)|cubic\\s+(yards|feet|inches)|miles|inches\n|\tlit(re|er)s|gallons|quarts\n|\t(kilo)?grams|ounces|pounds\n|\tdegrees\\s+(Celsius|Fahrenheit|Kelvin)\n)\n\\b",
"match": "(?ix)\\b\n\t\t\t\t\t\t(\t(cubic\\s+(centi)?|square\\s+(kilo)?|centi|kilo)met(er|re)s\n\t\t\t\t\t\t|\tsquare\\s+(yards|feet|miles)|cubic\\s+(yards|feet|inches)|miles|inches\n\t\t\t\t\t\t|\tlit(re|er)s|gallons|quarts\n\t\t\t\t\t\t|\t(kilo)?grams|ounces|pounds\n\t\t\t\t\t\t|\tdegrees\\s+(Celsius|Fahrenheit|Kelvin)\n\t\t\t\t\t\t)\n\t\t\t\t\t\\b",
"name": "support.class.built-in.unit.applescript"
},
{
Expand Down
Loading

0 comments on commit db6b460

Please sign in to comment.