diff --git a/.gitmodules b/.gitmodules index e7ce67b..9f29130 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,9 +7,6 @@ [submodule "sublime_syntaxes/LESS-sublime"] path = sublime_syntaxes/LESS-sublime url = https://github.com/danro/LESS-sublime.git -[submodule "sublime_syntaxes/TypeScript-Sublime-Plugin"] - path = sublime_syntaxes/TypeScript-Sublime-Plugin - url = https://github.com/Microsoft/TypeScript-Sublime-Plugin.git [submodule "sublime_syntaxes/Handlebars"] path = sublime_syntaxes/Handlebars url = https://github.com/daaain/Handlebars.git @@ -31,3 +28,6 @@ [submodule "sublime_syntaxes/Sublime-VimL"] path = sublime_syntaxes/Sublime-VimL url = https://github.com/SalGnt/Sublime-VimL.git +[submodule "sublime_syntaxes/TypeScript-TmLanguage"] + path = sublime_syntaxes/TypeScript-TmLanguage + url = https://github.com/Microsoft/TypeScript-TmLanguage diff --git a/docs/content/documentation/content/syntax-highlighting.md b/docs/content/documentation/content/syntax-highlighting.md index cd8a92f..9160bca 100644 --- a/docs/content/documentation/content/syntax-highlighting.md +++ b/docs/content/documentation/content/syntax-highlighting.md @@ -32,7 +32,8 @@ Here is a full list of the supported languages and the short names you can use: - Jinja2 -> ["j2", "jinja2"] - Julia -> ["jl"] - Kotlin -> ["kt", "kts"] -- LESS -> ["less"] +- Less -> ["less", "css.less"] +- Nim -> ["nim", "nims"] - ASP -> ["asa"] - HTML (ASP) -> ["asp"] - ActionScript -> ["as"] @@ -57,12 +58,12 @@ Here is a full list of the supported languages and the short names you can use: - Java Server Page (JSP) -> ["jsp"] - Java -> ["java", "bsh"] - Java Properties -> ["properties"] -- JSON -> ["json", "sublime-settings", "sublime-menu", "sublime-keymap", "sublime-mousemap", "sublime-theme", "sublime-build", "sublime-project", "sublime-completions", "sublime-commands", "sublime-macro"] +- JSON -> ["json", "sublime-settings", "sublime-menu", "sublime-keymap", "sublime-mousemap", "sublime-theme", "sublime-build", "sublime-project", "sublime-completions", "sublime-commands", "sublime-macro", "sublime-color-scheme"] - JavaScript -> ["js", "htc"] - BibTeX -> ["bib"] - LaTeX -> ["tex", "ltx"] - TeX -> ["sty", "cls"] -- Lisp -> ["lisp", "cl", "l", "mud", "el", "scm", "ss", "lsp", "fasl"] +- Lisp -> ["lisp", "cl", "clisp", "l", "mud", "el", "scm", "ss", "lsp", "fasl"] - Lua -> ["lua"] - Makefile -> ["make", "GNUmakefile", "makefile", "Makefile", "OCamlMakefile", "mak", "mk"] - Markdown -> ["md", "mdown", "markdown", "markdn"] @@ -89,13 +90,14 @@ Here is a full list of the supported languages and the short names you can use: - Rust -> ["rs"] - SQL -> ["sql", "ddl", "dml"] - Scala -> ["scala", "sbt"] -- Bourne Again Shell (bash) -> ["sh", "bash", "zsh", "fish", ".bash_aliases", ".bash_functions", ".bash_login", ".bash_logout", ".bash_profile", ".bash_variables", ".bashrc", ".profile", ".textmate_init"] +- Bourne Again Shell (bash) -> ["sh", "bash", "zsh", "fish", ".bash_aliases", ".bash_completions", ".bash_functions", ".bash_login", ".bash_logout", ".bash_profile", ".bash_variables", ".bashrc", ".profile", ".textmate_init"] - HTML (Tcl) -> ["adp"] - Tcl -> ["tcl"] - Textile -> ["textile"] - XML -> ["xml", "xsd", "xslt", "tld", "dtml", "rss", "opml", "svg"] - YAML -> ["yaml", "yml", "sublime-syntax"] -- Generic Config -> ["cfg", "conf", "config", "ini", "pro"] +- SWI-Prolog -> ["pro"] +- Generic Config -> ["cfg", "conf", "config", "ini", "pro", "mak", "mk", "Doxyfile", "inputrc", ".inputrc", "dircolors", ".dircolors", "gitmodules", ".gitmodules", "gitignore", ".gitignore", "gitattributes", ".gitattributes"] - Linker Script -> ["ld"] - TOML -> ["toml", "tml"] - TypeScript -> ["ts"] diff --git a/sublime_syntaxes/Elm.sublime-syntax b/sublime_syntaxes/Elm.sublime-syntax deleted file mode 100644 index 9e9eb66..0000000 --- a/sublime_syntaxes/Elm.sublime-syntax +++ /dev/null @@ -1,200 +0,0 @@ -%YAML 1.2 ---- -# http://www.sublimetext.com/docs/3/syntax.html -name: Elm -file_extensions: - - elm -scope: source.elm -contexts: - main: - - match: "(`)[a-zA-Z_']*?(`)" - scope: keyword.operator.function.infix.elm - captures: - 1: punctuation.definition.entity.elm - 2: punctuation.definition.entity.elm - - match: \(\) - scope: constant.language.unit.elm - - match: ^\b((effect|port)\s+)?(module)\s+ - captures: - 1: keyword.other.elm - 3: keyword.other.elm - push: - - meta_scope: meta.declaration.module.elm - - match: $|; - captures: - 1: keyword.other.elm - pop: true - - include: module_name - - match: '(where)\s*\{' - captures: - 1: keyword.other.elm - push: - - match: '\}' - pop: true - - include: type_signature - - match: (exposing) - scope: keyword.other.elm - - include: module_exports - - match: (where) - scope: keyword.other.elm - - match: "[a-z]+" - scope: invalid - - match: ^\b(import)\s+((open)\s+)? - captures: - 1: keyword.other.elm - 3: invalid - push: - - meta_scope: meta.import.elm - - match: ($|;) - pop: true - - match: (as|exposing) - scope: keyword.import.elm - - include: module_name - - include: module_exports - - match: '(\[)(glsl)(\|)' - captures: - 1: keyword.other.elm - 2: support.function.prelude.elm - 3: keyword.other.elm - push: - - meta_scope: entity.glsl.elm - - match: '(\|\])' - captures: - 1: keyword.other.elm - pop: true - - include: scope:source.glsl - - match: \b(type alias|type|case|of|let|in|as)\s+ - scope: keyword.other.elm - - match: \b(if|then|else)\s+ - scope: keyword.control.elm - - match: '\b([0-9]+\.[0-9]+([eE][+-]?[0-9]+)?|[0-9]+[eE][+-]?[0-9]+)\b' - comment: Floats are always decimal - scope: constant.numeric.float.elm - - match: '\b([0-9]+)\b' - scope: constant.numeric.elm - - match: '"""' - captures: - 0: punctuation.definition.string.begin.elm - push: - - meta_scope: string.quoted.double.elm - - match: '"""' - captures: - 0: punctuation.definition.string.end.elm - pop: true - - match: '\\(NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|[abfnrtv\\''\&])' - scope: constant.character.escape.elm - - match: '\^[A-Z@\[\]\\\^_]' - scope: constant.character.escape.control.elm - - match: '"' - captures: - 0: punctuation.definition.string.begin.elm - push: - - meta_scope: string.quoted.double.elm - - match: '"' - captures: - 0: punctuation.definition.string.end.elm - pop: true - - match: '\\(NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|[abfnrtv\\\"''\&])' - scope: constant.character.escape.elm - - match: '\^[A-Z@\[\]\\\^_]' - scope: constant.character.escape.control.elm - - match: |- - (?x) - (') - (?: - [\ -\[\]-~] # Basic Char - | (\\(?:NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE - |DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS - |US|SP|DEL|[abfnrtv\\\"'\&])) # Escapes - | (\^[A-Z@\[\]\\\^_]) # Control Chars - ) - (') - scope: string.quoted.single.elm - captures: - 1: punctuation.definition.string.begin.elm - 2: constant.character.escape.elm - 3: punctuation.definition.string.end.elm - - match: '^(port\s+)?([a-z_][a-zA-Z0-9_'']*|\([|!%$+\-.,=]+\))\s*((:)([:]+)?)' - captures: - 1: keyword.other.port.elm - 2: entity.name.function.elm - 4: keyword.other.colon.elm - 5: invalid - push: - - meta_scope: meta.function.type-declaration.elm - - match: $\n? - pop: true - - include: type_signature - - match: \bport\s+ - scope: keyword.other.port.elm - - match: '\b[A-Z]\w*\b' - scope: constant.other.elm - - include: comments - - match: '^[a-z][A-Za-z0-9_'']*\s+' - scope: entity.name.function.elm - - include: infix_op - - match: '[|!%$?~+:\-.=&\\*^]+' - scope: keyword.operator.elm - - match: '([\[\]\{\},])' - scope: constant.language.delimiter.elm - captures: - 1: support.function.delimiter.elm - - match: '([\(\)])' - scope: keyword.other.parenthesis.elm - block_comment: - - match: '\{-(?!#)' - captures: - 0: punctuation.definition.comment.elm - push: - - meta_scope: comment.block.elm - - include: block_comment - - match: '-\}' - captures: - 0: punctuation.definition.comment.elm - pop: true - comments: - - match: (--).*$\n? - scope: comment.line.double-dash.elm - captures: - 1: punctuation.definition.comment.elm - - include: block_comment - infix_op: - - match: '(\([|!%$+:\-.=]+\)|\(,+\))' - scope: entity.name.function.infix.elm - module_exports: - - match: \( - push: - - meta_scope: meta.declaration.exports.elm - - match: \) - pop: true - - match: '\b[a-z][a-zA-Z_''0-9]*' - scope: entity.name.function.elm - - match: '\b[A-Z][A-Za-z_''0-9]*' - scope: storage.type.elm - - match: "," - scope: punctuation.separator.comma.elm - - include: infix_op - - match: \(.*?\) - comment: So named because I don't know what to call this. - scope: meta.other.unknown.elm - module_name: - - match: "[A-Z][A-Za-z._']*" - scope: support.other.module.elm - type_signature: - - match: '\(\s*([A-Z][A-Za-z]*)\s+([a-z][A-Za-z_'']*)\)\s*(=>)' - scope: meta.class-constraint.elm - captures: - 1: entity.other.inherited-class.elm - 2: variable.other.generic-type.elm - 3: keyword.other.big-arrow.elm - - match: "->" - scope: keyword.other.arrow.elm - - match: "=>" - scope: keyword.other.big-arrow.elm - - match: '\b[a-z][a-zA-Z0-9_'']*\b' - scope: variable.other.generic-type.elm - - match: '\b[A-Z][a-zA-Z0-9_'']*\b' - scope: storage.type.elm - - match: \(\) - scope: support.constant.unit.elm - - include: comments diff --git a/sublime_syntaxes/LESS.sublime-syntax b/sublime_syntaxes/LESS.sublime-syntax deleted file mode 100644 index 38cfd30..0000000 --- a/sublime_syntaxes/LESS.sublime-syntax +++ /dev/null @@ -1,326 +0,0 @@ -%YAML 1.2 ---- -# http://www.sublimetext.com/docs/3/syntax.html -name: LESS -comment: LESS -file_extensions: - - less -scope: source.less -contexts: - main: - - include: comment-block - - include: comment-line - - include: less-at-rules - - include: less-declarations - - include: less-variables - - include: less-functions - - include: string-double - - include: string-single - - include: selector - - include: rule-list - - include: less-operators - - include: less-parameters - - include: numeric-values - color-values: - - match: \b(aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow)\b - comment: http://www.w3.org/TR/CSS21/syndata.html#value-def-color - scope: support.constant.color.w3c-standard-color-name.css - - match: \b(aliceblue|antiquewhite|aquamarine|azure|beige|bisque|blanchedalmond|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|gainsboro|ghostwhite|gold|goldenrod|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|limegreen|linen|magenta|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|oldlace|olivedrab|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|thistle|tomato|turquoise|violet|wheat|whitesmoke|yellowgreen)\b - comment: "These colours are mostly recognised but will not validate. ref: http://www.w3schools.com/css/css_colornames.asp" - scope: support.constant.color.non-standard - - match: (hsla?|rgba?)\s*(\() - captures: - 1: support.function.misc.css - 2: punctuation.section.function.css - push: - - match: (\)) - captures: - 1: punctuation.section.function.css - pop: true - - match: '(?x)\b(0*((1?[0-9]{1,2})|(2([0-4][0-9]|5[0-5])))\s*,\s*){2}(0*((1?[0-9]{1,2})|(2([0-4][0-9]|5[0-5])))\b)(\s*,\s*((0?\.[0-9]+)|[0-1]))?' - scope: constant.other.color.rgb-value.css - - match: '\b([0-9]{1,2}|100)\s*%,\s*([0-9]{1,2}|100)\s*%,\s*([0-9]{1,2}|100)\s*%' - scope: constant.other.color.rgb-percentage.css - - include: numeric-values - comment-block: - - match: /\* - captures: - 0: punctuation.definition.comment.css - push: - - meta_scope: comment.block.css - - match: \*/ - captures: - 0: punctuation.definition.comment.css - pop: true - comment-line: - - match: // - captures: - 0: punctuation.definition.comment.css - push: - - meta_scope: comment.line.double-slash.less - - match: $\n? - captures: - 0: punctuation.definition.comment.css - pop: true - less-at-rules: - - match: ^\s*((@)(?:-(?:webkit|moz|o)-)?(charset|import|namespace|media|page|font-face|keyframes|supports|document)\b) - scope: meta.at-rule.css - captures: - 1: keyword.control.at-rule.css - 2: punctuation.definition.keyword.css - less-data-uri: - - match: (url)(\()(data:) - captures: - 1: support.function.misc.css - 2: punctuation.section.function.css - 3: parameter.less.data-uri comment markup.raw - push: - - meta_content_scope: parameter.less.data-uri comment markup.raw - - match: (\)) - captures: - 1: punctuation.section.function.css - pop: true - - match: (url)(\()("data:) - captures: - 1: support.function.misc.css - 2: punctuation.section.function.css - 3: parameter.less.data-uri comment markup.raw - push: - - meta_content_scope: parameter.less.data-uri comment markup.raw - - match: (?<=")(\)) - captures: - 1: punctuation.section.function.css - pop: true - - match: (url)(\()('data:) - captures: - 1: support.function.misc.css - 2: punctuation.section.function.css - 3: parameter.less.data-uri comment markup.raw - push: - - meta_content_scope: parameter.less.data-uri comment markup.raw - - match: (?<=\')(\)) - captures: - 1: punctuation.section.function.css - pop: true - less-declarations: - - match: '(?>@[a-zA-Z0-9_-][\w-]*+)(?!:)' - scope: variable.other.less - - match: '@[a-zA-Z0-9_-][\w-]*' - scope: variable.declaration.less - less-functions: - - match: '([%a-zA-Z\-\_\d]*)(?=\()' - scope: support.function.less - - match: '([\.#](?![0-9])[a-zA-Z0-9_-]+(?=\())' - captures: - 1: entity.other.attribute-name.class.css entity.other.less.mixin - less-operators: - - match: /|!important|$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|(?([''"])(?:[^\\]|\\.)*?(\6)))))?\s*(\])' - scope: meta.attribute-selector.css - captures: - 1: punctuation.definition.entity.css - 2: entity.other.attribute-name.attribute.css - 3: punctuation.separator.operator.css - 4: string.unquoted.attribute-value.css - 5: string.quoted.double.attribute-value.css - 6: punctuation.definition.string.begin.css - 7: punctuation.definition.string.end.css - string-double: - - match: '"' - captures: - 0: punctuation.definition.string.begin.css - push: - - meta_scope: string.quoted.double.css - - match: '"' - captures: - 0: punctuation.definition.string.end.css - pop: true - - match: \\. - scope: constant.character.escape.css - string-single: - - match: "'" - captures: - 0: punctuation.definition.string.begin.css - push: - - meta_scope: string.quoted.single.css - - match: "'" - captures: - 0: punctuation.definition.string.end.css - pop: true - - match: \\. - scope: constant.character.escape.css diff --git a/sublime_syntaxes/Prolog.sublime-syntax b/sublime_syntaxes/Prolog.sublime-syntax new file mode 100644 index 0000000..06aa619 --- /dev/null +++ b/sublime_syntaxes/Prolog.sublime-syntax @@ -0,0 +1,135 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html +name: SWI-Prolog +comment: This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +file_extensions: + - pro +scope: source.prolog +contexts: + main: + - include: comments + - match: (?<=:-)\s* + push: + - meta_scope: meta.clause.body.prolog + - match: (\.) + captures: + 1: keyword.control.clause.bodyend.prolog + pop: true + - include: comments + - include: builtin + - include: controlandkeywords + - include: atom + - include: variable + - include: constants + - match: . + scope: meta.clause.body.prolog + - match: '^\s*([a-z][a-zA-Z0-9_]*)(\(?)(?=.*:-.*)' + captures: + 1: entity.name.function.clause.prolog + 2: punctuation.definition.parameters.begin + push: + - meta_scope: meta.clause.head.prolog + - match: ((\)?))\s*(:-) + captures: + 1: punctuation.definition.parameters.end + 3: keyword.control.clause.bodybegin.prolog + pop: true + - include: atom + - include: variable + - include: constants + - match: '^\s*([a-z][a-zA-Z0-9_]*)(\(?)(?=.*-->.*)' + captures: + 1: entity.name.function.dcg.prolog + 2: punctuation.definition.parameters.begin + push: + - meta_scope: meta.dcg.head.prolog + - match: ((\)?))\s*(-->) + captures: + 1: punctuation.definition.parameters.end + 3: keyword.control.dcg.bodybegin.prolog + pop: true + - include: atom + - include: variable + - include: constants + - match: (?<=-->)\s* + push: + - meta_scope: meta.dcg.body.prolog + - match: (\.) + captures: + 1: keyword.control.dcg.bodyend.prolog + pop: true + - include: comments + - include: controlandkeywords + - include: atom + - include: variable + - include: constants + - match: . + scope: meta.dcg.body.prolog + - match: '^\s*([a-zA-Z][a-zA-Z0-9_]*)(\(?)(?!.*(:-|-->).*)' + captures: + 1: entity.name.function.fact.prolog + 2: punctuation.definition.parameters.begin + push: + - meta_scope: meta.fact.prolog + - match: ((\)?))\s*(\.)(?!\d+) + captures: + 1: punctuation.definition.parameters.end + 3: keyword.control.fact.end.prolog + pop: true + - include: atom + - include: variable + - include: constants + atom: + - match: '(?) + captures: + 1: keyword.control.if.prolog + push: + - meta_scope: meta.if.prolog + - match: (;) + captures: + 1: keyword.control.else.prolog + pop: true + - include: main + - include: builtin + - include: comments + - include: atom + - include: variable + - match: . + scope: meta.if.body.prolog + - match: "!" + scope: keyword.control.cut.prolog + - match: (\s(is)\s)|=:=|=?\\?=|\\\+|@?>|@?=?<|\+|\*|\- + scope: keyword.operator.prolog + variable: + - match: "(?)' + - match: '(?:(?)' scope: meta.arrow.ts captures: 1: storage.modifier.async.ts 2: variable.parameter.ts - match: |- (?x) (?: - (? is on new line - ( - [(]\s* - ( - ([)]\s*:) | # (): - ([_$[:alpha:]][_$[:alnum:]]*\s*:) | # [(]param: - (\.\.\.) # [(]... - ) - ) | - ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends - ) | - # arrow function possible to detect only with => on same line - ( - (<([^<>]|\<[^<>]+\>)+>\s*)? # typeparameters - \(([^()]|\([^()]*\))*\) # parameteres - (\s*:\s*(.)*)? # return type - \s*=> # arrow operator - ) + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: + ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator + ) ) ) captures: 1: storage.modifier.async.ts push: - meta_scope: meta.arrow.ts - - match: '(?==>|\{)' + - match: '(?==>|\{|(^\s*(export|function|class|interface|let|var|const|import|enum|namespace|module|type|abstract|declare)\s+))' pop: true - include: comment - include: type-parameters @@ -131,7 +130,7 @@ contexts: 0: storage.type.function.arrow.ts push: - meta_scope: meta.arrow.ts - - match: '(?<=\})|((?!\{)(?=\S))' + - match: '(?<=\}|\S)(?)|((?!\{)(?=\S))' pop: true - include: decl-block - include: expression @@ -141,18 +140,13 @@ contexts: 1: keyword.operator.type.annotation.ts push: - meta_scope: meta.return.type.arrow.ts - - match: '(?==>|\{)' + - match: '(?==>|\{|(^\s*(export|function|class|interface|let|var|const|import|enum|namespace|module|type|abstract|declare)\s+))' pop: true - - match: '(?<=:)\s*(\{)' - captures: - 1: punctuation.definition.block.ts + - match: '(?<=[:])(?=\s*\{)' push: - - meta_scope: meta.object.type.ts - - match: '\}' - captures: - 0: punctuation.definition.block.ts + - match: '(?<=\})' pop: true - - include: type-object-members + - include: type-object - include: type-predicate-operator - include: type binding-element: @@ -162,32 +156,70 @@ contexts: - include: destructuring-variable-rest - include: variable-initializer boolean-literal: - - match: (?*?\&\|\^]|[^_$[:alnum:]](?:\+\+|\-\-)|[^\+]\+|[^\-]\-))\s*(<)(?!)\s* captures: - 0: punctuation.definition.section.case-statement.ts + 1: meta.brace.angle.ts pop: true - - include: expression - cast: - - match: '(?:(?<=return|throw|yield|await|default|^|[=(,:>*]))\s*(<)(?!)' captures: 1: meta.brace.angle.ts push: - meta_scope: cast.expr.ts - - match: \> + - match: (\>)\s* captures: - 0: meta.brace.angle.ts + 1: meta.brace.angle.ts pop: true - include: type + class-declaration: + - match: '(?\s*$)' + - match: '^(///)\s*(?=<(reference|amd-dependency|amd-module)(\s+(path|types|no-default-lib|name)\s*=\s*((\''([^\''\\]|\\\''|\\)*\'')|(\"([^\"\\]|\\\"|\\)*\")))+\s*/>\s*$)' captures: 1: punctuation.definition.comment.ts push: - meta_scope: comment.line.triple-slash.directive.ts - - match: (?=$) + - match: (?=^) pop: true - match: (<)(reference|amd-dependency|amd-module) captures: @@ -374,270 +389,251 @@ contexts: - include: string docblock: - match: |- - (?x)(?*/] + (?:[^@<>*/]|\*[^/])* ) - scope: other.meta.jsdoc + (?: + \s* + (<) + ([^>\s]+) + (>) + )? captures: - 0: entity.name.type.instance.jsdoc - 1: constant.other.description.jsdoc - 2: storage.type.class.jsdoc - 3: variable.other.description.jsdoc + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: entity.name.type.instance.jsdoc + 4: punctuation.definition.bracket.angle.begin.jsdoc + 5: constant.other.email.link.underline.jsdoc + 6: punctuation.definition.bracket.angle.end.jsdoc + - match: |- + (?x) + ((@)borrows) \s+ + ((?:[^@\s*/]|\*[^/])+) # + \s+ (as) \s+ # as + ((?:[^@\s*/]|\*[^/])+) # + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: entity.name.type.instance.jsdoc + 4: keyword.operator.control.jsdoc + 5: entity.name.type.instance.jsdoc + - match: ((@)example)\s+ + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + push: + - meta_scope: meta.example.jsdoc + - match: (?=@|\*/) + pop: true + - match: ^\s\*\s+ + - match: \G(<)caption(>) + captures: + 0: entity.name.tag.inline.jsdoc + 1: punctuation.definition.bracket.angle.begin.jsdoc + 2: punctuation.definition.bracket.angle.end.jsdoc + push: + - meta_content_scope: constant.other.description.jsdoc + - match: ()|(?=\*/) + captures: + 0: entity.name.tag.inline.jsdoc + 1: punctuation.definition.bracket.angle.begin.jsdoc + 2: punctuation.definition.bracket.angle.end.jsdoc + pop: true + - match: '[^\s@*](?:[^*]|\*[^/])*' + captures: + 0: source.embedded.ts + - match: (?x) ((@)kind) \s+ (class|constant|event|external|file|function|member|mixin|module|namespace|typedef) \b + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: constant.language.symbol-type.jsdoc - match: |- (?x) - - (?:(?<=@param)|(?<=@arg)|(?<=@argument)|(?<=@type)|(?<=@property)|(?<=@prop)) - + ((@)see) \s+ - - ({(?: - \* | # {*} any type - \? | # {?} unknown type - - (?: - (?: # Check for a prefix - \? | # {?string} nullable type - ! | # {!string} non-nullable type - \.{3} # {...string} variable number of parameters - )? - - (?: - (?: - function # {function(string, number)} function type - \s* - \( - \s* - (?: - [a-zA-Z_$][\w$]* - (?: - \s*,\s* - [a-zA-Z_$][\w$]* - )* - )? - \s* - \) - (?: # {function(): string} function return type - \s*:\s* - [a-zA-Z_$][\w$]* - )? - )? + (?: + # URL + ( + (?=https?://) + (?:[^\s*]|\*[^/])+ + ) + | + # JSDoc namepath + ( + (?! + # Avoid matching bare URIs (also acceptable as links) + https?:// | - (?: - \( # Opening bracket of multiple types with parenthesis {(string|number)} - [a-zA-Z_$]+ - (?: - (?: - [\w$]* - (?:\[\])? # {(string[]|number)} type application, an array of strings or a number - ) | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - (?: - [\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback - [a-zA-Z_$]+ - (?: - (?: - [\w$]* - (?:\[\])? # {(string|number[])} type application, a string or an array of numbers - ) | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - )* - \) | - [a-zA-Z_$]+ - (?: - (?: - [\w$]* - (?:\[\])? # {(string|number[])} type application, a string or an array of numbers - ) | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - (?: - [\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback - [a-zA-Z_$]+ - (?: - [\w$]* | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - )* - ) + # Avoid matching {@inline tags}; we match those below + (?:\[[^\[\]]*\])? # Possible description [preceding]{@tag} + {@(?:link|linkcode|linkplain|tutorial)\b ) - # Check for suffix - (?:\[\])? # {string[]} type application, an array of strings - =? # {string=} optional parameter + # Matched namepath + (?:[^@\s*/]|\*[^/])+ ) - )}) - + ) + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: variable.other.link.underline.jsdoc + 4: entity.name.type.instance.jsdoc + - match: |- + (?x) + ((@)template) \s+ - + # One or more valid identifiers ( - \[ # [foo] optional parameter - \s* - (?: - [a-zA-Z_$][\w$]* - (?: - (?:\[\])? # Foo[].bar properties within an array - \. # Foo.Bar namespaced parameter - [a-zA-Z_$][\w$]* - )* - (?: - \s* - = # [foo=bar] Default parameter value - \s* - [\w$\s]* - )? - ) - \s* - \] | - (?: - [a-zA-Z_$][\w$]* - (?: - (?:\[\])? # Foo[].bar properties within an array - \. # Foo.Bar namespaced parameter - [a-zA-Z_$][\w$]* - )* - )? + [A-Za-z_$] # First character: non-numeric word character + [\w$.\[\]]* # Rest of identifier + (?: # Possible list of additional identifiers + \s* , \s* + [A-Za-z_$] + [\w$.\[\]]* + )* ) - - \s+ - - (?:-\s+)? # optional hyphen before the description - - ((?:(?!\*\/).)*) # The type description - captures: - 0: other.meta.jsdoc - 1: entity.name.type.instance.jsdoc - 2: variable.other.jsdoc - 3: other.description.jsdoc + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: variable.other.jsdoc - match: |- (?x) - - ({(?: - \* | # {*} any type - \? | # {?} unknown type - - (?: - (?: # Check for a prefix - \? | # {?string} nullable type - ! | # {!string} non-nullable type - \.{3} # {...string} variable number of parameters - )? - + ( + (@) + (?:arg|argument|const|constant|member|namespace|param|var) + ) + \s+ + ( + [A-Za-z_$] + [\w$.\[\]]* + ) + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: variable.other.jsdoc + - match: '((@)typedef)\s+(?={)' + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + push: + - match: '(?=\s|\*/|[^{}\[\]A-Za-z_$])' + pop: true + - include: jsdoctype + - match: '(?:[^@\s*/]|\*[^/])+' + scope: entity.name.type.instance.jsdoc + - match: '((@)(?:arg|argument|const|constant|member|namespace|param|prop|property|var))\s+(?={)' + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + push: + - match: '(?=\s|\*/|[^{}\[\]A-Za-z_$])' + pop: true + - include: jsdoctype + - match: '([A-Za-z_$][\w$.\[\]]*)' + scope: variable.other.jsdoc + - match: |- + (?x) + (\[)\s* + [\w$]+ (?: - (?: - function # {function(string, number)} function type - \s* - \( - \s* - (?: - [a-zA-Z_$][\w$]* - (?: - \s*,\s* - [a-zA-Z_$][\w$]* - )* - )? - \s* - \) - (?: # {function(): string} function return type - \s*:\s* - [a-zA-Z_$][\w$]* - )? - )? - | - (?: - \( # Opening bracket of multiple types with parenthesis {(string|number)} - [a-zA-Z_$]+ - (?: - [\w$]* | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - (?: - [\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback - [a-zA-Z_$]+ - (?: - [\w$]* | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - )* - \) | - [a-zA-Z_$]+ - (?: - [\w$]* | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - (?: - [\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback - [a-zA-Z_$]+ - (?: - [\w$]* | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) + (?:\[\])? # Foo[ ].bar properties within an array + \. # Foo.Bar namespaced parameter + [\w$]+ + )* + (?: + \s* + (=) # [foo=bar] Default parameter value + \s* + ( + # The inner regexes are to stop the match early at */ and to not stop at escaped quotes + (?> + "(?:(?:\*(?!/))|(?:\\(?!"))|[^*\\])*?" | # [foo="bar"] Double-quoted + '(?:(?:\*(?!/))|(?:\\(?!'))|[^*\\])*?' | # [foo='bar'] Single-quoted + \[ (?:(?:\*(?!/))|[^*])*? \] | # [foo=[1,2]] Array literal + (?:(?:\*(?!/))|\s(?!\s*\])|\[.*?(?:\]|(?=\*/))|[^*\s\[\]])* # Everything else )* ) - ) - # Check for suffix - (?:\[\])? # {string[]} type application, an array of strings - =? # {string=} optional parameter - ) - )}) - + )? + \s*(?:(\])((?:[^*\s]|\*[^\s/])+)?|(?=\*/)) + scope: variable.other.jsdoc + captures: + 1: punctuation.definition.optional-value.begin.bracket.square.jsdoc + 2: keyword.operator.assignment.jsdoc + 3: source.embedded.ts + 4: punctuation.definition.optional-value.end.bracket.square.jsdoc + 5: invalid.illegal.syntax.jsdoc + - match: |- + (?x) + ( + (@) + (?:define|enum|exception|export|extends|lends|implements|modifies + |namespace|private|protected|returns?|suppress|this|throws|type + |yields?) + ) + \s+(?={) + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + push: + - match: '(?=\s|\*/|[^{}\[\]A-Za-z_$])' + pop: true + - include: jsdoctype + - match: |- + (?x) + ( + (@) + (?:alias|augments|callback|constructs|emits|event|fires|exports? + |extends|external|function|func|host|lends|listens|interface|memberof!? + |method|module|mixes|mixin|name|requires|see|this|typedef|uses) + ) \s+ - - (?:-\s+)? # optional hyphen before the description - - ((?:(?!\*\/).)*) # The type description - captures: - 0: other.meta.jsdoc - 1: entity.name.type.instance.jsdoc - 2: other.description.jsdoc + ( + (?: + [^{}@\s*] | \*[^/] + )+ + ) + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: entity.name.type.instance.jsdoc + - match: '((@)(?:default(?:value)?|license|version))\s+(([''''"]))' + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: variable.other.jsdoc + 4: punctuation.definition.string.begin.jsdoc + push: + - meta_content_scope: variable.other.jsdoc + - match: (\3)|(?=$|\*/) + captures: + 0: variable.other.jsdoc + 1: punctuation.definition.string.end.jsdoc + pop: true + - match: '((@)(?:default(?:value)?|license|tutorial|variation|version))\s+([^\s*]+)' + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: variable.other.jsdoc + - match: '(?x) (@) (?:abstract|access|alias|api|arg|argument|async|attribute|augments|author|beta|borrows|bubbles |callback|chainable|class|classdesc|code|config|const|constant|constructor|constructs|copyright |default|defaultvalue|define|deprecated|desc|description|dict|emits|enum|event|example|exception |exports?|extends|extension(?:_?for)?|external|externs|file|fileoverview|final|fires|for|func |function|generator|global|hideconstructor|host|ignore|implements|implicitCast|inherit[Dd]oc |inner|instance|interface|internal|kind|lends|license|listens|main|member|memberof!?|method |mixes|mixins?|modifies|module|name|namespace|noalias|nocollapse|nocompile|nosideeffects |override|overview|package|param|polymer(?:Behavior)?|preserve|private|prop|property|protected |public|read[Oo]nly|record|require[ds]|returns?|see|since|static|struct|submodule|summary |suppress|template|this|throws|todo|tutorial|type|typedef|unrestricted|uses|var|variation |version|virtual|writeOnce|yields?) \b' + scope: storage.type.class.jsdoc + captures: + 1: punctuation.definition.block.tag.jsdoc + - include: inline-tags enum-declaration: - - match: '(?) | - ([(]\s*(([)]\s*:)|([_$[:alpha:]][_$[:alnum:]]*\s*:)|(\.\.\.) )) | - ([<]\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s*[^=>])|(\s*[,]))) | - ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) - ) | - (:\s*( - (<) | - ([(]\s*( - ([)]) | - (\.\.\.) | - ([_$[:alnum:]]+\s*( - ([:,?=])| - ([)]\s*=>) - )) - ))) + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) + )) | + ((async\s*)?( + # sure shot arrow functions even if => is on new line + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator ) + )) + )) | + # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) => + (:\s*( + (<) | + ([(]\s*( + ([)]) | + (\.\.\.) | + ([_$[:alnum:]]+\s*( + ([:,?=])| + ([)]\s*=>) + )) + )) + ))) scope: meta.definition.property.ts entity.name.function.ts - match: "[_$[:alpha:]][_$[:alnum:]]*" scope: meta.definition.property.ts variable.object.property.ts - match: \? scope: keyword.operator.optional.ts for-loop: - - match: (?]|\<[^<>]+\>)+>\s*)?\()' + - match: '(?=(([_$[:alpha:]][_$[:alnum:]]*\s*\??\.\s*)*|(\??\.\s*)?)([_$[:alpha:]][_$[:alnum:]]*)\s*(\?\.\s*)?(<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\))|\<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\)))*\>)*>\s*)?\()' push: - - match: '(?<=\))(?!(([_$[:alpha:]][_$[:alnum:]]*\s*\.\s*)*|(\.\s*)?)([_$[:alpha:]][_$[:alnum:]]*)\s*(<([^<>]|\<[^<>]+\>)+>\s*)?\()' + - match: '(?<=\))(?!(([_$[:alpha:]][_$[:alnum:]]*\s*\??\.\s*)*|(\??\.\s*)?)([_$[:alpha:]][_$[:alnum:]]*)\s*(\?\.\s*)?(<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\))|\<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\)))*\>)*>\s*)?\()' pop: true - - include: literal - - include: support-objects - - include: object-identifiers - - include: punctuation-accessor - - match: "([_$[:alpha:]][_$[:alnum:]]*)" - scope: entity.name.function.ts + - match: '(?=(([_$[:alpha:]][_$[:alnum:]]*\s*\??\.\s*)*|(\??\.\s*)?)([_$[:alpha:]][_$[:alnum:]]*))' + push: + - meta_scope: meta.function-call.ts + - match: '(?=\s*(\?\.\s*)?(<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\))|\<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\)))*\>)*>\s*)?\()' + pop: true + - include: literal + - include: support-objects + - include: object-identifiers + - include: punctuation-accessor + - match: '(?:(?)| - ([(]\s*(([)]\s*:)|([_$[:alpha:]][_$[:alnum:]]*\s*:)|(\.\.\.) )) | - ([<]\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s*[^=>])|(\s*[,]))) | - ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>))) + (?x)(?:(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*)?([_$[:alpha:]][_$[:alnum:]]*)(?=\s*=\s*( + ((async\s+)?( + (function\s*[(<*]) | + (function\s+) | + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) + )) | + ((async\s*)?( + # sure shot arrow functions even if => is on new line + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: + ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator + ) + )) + )) captures: 1: punctuation.accessor.ts - 2: entity.name.function.ts - - match: '(\.)\s*([[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])' + 2: punctuation.accessor.optional.ts + 3: entity.name.function.ts + - match: '(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*([[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])' captures: 1: punctuation.accessor.ts - 2: variable.other.constant.property.ts - - match: '(\.)\s*([_$[:alpha:]][_$[:alnum:]]*)' + 2: punctuation.accessor.optional.ts + 3: variable.other.constant.property.ts + - match: '(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*([_$[:alpha:]][_$[:alnum:]]*)' captures: 1: punctuation.accessor.ts - 2: variable.other.property.ts + 2: punctuation.accessor.optional.ts + 3: variable.other.property.ts - match: "([[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])" scope: variable.other.constant.ts - match: "[_$[:alpha:]][_$[:alnum:]]*" scope: variable.other.readwrite.ts import-declaration: - - match: (?)| - ([(]\s*(([)]\s*:)|([_$[:alpha:]][_$[:alnum:]]*\s*:)|(\.\.\.) )) | - ([<]\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s*[^=>])|(\s*[,]))) | - ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)))) + (?x)(?:([_$[:alpha:]][_$[:alnum:]]*)\s*(?=:\s*( + ((async\s+)?( + (function\s*[(<*]) | + (function\s+) | + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) + )) | + ((async\s*)?( + # sure shot arrow functions even if => is on new line + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: + ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator + ) + )) + ))) + scope: meta.object.member.ts captures: 0: meta.object-literal.key.ts 1: entity.name.function.ts - 2: punctuation.separator.key-value.ts + - match: '(?:[_$[:alpha:]][_$[:alnum:]]*)\s*(?=:)' + scope: meta.object.member.ts + captures: + 0: meta.object-literal.key.ts + - match: \.\.\. + captures: + 0: keyword.operator.spread.ts push: - meta_scope: meta.object.member.ts - match: '(?=,|\})' pop: true - include: expression - - match: '(?:[_$[:alpha:]][_$[:alnum:]]*)\s*(:)' + - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?=,|\}|$)' + scope: meta.object.member.ts captures: - 0: meta.object-literal.key.ts - 1: punctuation.separator.key-value.ts + 1: variable.other.readwrite.ts + - match: '(?=[_$[:alpha:]][_$[:alnum:]]*\s*=)' push: - meta_scope: meta.object.member.ts - - match: '(?=,|\})' + - match: '(?=,|\}|$)' pop: true - include: expression - - match: \.\.\. + - match: ":" captures: - 0: keyword.operator.spread.ts + 0: meta.object-literal.key.ts punctuation.separator.key-value.ts push: - meta_scope: meta.object.member.ts - match: '(?=,|\})' pop: true - include: expression - - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?=,|\}|$)' - scope: meta.object.member.ts - captures: - 1: variable.other.readwrite.ts - include: punctuation-comma parameter-array-binding-pattern: - match: '(?:(\.\.\.)\s*)?(\[)' @@ -1313,42 +1448,63 @@ contexts: captures: 1: storage.modifier.ts - match: |- - (?x)(?:\s*\b(public|private|protected|readonly)\s+)?(\.\.\.)?\s*(?) | - ([(]\s*(([)]\s*:)|([_$[:alpha:]][_$[:alnum:]]*\s*:)|(\.\.\.) )) | - ([<]\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s*[^=>])|(\s*[,]))) | - ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) - ) | - (:\s*( - (<) | - ([(]\s*( - ([)]) | - (\.\.\.) | - ([_$[:alnum:]]+\s*( - ([:,?=])| - ([)]\s*=>) - )) - ))) + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) + )) | + ((async\s*)?( + # sure shot arrow functions even if => is on new line + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator ) + )) + )) | + # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) => + (:\s*( + (<) | + ([(]\s*( + ([)]) | + (\.\.\.) | + ([_$[:alnum:]]+\s*( + ([:,?=])| + ([)]\s*=>) + )) + )) + ))) captures: 1: storage.modifier.ts 2: keyword.operator.rest.ts - 3: entity.name.function.ts - 4: keyword.operator.optional.ts - - match: '(?:\s*\b(public|private|protected|readonly)\s+)?(\.\.\.)?\s*(?|&&|\|\||\*\/)\s*(/)(?![/*])(?=(?:[^/\\\[]|\\.|\[([^\]\\]|\\.)+\])+/(?![/*])[gimy]*(?!\s*[a-zA-Z0-9_$]))' + - match: '(?<=[=(:,\[?+!]|return|case|=>|&&|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))' captures: 1: punctuation.definition.string.begin.ts push: @@ -1428,7 +1586,7 @@ contexts: 2: keyword.other.ts pop: true - include: regexp - - match: '(?]|\<[^<>]+\>)+>\s*)?\() + |vAlign|value|valueType|vendor|vendorSub|version|visibility|vspace|whiteSpace|width|X[MS]LDocument|zIndex))\b(?!\$|\s*(<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)?\() captures: 1: punctuation.accessor.ts - 2: support.constant.dom.ts - 3: support.variable.property.dom.ts + 2: punctuation.accessor.optional.ts + 3: support.constant.dom.ts + 4: support.variable.property.dom.ts - match: |- - (?x)(?])|(?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)' - pop: true - - include: comment - - include: type - type-builtin-literals: - - match: (?])|((?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)))' + pop: true + - include: type + - match: (:) + captures: + 1: keyword.operator.type.annotation.ts + push: + - meta_scope: meta.type.annotation.ts + - match: '(?])|(?=^\s*$)|((?<=\S)(?=\s*$))|((?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)))' + pop: true + - include: type + type-builtin-literals: + - match: '(?)(?=\s*\S) + captures: + 1: storage.type.function.arrow.ts + push: + - meta_scope: meta.type.function.return.ts + - match: '(?)(?]|//|$)' + pop: true + - include: type-function-return-type-core - match: "=>" captures: 0: storage.type.function.arrow.ts push: - meta_scope: meta.type.function.return.ts - - match: '(?)(?=[,\]\)\{\}=;>]|//|$)' + - match: '(?)(?]|//|^\s*$)|((?<=\S)(?=\s*$)))' pop: true - - include: comment - - match: '(?<==>)\s*(\{)' - captures: - 1: punctuation.definition.block.ts - push: - - meta_scope: meta.object.type.ts - - match: '\}' - captures: - 0: punctuation.definition.block.ts - pop: true - - include: type-object-members - - include: type-predicate-operator - - include: type + - include: type-function-return-type-core + type-function-return-type-core: + - include: comment + - match: '(?<==>)(?=\s*\{)' + push: + - match: '(?<=\})' + pop: true + - include: type-object + - include: type-predicate-operator + - include: type type-name: - - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(\.)' + - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))' captures: 1: entity.name.type.module.ts 2: punctuation.accessor.ts + 3: punctuation.accessor.optional.ts - match: "[_$[:alpha:]][_$[:alnum:]]*" scope: entity.name.type.ts type-object: @@ -1981,29 +2169,38 @@ contexts: captures: 0: punctuation.definition.block.ts pop: true - - include: type-object-members - type-object-members: - - include: comment - - include: method-declaration - - include: indexer-declaration - - include: indexer-mapped-type-declaration - - include: field-declaration - - include: type-annotation - - match: \.\.\. - captures: - 0: keyword.operator.spread.ts - push: - - match: '(?=\}|;|,|$)|(?<=\})' - pop: true + - include: comment + - include: method-declaration + - include: indexer-declaration + - include: indexer-mapped-type-declaration + - include: field-declaration + - include: type-annotation + - match: \.\.\. + captures: + 0: keyword.operator.spread.ts + push: + - match: '(?=\}|;|,|$)|(?<=\})' + pop: true + - include: type + - include: punctuation-comma + - include: punctuation-semicolon - include: type - - include: punctuation-comma - - include: punctuation-semicolon - - include: type type-operators: - include: typeof-operator + - match: '([&|])(?=\s*\{)' + captures: + 0: keyword.operator.type.ts + push: + - match: '(?<=\})' + pop: true + - include: type-object - match: "[&|]" - scope: keyword.operator.type.ts - - match: (?) + - match: (>) captures: 1: punctuation.definition.typeparameters.end.ts pop: true - include: comment - - match: (?) scope: keyword.operator.assignment.ts @@ -2035,10 +2232,10 @@ contexts: - include: type - include: function-parameters type-predicate-operator: - - match: (?) | - ([(]\s*(([)]\s*:)|([_$[:alpha:]][_$[:alnum:]]*\s*:)|(\.\.\.) )) | - ([<]\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s*[^=>])|(\s*[,]))) | - ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) - ) | - (:\s*( - (<) | - ([(]\s*( - ([)]) | - (\.\.\.) | - ([_$[:alnum:]]+\s*( - ([:,?=])| - ([)]\s*=>) - )) - ))) + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) + )) | + ((async\s*)?( + # sure shot arrow functions even if => is on new line + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator ) + )) + )) | + # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) => + (:\s*( + (<) | + ([(]\s*( + ([)]) | + (\.\.\.) | + ([_$[:alnum:]]+\s*( + ([:,?=])| + ([)]\s*=>) + )) + )) + ))) captures: 1: meta.definition.variable.ts entity.name.function.ts push: - meta_scope: meta.var-single-variable.expr.ts - - match: '(?=$|[;,=}]|(\s+(of|in)\s+))' + - match: '(?=$|^|[;,=}]|(\s+(of|in)\s+))' pop: true - include: var-single-variable-type-annotation - match: "([[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])" @@ -2108,7 +2334,7 @@ contexts: 1: meta.definition.variable.ts variable.other.constant.ts push: - meta_scope: meta.var-single-variable.expr.ts - - match: '(?=$|[;,=}]|(\s+(of|in)\s+))' + - match: '(?=$|^|[;,=}]|(\s+(of|in)\s+))' pop: true - include: var-single-variable-type-annotation - match: "([_$[:alpha:]][_$[:alnum:]]*)" @@ -2116,7 +2342,7 @@ contexts: 1: meta.definition.variable.ts variable.other.readwrite.ts push: - meta_scope: meta.var-single-variable.expr.ts - - match: '(?=$|[;,=}]|(\s+(of|in)\s+))' + - match: '(?=$|^|[;,=}]|(\s+(of|in)\s+))' pop: true - include: var-single-variable-type-annotation var-single-variable-type-annotation: @@ -2128,13 +2354,13 @@ contexts: captures: 1: keyword.operator.assignment.ts push: - - match: '(?=$|[,);}\]])' + - match: '(?=$|^|[,);}\]])' pop: true - include: expression - match: (?)' + - match: '(?:(?)' scope: meta.arrow.tsx captures: 1: storage.modifier.async.tsx 2: variable.parameter.tsx - match: |- (?x) (?: - (? is on new line - ( - [(]\s* - ( - ([)]\s*:) | # (): - ([_$[:alpha:]][_$[:alnum:]]*\s*:) | # [(]param: - (\.\.\.) # [(]... - ) - ) | - ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends - ) | - # arrow function possible to detect only with => on same line - ( - (<([^<>]|\<[^<>]+\>)+>\s*)? # typeparameters - \(([^()]|\([^()]*\))*\) # parameteres - (\s*:\s*(.)*)? # return type - \s*=> # arrow operator - ) + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: + ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator + ) ) ) captures: 1: storage.modifier.async.tsx push: - meta_scope: meta.arrow.tsx - - match: '(?==>|\{)' + - match: '(?==>|\{|(^\s*(export|function|class|interface|let|var|const|import|enum|namespace|module|type|abstract|declare)\s+))' pop: true - include: comment - include: type-parameters @@ -131,7 +130,7 @@ contexts: 0: storage.type.function.arrow.tsx push: - meta_scope: meta.arrow.tsx - - match: '(?<=\})|((?!\{)(?=\S))' + - match: '(?<=\}|\S)(?)|((?!\{)(?=\S))' pop: true - include: decl-block - include: expression @@ -141,18 +140,13 @@ contexts: 1: keyword.operator.type.annotation.tsx push: - meta_scope: meta.return.type.arrow.tsx - - match: '(?==>|\{)' + - match: '(?==>|\{|(^\s*(export|function|class|interface|let|var|const|import|enum|namespace|module|type|abstract|declare)\s+))' pop: true - - match: '(?<=:)\s*(\{)' - captures: - 1: punctuation.definition.block.tsx + - match: '(?<=[:])(?=\s*\{)' push: - - meta_scope: meta.object.type.tsx - - match: '\}' - captures: - 0: punctuation.definition.block.tsx + - match: '(?<=\})' pop: true - - include: type-object-members + - include: type-object - include: type-predicate-operator - include: type binding-element: @@ -162,23 +156,51 @@ contexts: - include: destructuring-variable-rest - include: variable-initializer boolean-literal: - - match: (?\s*$)' + - match: '^(///)\s*(?=<(reference|amd-dependency|amd-module)(\s+(path|types|no-default-lib|name)\s*=\s*((\''([^\''\\]|\\\''|\\)*\'')|(\"([^\"\\]|\\\"|\\)*\")))+\s*/>\s*$)' captures: 1: punctuation.definition.comment.tsx push: - meta_scope: comment.line.triple-slash.directive.tsx - - match: (?=$) + - match: (?=^) pop: true - match: (<)(reference|amd-dependency|amd-module) captures: @@ -365,270 +370,251 @@ contexts: - include: string docblock: - match: |- - (?x)(?*/] + (?:[^@<>*/]|\*[^/])* ) - scope: other.meta.jsdoc + (?: + \s* + (<) + ([^>\s]+) + (>) + )? captures: - 0: entity.name.type.instance.jsdoc - 1: constant.other.description.jsdoc - 2: storage.type.class.jsdoc - 3: variable.other.description.jsdoc + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: entity.name.type.instance.jsdoc + 4: punctuation.definition.bracket.angle.begin.jsdoc + 5: constant.other.email.link.underline.jsdoc + 6: punctuation.definition.bracket.angle.end.jsdoc - match: |- (?x) - - (?:(?<=@param)|(?<=@arg)|(?<=@argument)|(?<=@type)|(?<=@property)|(?<=@prop)) - + ((@)borrows) \s+ + ((?:[^@\s*/]|\*[^/])+) # + \s+ (as) \s+ # as + ((?:[^@\s*/]|\*[^/])+) # + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: entity.name.type.instance.jsdoc + 4: keyword.operator.control.jsdoc + 5: entity.name.type.instance.jsdoc + - match: ((@)example)\s+ + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + push: + - meta_scope: meta.example.jsdoc + - match: (?=@|\*/) + pop: true + - match: ^\s\*\s+ + - match: \G(<)caption(>) + captures: + 0: entity.name.tag.inline.jsdoc + 1: punctuation.definition.bracket.angle.begin.jsdoc + 2: punctuation.definition.bracket.angle.end.jsdoc + push: + - meta_content_scope: constant.other.description.jsdoc + - match: ()|(?=\*/) + captures: + 0: entity.name.tag.inline.jsdoc + 1: punctuation.definition.bracket.angle.begin.jsdoc + 2: punctuation.definition.bracket.angle.end.jsdoc + pop: true + - match: '[^\s@*](?:[^*]|\*[^/])*' + captures: + 0: source.embedded.tsx + - match: (?x) ((@)kind) \s+ (class|constant|event|external|file|function|member|mixin|module|namespace|typedef) \b + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: constant.language.symbol-type.jsdoc + - match: |- + (?x) + ((@)see) \s+ - - ({(?: - \* | # {*} any type - \? | # {?} unknown type - - (?: - (?: # Check for a prefix - \? | # {?string} nullable type - ! | # {!string} non-nullable type - \.{3} # {...string} variable number of parameters - )? - - (?: - (?: - function # {function(string, number)} function type - \s* - \( - \s* - (?: - [a-zA-Z_$][\w$]* - (?: - \s*,\s* - [a-zA-Z_$][\w$]* - )* - )? - \s* - \) - (?: # {function(): string} function return type - \s*:\s* - [a-zA-Z_$][\w$]* - )? - )? + (?: + # URL + ( + (?=https?://) + (?:[^\s*]|\*[^/])+ + ) + | + # JSDoc namepath + ( + (?! + # Avoid matching bare URIs (also acceptable as links) + https?:// | - (?: - \( # Opening bracket of multiple types with parenthesis {(string|number)} - [a-zA-Z_$]+ - (?: - (?: - [\w$]* - (?:\[\])? # {(string[]|number)} type application, an array of strings or a number - ) | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - (?: - [\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback - [a-zA-Z_$]+ - (?: - (?: - [\w$]* - (?:\[\])? # {(string|number[])} type application, a string or an array of numbers - ) | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - )* - \) | - [a-zA-Z_$]+ - (?: - (?: - [\w$]* - (?:\[\])? # {(string|number[])} type application, a string or an array of numbers - ) | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - (?: - [\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback - [a-zA-Z_$]+ - (?: - [\w$]* | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - )* - ) + # Avoid matching {@inline tags}; we match those below + (?:\[[^\[\]]*\])? # Possible description [preceding]{@tag} + {@(?:link|linkcode|linkplain|tutorial)\b ) - # Check for suffix - (?:\[\])? # {string[]} type application, an array of strings - =? # {string=} optional parameter + # Matched namepath + (?:[^@\s*/]|\*[^/])+ ) - )}) - + ) + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: variable.other.link.underline.jsdoc + 4: entity.name.type.instance.jsdoc + - match: |- + (?x) + ((@)template) \s+ - + # One or more valid identifiers ( - \[ # [foo] optional parameter - \s* - (?: - [a-zA-Z_$][\w$]* - (?: - (?:\[\])? # Foo[].bar properties within an array - \. # Foo.Bar namespaced parameter - [a-zA-Z_$][\w$]* - )* - (?: - \s* - = # [foo=bar] Default parameter value - \s* - [\w$\s]* - )? - ) - \s* - \] | - (?: - [a-zA-Z_$][\w$]* - (?: - (?:\[\])? # Foo[].bar properties within an array - \. # Foo.Bar namespaced parameter - [a-zA-Z_$][\w$]* - )* - )? + [A-Za-z_$] # First character: non-numeric word character + [\w$.\[\]]* # Rest of identifier + (?: # Possible list of additional identifiers + \s* , \s* + [A-Za-z_$] + [\w$.\[\]]* + )* ) - - \s+ - - (?:-\s+)? # optional hyphen before the description - - ((?:(?!\*\/).)*) # The type description - captures: - 0: other.meta.jsdoc - 1: entity.name.type.instance.jsdoc - 2: variable.other.jsdoc - 3: other.description.jsdoc + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: variable.other.jsdoc - match: |- (?x) - - ({(?: - \* | # {*} any type - \? | # {?} unknown type - - (?: - (?: # Check for a prefix - \? | # {?string} nullable type - ! | # {!string} non-nullable type - \.{3} # {...string} variable number of parameters - )? - + ( + (@) + (?:arg|argument|const|constant|member|namespace|param|var) + ) + \s+ + ( + [A-Za-z_$] + [\w$.\[\]]* + ) + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: variable.other.jsdoc + - match: '((@)typedef)\s+(?={)' + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + push: + - match: '(?=\s|\*/|[^{}\[\]A-Za-z_$])' + pop: true + - include: jsdoctype + - match: '(?:[^@\s*/]|\*[^/])+' + scope: entity.name.type.instance.jsdoc + - match: '((@)(?:arg|argument|const|constant|member|namespace|param|prop|property|var))\s+(?={)' + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + push: + - match: '(?=\s|\*/|[^{}\[\]A-Za-z_$])' + pop: true + - include: jsdoctype + - match: '([A-Za-z_$][\w$.\[\]]*)' + scope: variable.other.jsdoc + - match: |- + (?x) + (\[)\s* + [\w$]+ (?: - (?: - function # {function(string, number)} function type - \s* - \( - \s* - (?: - [a-zA-Z_$][\w$]* - (?: - \s*,\s* - [a-zA-Z_$][\w$]* - )* - )? - \s* - \) - (?: # {function(): string} function return type - \s*:\s* - [a-zA-Z_$][\w$]* - )? - )? - | - (?: - \( # Opening bracket of multiple types with parenthesis {(string|number)} - [a-zA-Z_$]+ - (?: - [\w$]* | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - (?: - [\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback - [a-zA-Z_$]+ - (?: - [\w$]* | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - )* - \) | - [a-zA-Z_$]+ - (?: - [\w$]* | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) - (?: - [\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback - [a-zA-Z_$]+ - (?: - [\w$]* | - \.?<[\w$]+(?:,\s+[\w$]+)*> # {Array} or {Object} type application (optional .) - ) + (?:\[\])? # Foo[ ].bar properties within an array + \. # Foo.Bar namespaced parameter + [\w$]+ + )* + (?: + \s* + (=) # [foo=bar] Default parameter value + \s* + ( + # The inner regexes are to stop the match early at */ and to not stop at escaped quotes + (?> + "(?:(?:\*(?!/))|(?:\\(?!"))|[^*\\])*?" | # [foo="bar"] Double-quoted + '(?:(?:\*(?!/))|(?:\\(?!'))|[^*\\])*?' | # [foo='bar'] Single-quoted + \[ (?:(?:\*(?!/))|[^*])*? \] | # [foo=[1,2]] Array literal + (?:(?:\*(?!/))|\s(?!\s*\])|\[.*?(?:\]|(?=\*/))|[^*\s\[\]])* # Everything else )* ) - ) - # Check for suffix - (?:\[\])? # {string[]} type application, an array of strings - =? # {string=} optional parameter - ) - )}) - + )? + \s*(?:(\])((?:[^*\s]|\*[^\s/])+)?|(?=\*/)) + scope: variable.other.jsdoc + captures: + 1: punctuation.definition.optional-value.begin.bracket.square.jsdoc + 2: keyword.operator.assignment.jsdoc + 3: source.embedded.tsx + 4: punctuation.definition.optional-value.end.bracket.square.jsdoc + 5: invalid.illegal.syntax.jsdoc + - match: |- + (?x) + ( + (@) + (?:define|enum|exception|export|extends|lends|implements|modifies + |namespace|private|protected|returns?|suppress|this|throws|type + |yields?) + ) + \s+(?={) + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + push: + - match: '(?=\s|\*/|[^{}\[\]A-Za-z_$])' + pop: true + - include: jsdoctype + - match: |- + (?x) + ( + (@) + (?:alias|augments|callback|constructs|emits|event|fires|exports? + |extends|external|function|func|host|lends|listens|interface|memberof!? + |method|module|mixes|mixin|name|requires|see|this|typedef|uses) + ) \s+ - - (?:-\s+)? # optional hyphen before the description - - ((?:(?!\*\/).)*) # The type description - captures: - 0: other.meta.jsdoc - 1: entity.name.type.instance.jsdoc - 2: other.description.jsdoc + ( + (?: + [^{}@\s*] | \*[^/] + )+ + ) + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: entity.name.type.instance.jsdoc + - match: '((@)(?:default(?:value)?|license|version))\s+(([''''"]))' + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: variable.other.jsdoc + 4: punctuation.definition.string.begin.jsdoc + push: + - meta_content_scope: variable.other.jsdoc + - match: (\3)|(?=$|\*/) + captures: + 0: variable.other.jsdoc + 1: punctuation.definition.string.end.jsdoc + pop: true + - match: '((@)(?:default(?:value)?|license|tutorial|variation|version))\s+([^\s*]+)' + captures: + 1: storage.type.class.jsdoc + 2: punctuation.definition.block.tag.jsdoc + 3: variable.other.jsdoc + - match: '(?x) (@) (?:abstract|access|alias|api|arg|argument|async|attribute|augments|author|beta|borrows|bubbles |callback|chainable|class|classdesc|code|config|const|constant|constructor|constructs|copyright |default|defaultvalue|define|deprecated|desc|description|dict|emits|enum|event|example|exception |exports?|extends|extension(?:_?for)?|external|externs|file|fileoverview|final|fires|for|func |function|generator|global|hideconstructor|host|ignore|implements|implicitCast|inherit[Dd]oc |inner|instance|interface|internal|kind|lends|license|listens|main|member|memberof!?|method |mixes|mixins?|modifies|module|name|namespace|noalias|nocollapse|nocompile|nosideeffects |override|overview|package|param|polymer(?:Behavior)?|preserve|private|prop|property|protected |public|read[Oo]nly|record|require[ds]|returns?|see|since|static|struct|submodule|summary |suppress|template|this|throws|todo|tutorial|type|typedef|unrestricted|uses|var|variation |version|virtual|writeOnce|yields?) \b' + scope: storage.type.class.jsdoc + captures: + 1: punctuation.definition.block.tag.jsdoc + - include: inline-tags enum-declaration: - - match: '(?) | - ([(]\s*(([)]\s*:)|([_$[:alpha:]][_$[:alnum:]]*\s*:)|(\.\.\.) )) | - ([<]\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s*[^=>])|(\s*[,]))) | - ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) - ) | - (:\s*( - (<) | - ([(]\s*( - ([)]) | - (\.\.\.) | - ([_$[:alnum:]]+\s*( - ([:,?=])| - ([)]\s*=>) - )) - ))) + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) + )) | + ((async\s*)?( + # sure shot arrow functions even if => is on new line + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator ) + )) + )) | + # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) => + (:\s*( + (<) | + ([(]\s*( + ([)]) | + (\.\.\.) | + ([_$[:alnum:]]+\s*( + ([:,?=])| + ([)]\s*=>) + )) + )) + ))) scope: meta.definition.property.tsx entity.name.function.tsx - match: "[_$[:alpha:]][_$[:alnum:]]*" scope: meta.definition.property.tsx variable.object.property.tsx - match: \? scope: keyword.operator.optional.tsx for-loop: - - match: (?]|\<[^<>]+\>)+>\s*)?\()' + - match: '(?=(([_$[:alpha:]][_$[:alnum:]]*\s*\??\.\s*)*|(\??\.\s*)?)([_$[:alpha:]][_$[:alnum:]]*)\s*(\?\.\s*)?(<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\))|\<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\)))*\>)*>\s*)?\()' push: - - match: '(?<=\))(?!(([_$[:alpha:]][_$[:alnum:]]*\s*\.\s*)*|(\.\s*)?)([_$[:alpha:]][_$[:alnum:]]*)\s*(<([^<>]|\<[^<>]+\>)+>\s*)?\()' + - match: '(?<=\))(?!(([_$[:alpha:]][_$[:alnum:]]*\s*\??\.\s*)*|(\??\.\s*)?)([_$[:alpha:]][_$[:alnum:]]*)\s*(\?\.\s*)?(<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\))|\<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\)))*\>)*>\s*)?\()' pop: true - - include: literal - - include: support-objects - - include: object-identifiers - - include: punctuation-accessor - - match: "([_$[:alpha:]][_$[:alnum:]]*)" - scope: entity.name.function.tsx + - match: '(?=(([_$[:alpha:]][_$[:alnum:]]*\s*\??\.\s*)*|(\??\.\s*)?)([_$[:alpha:]][_$[:alnum:]]*))' + push: + - meta_scope: meta.function-call.tsx + - match: '(?=\s*(\?\.\s*)?(<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\))|\<\s*(([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))|(\''[^\'']*\'')|(\"[^\"]*\")|(\`[^\`]*\`))([^<>\(]|(\([^\(\)]*\)))*\>)*>\s*)?\()' + pop: true + - include: literal + - include: support-objects + - include: object-identifiers + - include: punctuation-accessor + - match: '(?:(?)| - ([(]\s*(([)]\s*:)|([_$[:alpha:]][_$[:alnum:]]*\s*:)|(\.\.\.) )) | - ([<]\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s*[^=>])|(\s*[,]))) | - ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>))) + (?x)(?:(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*)?([_$[:alpha:]][_$[:alnum:]]*)(?=\s*=\s*( + ((async\s+)?( + (function\s*[(<*]) | + (function\s+) | + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) + )) | + ((async\s*)?( + # sure shot arrow functions even if => is on new line + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: + ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator + ) + )) + )) captures: 1: punctuation.accessor.tsx - 2: entity.name.function.tsx - - match: '(\.)\s*([[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])' + 2: punctuation.accessor.optional.tsx + 3: entity.name.function.tsx + - match: '(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*([[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])' captures: 1: punctuation.accessor.tsx - 2: variable.other.constant.property.tsx - - match: '(\.)\s*([_$[:alpha:]][_$[:alnum:]]*)' + 2: punctuation.accessor.optional.tsx + 3: variable.other.constant.property.tsx + - match: '(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*([_$[:alpha:]][_$[:alnum:]]*)' captures: 1: punctuation.accessor.tsx - 2: variable.other.property.tsx + 2: punctuation.accessor.optional.tsx + 3: variable.other.property.tsx - match: "([[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])" scope: variable.other.constant.tsx - match: "[_$[:alpha:]][_$[:alnum:]]*" scope: variable.other.readwrite.tsx import-declaration: - - match: (?)) push: - - match: '(/>)|(?:())' + - match: '(/>)|(?:())' captures: 0: meta.tag.tsx 1: punctuation.definition.tag.end.tsx 2: punctuation.definition.tag.begin.tsx 3: entity.name.tag.tsx - 4: punctuation.definition.tag.end.tsx + 4: support.class.component.tsx + 5: punctuation.definition.tag.end.tsx pop: true - include: jsx-tag jsx-children: - include: jsx-tag-without-attributes - include: jsx-child-tag - - include: jsx-tag-invalid - include: jsx-evaluated-code - include: jsx-entities jsx-entities: @@ -1114,12 +1207,14 @@ contexts: - match: |- (?x) (<)\s* - ([_$a-zA-Z][-$\w.]*(?) captures: 1: punctuation.definition.tag.begin.tsx 2: entity.name.tag.tsx + 3: support.class.component.tsx push: + - meta_content_scope: meta.tag.attributes.tsx - match: "(?=[/]?>)" pop: true - include: comment @@ -1157,40 +1252,48 @@ contexts: - match: |- (?x) (?<=[({\[,?=>:*]|&&|\|\||\?|\Wreturn|^return|\Wdefault|^)\s* - (?!(<)\s*([_$a-zA-Z][-$\w.]*(?)) #look ahead is not start of tag without attributes (?!<\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=>])|,)) # look ahead is not type parameter of arrow (?=(<)\s* ([_$a-zA-Z][-$\w.]*(?)) push: - - match: '(/>)|(?:())' + - match: '(/>)|(?:())' captures: 0: meta.tag.tsx 1: punctuation.definition.tag.end.tsx 2: punctuation.definition.tag.begin.tsx 3: entity.name.tag.tsx - 4: punctuation.definition.tag.end.tsx + 4: support.class.component.tsx + 5: punctuation.definition.tag.end.tsx pop: true - include: jsx-tag - jsx-tag-invalid: - - match: <\s*> - scope: invalid.illegal.tag.incomplete.tsx jsx-tag-without-attributes: - - match: '(<)\s*([_$a-zA-Z][-$\w.]*(?)' + - match: '(<)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?)' captures: 1: punctuation.definition.tag.begin.tsx 2: entity.name.tag.tsx - 3: punctuation.definition.tag.end.tsx + 3: support.class.component.tsx + 4: punctuation.definition.tag.end.tsx push: - meta_scope: meta.tag.without-attributes.tsx - meta_content_scope: meta.jsx.children.tsx - - match: '()' + - match: '()' captures: 1: punctuation.definition.tag.begin.tsx 2: entity.name.tag.tsx - 3: punctuation.definition.tag.end.tsx + 3: support.class.component.tsx + 4: punctuation.definition.tag.end.tsx pop: true - include: jsx-children + jsx-tag-without-attributes-in-expression: + - match: |- + (?x) + (?<=[({\[,?=>:*]|&&|\|\||\?|\Wreturn|^return|\Wdefault|^)\s* + (?=(<)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?)) + push: + - match: '(?!\s*(<)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?))' + pop: true + - include: jsx-tag-without-attributes literal: - include: numeric-literal - include: boolean-literal @@ -1201,27 +1304,35 @@ contexts: - include: this-literal - include: super-literal method-declaration: - - match: '(?)| - ([(]\s*(([)]\s*:)|([_$[:alpha:]][_$[:alnum:]]*\s*:)|(\.\.\.) )) | - ([<]\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s*[^=>])|(\s*[,]))) | - ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)))) + (?x)(?:([_$[:alpha:]][_$[:alnum:]]*)\s*(?=:\s*( + ((async\s+)?( + (function\s*[(<*]) | + (function\s+) | + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) + )) | + ((async\s*)?( + # sure shot arrow functions even if => is on new line + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: + ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator + ) + )) + ))) + scope: meta.object.member.tsx captures: 0: meta.object-literal.key.tsx 1: entity.name.function.tsx - 2: punctuation.separator.key-value.tsx + - match: '(?:[_$[:alpha:]][_$[:alnum:]]*)\s*(?=:)' + scope: meta.object.member.tsx + captures: + 0: meta.object-literal.key.tsx + - match: \.\.\. + captures: + 0: keyword.operator.spread.tsx push: - meta_scope: meta.object.member.tsx - match: '(?=,|\})' pop: true - include: expression - - match: '(?:[_$[:alpha:]][_$[:alnum:]]*)\s*(:)' + - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?=,|\}|$)' + scope: meta.object.member.tsx captures: - 0: meta.object-literal.key.tsx - 1: punctuation.separator.key-value.tsx + 1: variable.other.readwrite.tsx + - match: '(?=[_$[:alpha:]][_$[:alnum:]]*\s*=)' push: - meta_scope: meta.object.member.tsx - - match: '(?=,|\})' + - match: '(?=,|\}|$)' pop: true - include: expression - - match: \.\.\. + - match: ":" captures: - 0: keyword.operator.spread.tsx + 0: meta.object-literal.key.tsx punctuation.separator.key-value.tsx push: - meta_scope: meta.object.member.tsx - match: '(?=,|\})' pop: true - include: expression - - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?=,|\}|$)' - scope: meta.object.member.tsx - captures: - 1: variable.other.readwrite.tsx - include: punctuation-comma parameter-array-binding-pattern: - match: '(?:(\.\.\.)\s*)?(\[)' @@ -1462,42 +1596,63 @@ contexts: captures: 1: storage.modifier.tsx - match: |- - (?x)(?:\s*\b(public|private|protected|readonly)\s+)?(\.\.\.)?\s*(?) | - ([(]\s*(([)]\s*:)|([_$[:alpha:]][_$[:alnum:]]*\s*:)|(\.\.\.) )) | - ([<]\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s*[^=>])|(\s*[,]))) | - ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) - ) | - (:\s*( - (<) | - ([(]\s*( - ([)]) | - (\.\.\.) | - ([_$[:alnum:]]+\s*( - ([:,?=])| - ([)]\s*=>) - )) - ))) + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) + )) | + ((async\s*)?( + # sure shot arrow functions even if => is on new line + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator ) + )) + )) | + # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) => + (:\s*( + (<) | + ([(]\s*( + ([)]) | + (\.\.\.) | + ([_$[:alnum:]]+\s*( + ([:,?=])| + ([)]\s*=>) + )) + )) + ))) captures: 1: storage.modifier.tsx 2: keyword.operator.rest.tsx - 3: entity.name.function.tsx - 4: keyword.operator.optional.tsx - - match: '(?:\s*\b(public|private|protected|readonly)\s+)?(\.\.\.)?\s*(?|&&|\|\||\*\/)\s*(/)(?![/*])(?=(?:[^/\\\[]|\\.|\[([^\]\\]|\\.)+\])+/(?![/*])[gimy]*(?!\s*[a-zA-Z0-9_$]))' + - match: '(?<=[=(:,\[?+!]|return|case|=>|&&|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))' captures: 1: punctuation.definition.string.begin.tsx push: @@ -1577,7 +1734,7 @@ contexts: 2: keyword.other.tsx pop: true - include: regexp - - match: '(?]|\<[^<>]+\>)+>\s*)?\() + |vAlign|value|valueType|vendor|vendorSub|version|visibility|vspace|whiteSpace|width|X[MS]LDocument|zIndex))\b(?!\$|\s*(<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)?\() captures: 1: punctuation.accessor.tsx - 2: support.constant.dom.tsx - 3: support.variable.property.dom.tsx + 2: punctuation.accessor.optional.tsx + 3: support.constant.dom.tsx + 4: support.variable.property.dom.tsx - match: |- - (?x)(?])|(?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)' - pop: true - - include: comment - - include: type - type-builtin-literals: - - match: (?])|((?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)))' + pop: true + - include: type + - match: (:) + captures: + 1: keyword.operator.type.annotation.tsx + push: + - meta_scope: meta.type.annotation.tsx + - match: '(?])|(?=^\s*$)|((?<=\S)(?=\s*$))|((?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)))' + pop: true + - include: type + type-builtin-literals: + - match: '(?)(?=\s*\S) + captures: + 1: storage.type.function.arrow.tsx + push: + - meta_scope: meta.type.function.return.tsx + - match: '(?)(?]|//|$)' + pop: true + - include: type-function-return-type-core - match: "=>" captures: 0: storage.type.function.arrow.tsx push: - meta_scope: meta.type.function.return.tsx - - match: '(?)(?=[,\]\)\{\}=;>]|//|$)' + - match: '(?)(?]|//|^\s*$)|((?<=\S)(?=\s*$)))' pop: true - - include: comment - - match: '(?<==>)\s*(\{)' - captures: - 1: punctuation.definition.block.tsx - push: - - meta_scope: meta.object.type.tsx - - match: '\}' - captures: - 0: punctuation.definition.block.tsx - pop: true - - include: type-object-members - - include: type-predicate-operator - - include: type + - include: type-function-return-type-core + type-function-return-type-core: + - include: comment + - match: '(?<==>)(?=\s*\{)' + push: + - match: '(?<=\})' + pop: true + - include: type-object + - include: type-predicate-operator + - include: type type-name: - - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(\.)' + - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))' captures: 1: entity.name.type.module.tsx 2: punctuation.accessor.tsx + 3: punctuation.accessor.optional.tsx - match: "[_$[:alpha:]][_$[:alnum:]]*" scope: entity.name.type.tsx type-object: @@ -2130,29 +2317,38 @@ contexts: captures: 0: punctuation.definition.block.tsx pop: true - - include: type-object-members - type-object-members: - - include: comment - - include: method-declaration - - include: indexer-declaration - - include: indexer-mapped-type-declaration - - include: field-declaration - - include: type-annotation - - match: \.\.\. - captures: - 0: keyword.operator.spread.tsx - push: - - match: '(?=\}|;|,|$)|(?<=\})' - pop: true + - include: comment + - include: method-declaration + - include: indexer-declaration + - include: indexer-mapped-type-declaration + - include: field-declaration + - include: type-annotation + - match: \.\.\. + captures: + 0: keyword.operator.spread.tsx + push: + - match: '(?=\}|;|,|$)|(?<=\})' + pop: true + - include: type + - include: punctuation-comma + - include: punctuation-semicolon - include: type - - include: punctuation-comma - - include: punctuation-semicolon - - include: type type-operators: - include: typeof-operator + - match: '([&|])(?=\s*\{)' + captures: + 0: keyword.operator.type.tsx + push: + - match: '(?<=\})' + pop: true + - include: type-object - match: "[&|]" - scope: keyword.operator.type.tsx - - match: (?) + - match: (>) captures: 1: punctuation.definition.typeparameters.end.tsx pop: true - include: comment - - match: (?) scope: keyword.operator.assignment.tsx @@ -2184,10 +2380,10 @@ contexts: - include: type - include: function-parameters type-predicate-operator: - - match: (?) | - ([(]\s*(([)]\s*:)|([_$[:alpha:]][_$[:alnum:]]*\s*:)|(\.\.\.) )) | - ([<]\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s*[^=>])|(\s*[,]))) | - ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) - ) | - (:\s*( - (<) | - ([(]\s*( - ([)]) | - (\.\.\.) | - ([_$[:alnum:]]+\s*( - ([:,?=])| - ([)]\s*=>) - )) - ))) + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) + )) | + ((async\s*)?( + # sure shot arrow functions even if => is on new line + ( + [(]\s* + ( + ([)]\s*:) | # (): + ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:) # [(]param: | [(]...param: ) + ) | + ( + [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + ) | + # arrow function possible to detect only with => on same line + ( + (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)? # typeparameters + \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\) # parameteres + (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type + \s*=> # arrow operator ) + )) + )) | + # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) => + (:\s*( + (<) | + ([(]\s*( + ([)]) | + (\.\.\.) | + ([_$[:alnum:]]+\s*( + ([:,?=])| + ([)]\s*=>) + )) + )) + ))) captures: 1: meta.definition.variable.tsx entity.name.function.tsx push: - meta_scope: meta.var-single-variable.expr.tsx - - match: '(?=$|[;,=}]|(\s+(of|in)\s+))' + - match: '(?=$|^|[;,=}]|(\s+(of|in)\s+))' pop: true - include: var-single-variable-type-annotation - match: "([[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])" @@ -2257,7 +2482,7 @@ contexts: 1: meta.definition.variable.tsx variable.other.constant.tsx push: - meta_scope: meta.var-single-variable.expr.tsx - - match: '(?=$|[;,=}]|(\s+(of|in)\s+))' + - match: '(?=$|^|[;,=}]|(\s+(of|in)\s+))' pop: true - include: var-single-variable-type-annotation - match: "([_$[:alpha:]][_$[:alnum:]]*)" @@ -2265,7 +2490,7 @@ contexts: 1: meta.definition.variable.tsx variable.other.readwrite.tsx push: - meta_scope: meta.var-single-variable.expr.tsx - - match: '(?=$|[;,=}]|(\s+(of|in)\s+))' + - match: '(?=$|^|[;,=}]|(\s+(of|in)\s+))' pop: true - include: var-single-variable-type-annotation var-single-variable-type-annotation: @@ -2277,13 +2502,13 @@ contexts: captures: 1: keyword.operator.assignment.tsx push: - - match: '(?=$|[,);}\]])' + - match: '(?=$|^|[,);}\]])' pop: true - include: expression - match: (?