Skip to content

Instantly share code, notes, and snippets.

@kazemihabib
Created April 23, 2016 22:43
Show Gist options
  • Save kazemihabib/9a4757af3d9bca1daefbc977148f6ed5 to your computer and use it in GitHub Desktop.
Save kazemihabib/9a4757af3d9bca1daefbc977148f6ed5 to your computer and use it in GitHub Desktop.
name: "TypeScript"
scopeName: "source.ts"
fileTypes: [
"ts"
]
uuid: "ef98eb90-bf9b-11e4-bb52-0800200c9a66"
patterns: [
{
include: "#expression"
}
]
repository:
"var-expr":
name: "meta.var.expr.ts"
begin: "(?<!\\()\\s*\\b(var|let|const(?!\\s+enum)\\b)"
beginCaptures:
"1":
name: "storage.type.ts"
end: "(?=$|;)"
patterns: [
{
include: "#var-single-variable"
}
{
include: "#comment"
}
]
"var-single-variable":
name: "meta.var-single-variable.expr.ts"
begin: "\\b([a-zA-Z_$][\\w$]*)\\s*(=?)"
beginCaptures:
"1":
name: "variable.ts"
end: "(?=$|[;,])"
patterns: [
{
include: "#type-annotation"
}
{
include: "#string"
}
{
include: "#comment"
}
{
include: "#expression"
}
]
"control-statement":
name: "keyword.control.ts"
match: "(?<!\\.)\\b(break|catch|continue|debugger|declare|do|else|finally|for|if|return|switch|throw|try|while|with|super|case|default)\\b"
declaration:
name: "meta.declaration.ts"
patterns: [
{
include: "#function-declaration"
}
{
include: "#object-declaration"
}
{
include: "#type-declaration"
}
{
include: "#enum-declaration"
}
]
"type-declaration":
name: "meta.type.declaration.ts"
begin: "\\b(type)\\b\\s+([a-zA-Z_$][\\w$]*)\\s*=\\s*"
beginCaptures:
"1":
name: "keyword.other.ts"
"2":
name: "storage.type.ts"
end: "(?=$|[,);>]|var|type|function|class|interface)"
patterns: [
{
include: "#type"
}
]
"enum-declaration":
name: "meta.enum.declaration.ts"
match: "(?:\\b(const)\\s+)?\\b(enum)\\s+([a-zA-Z_$][\\w$]*)"
captures:
"1":
name: "storage.modifier.ts"
"2":
name: "storage.type.ts"
"3":
name: "entity.name.class.ts"
"object-declaration":
name: "meta.declaration.object.ts"
begin: "\\b(?:(export)\\s+)?\\b(?:(abstract)\\s+)?\\b(?<!\\.)(class|interface)\\b"
beginCaptures:
"1":
name: "storage.modifier.ts"
"2":
name: "storage.modifier.ts"
"3":
name: "storage.type.ts"
end: "(?<=\\})"
endCaptures:
"1":
name: "brace.curly.ts"
patterns: [
{
include: "#comment"
}
{
include: "#object-heritage"
}
{
include: "#object-name"
}
{
include: "#type-parameters"
}
{
include: "#object-body"
}
]
"object-name":
name: "meta.object.name.ts"
match: "[a-zA-Z_$][\\w$]*"
captures:
"0":
name: "entity.name.class.ts"
"object-heritage":
name: "meta.object.heritage.ts"
begin: "(?:\\b(extends|implements))"
beginCaptures:
"1":
name: "keyword.other.ts"
end: "(?=\\{)"
endCaptures:
"1":
name: "brace.curly.ts"
patterns: [
{
include: "#comment"
}
{
include: "#object-heritage"
}
{
include: "#type-parameters"
}
{
include: "#object-heritage-parent"
}
]
"object-heritage-parent":
name: "meta.object.heritage.parent.ts"
match: "(?:\\s*([a-zA-Z_$][\\w$]*))"
captures:
"1":
name: "storage.type.ts"
"object-body":
name: "meta.object.body.ts"
begin: "\\{"
beginCaptures:
"0":
name: "meta.brace.curly.ts"
end: "\\}"
endCaptures:
"0":
name: "meta.brace.curly.ts"
patterns: [
{
include: "#string"
}
{
include: "#comment"
}
{
include: "#field-declaration"
}
{
include: "#method-declaration"
}
{
include: "#indexer-declaration"
}
{
include: "#type-annotation"
}
{
include: "#variable-initializer"
}
{
include: "#access-modifier"
}
{
include: "#static-modifier"
}
{
include: "#property-accessor"
}
]
"type-object":
name: "meta.object.type.ts"
begin: "\\{"
beginCaptures:
"0":
name: "meta.brace.curly.ts"
end: "\\}"
endCaptures:
"0":
name: "meta.brace.curly.ts"
patterns: [
{
include: "#comment"
}
{
include: "#field-declaration"
}
{
include: "#method-declaration"
}
{
include: "#indexer-declaration"
}
{
include: "#type-annotation"
}
]
"field-declaration":
name: "meta.field.declaration.ts"
begin: "(?<!\\()\\s*((?:\\b[a-zA-Z_$][\\w$]*)|(?:\\'[^']*\\')|(?:\\\"[^\"]*\\\"))\\s*(\\?\\s*)?(?=(=|:))"
beginCaptures:
"1":
name: "variable.ts"
"2":
name: "keyword.operator.ts"
end: "(?=\\}|;|,|$)|(?<=\\})"
patterns: [
{
include: "#expression"
}
]
"method-declaration":
name: "meta.method.declaration.ts"
begin: "\\b(?:(abstract)\\s+)?\\b(?:(public|private|protected)\\s+)?\\b(?:(async)\\s+)?(?:(get|set)\\s+)?(?:(new)|(?:([a-zA-Z_$][\\.\\w$]*)\\s*(\\??)))?\\s*(?=\\(|\\<)"
beginCaptures:
"1":
name: "storage.modifier.ts"
"2":
name: "storage.modifier.ts"
"3":
name: "storage.modifier.ts"
"4":
name: "storage.type.property.ts"
"5":
name: "keyword.operator.ts"
"6":
name: "entity.name.function.ts"
"7":
name: "keyword.operator.ts"
end: "(?=\\}|;|,)|(?<=\\})"
patterns: [
{
include: "#comment"
}
{
include: "#type-parameters"
}
{
include: "#function-type-parameters"
}
{
include: "#type-annotation"
}
{
include: "#method-overload-declaration"
}
{
include: "#decl-block"
}
]
"method-overload-declaration":
name: "meta.method.overload.declaration.ts"
match: "\\b(?:(abstract)\\s+)?\\b(?:(public|private|protected)\\s+)?\\b(?:(async)\\s+)?(?:(get|set)\\s+)?(?:(new)|(?:([a-zA-Z_$][\\.\\w$]*)\\s*(\\??)))?\\s*(?=\\(|\\<)"
captures:
"1":
name: "storage.modifier.ts"
"2":
name: "storage.modifier.ts"
"3":
name: "storage.modifier.ts"
"4":
name: "storage.type.property.ts"
"5":
name: "keyword.operator.ts"
"6":
name: "entity.name.function.ts"
"7":
name: "keyword.operator.ts"
"indexer-declaration":
name: "meta.indexer.declaration.ts"
begin: "\\["
beginCaptures:
"0":
name: "meta.brace.square.ts"
end: "(\\])\\s*(\\?\\s*)?|$"
endCaptures:
"1":
name: "meta.brace.square.ts"
"2":
name: "keyword.operator.ts"
patterns: [
{
include: "#type-annotation"
}
{
include: "#indexer-parameter"
}
{
include: "#expression"
}
]
"indexer-parameter":
name: "meta.indexer.parameter.ts"
match: "([a-zA-Z_$][\\w$]*)(?=\\:)"
captures:
"1":
name: "variable.parameter.ts"
"function-declaration":
name: "meta.function.ts"
begin: "\\b(?:(export)\\s+)?(?:(async)\\s+)?(function\\b)(?:\\s+([a-zA-Z_$][\\w$]*))?\\s*"
beginCaptures:
"1":
name: "storage.modifier.ts"
"2":
name: "storage.modifier.ts"
"3":
name: "storage.type.function.ts"
"4":
name: "entity.name.function.ts"
end: "(?=;|\\})|(?<=\\})"
patterns: [
{
include: "#comment"
}
{
include: "#type-parameters"
}
{
include: "#function-type-parameters"
}
{
include: "#return-type"
}
{
include: "#function-overload-declaration"
}
{
include: "#decl-block"
}
]
"function-overload-declaration":
name: "meta.function.overload.ts"
match: "\\b(?:(export)\\s+)?(function\\b)(?:\\s+([a-zA-Z_$][\\w$]*))?\\s*"
captures:
"1":
name: "storage.modifier.ts"
"2":
name: "storage.type.function.ts"
"3":
name: "entity.name.function.ts"
block:
name: "meta.block.ts"
begin: "\\{"
beginCaptures:
"0":
name: "meta.brace.curly.ts"
end: "\\}"
endCaptures:
"0":
name: "meta.brace.curly.ts"
patterns: [
{
include: "#object-member"
}
{
include: "#expression"
}
]
"decl-block":
name: "meta.decl.block.ts"
begin: "\\{"
beginCaptures:
"0":
name: "meta.brace.curly.ts"
end: "\\}"
endCaptures:
"0":
name: "meta.brace.curly.ts"
patterns: [
{
include: "#expression"
}
]
"parameter-name":
name: "parameter.name.ts"
match: "(?:\\s*\\b(public|private|protected)\\b\\s+)?(\\.\\.\\.)?\\s*([a-zA-Z_$][\\w$]*)\\s*(\\??)"
captures:
"1":
name: "storage.modifier.ts"
"2":
name: "keyword.operator.ts"
"3":
name: "variable.parameter.ts"
"4":
name: "keyword.operator.ts"
"return-type":
name: "meta.return.type.ts"
begin: "(?<=\\))\\s*:"
end: "(?=$)|(?=\\{|;|//)"
patterns: [
{
include: "#type"
}
]
"type-annotation":
name: "meta.type.annotation.ts"
begin: ":"
end: "(?=$|[,);\\}\\]]|//)|(?==[^>])|(?<=[\\}>\\]\\)]|[a-zA-Z_$])\\s*(?=\\{)"
patterns: [
{
include: "#type"
}
{
include: "#string"
}
{
include: "#comment"
}
]
type:
name: "meta.type.ts"
patterns: [
{
include: "#type-primitive"
}
{
include: "#type-parameters"
}
{
include: "#type-tuple"
}
{
include: "#type-object"
}
{
include: "#type-operator"
}
{
include: "#type-paren-or-function-type-parameters"
}
{
include: "#type-function-return-type"
}
{
include: "#type-name"
}
]
"function-type-parameters":
name: "meta.function.type.parameter.ts"
begin: "\\("
beginCaptures:
"0":
name: "meta.brace.round.ts"
end: "\\)"
endCaptures:
"0":
name: "meta.brace.round.ts"
patterns: [
{
include: "#comment"
}
{
include: "#parameter-name"
}
{
include: "#type-annotation"
}
{
include: "#variable-initializer"
}
]
"type-primitive":
name: "meta.type.primitive.ts"
match: "\\b(string|number|boolean|symbol|any|void)\\b"
captures:
"1":
name: "storage.type.ts"
"type-paren-or-function-type-parameters":
name: "meta.type.paren.cover.ts"
begin: "(?:\\b(new)\\b)?\\s*\\("
beginCaptures:
"1":
name: "keyword.control.ts"
end: "\\)"
patterns: [
{
include: "#comment"
}
{
include: "#type"
}
{
include: "#function-type-parameters"
}
]
"await-modifier":
name: "storage.modifier.ts"
match: "await"
"type-operator":
name: "keyword.operator.type.ts"
match: "[.|]"
"type-function-return-type":
name: "meta.type.function.return.ts"
begin: "=>"
beginCaptures:
"0":
name: "keyword.operator.ts"
end: "(?=\\s*[,\\)\\{=;>]|//|$)"
patterns: [
{
include: "#type"
}
]
"type-tuple":
name: "meta.type.tuple.ts"
begin: "\\["
beginCaptures:
"0":
name: "meta.brace.square.ts"
end: "\\]"
endCaptures:
"0":
name: "meta.brace.square.ts"
patterns: [
{
include: "#type"
}
{
include: "#comment"
}
]
"type-name":
name: "meta.type.name.ts"
match: "[a-zA-Z_$][.\\w$]*"
captures:
"1":
name: "entity.name.type.ts"
"type-parameters":
name: "meta.type.parameters.ts"
begin: "([a-zA-Z_$][\\w$]*)?(<)"
beginCaptures:
"1":
name: "entity.name.type.ts"
"2":
name: "meta.brace.angle.ts"
end: "(?=$)|(>)"
endCaptures:
"2":
name: "meta.brace.angle.ts"
patterns: [
{
name: "keyword.other.ts"
match: "\\b(extends)\\b"
}
{
include: "#comment"
}
{
include: "#type"
}
]
"variable-initializer":
begin: "(=)"
beginCaptures:
"1":
name: "keyword.operator.ts"
end: "(?=$|[,);=])"
patterns: [
{
include: "#expression"
}
]
expression:
name: "meta.expression.ts"
patterns: [
{
comment: "Match ES6 \"import from\" syntax"
match: "\\b(import)\\b.*\\b(from)\\b\\s+((['\"]).*\\4)"
captures:
"1":
name: "keyword.other.ts"
"2":
name: "keyword.other.ts"
"3":
name: "es6import.path.quoted.string"
}
{
comment: "Match import = require"
match: "\\b(import)\\s+([\\p{L}\\p{Nl}$_][\\p{L}\\p{Nl}$\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}\\x{200C}\\x{200D}]*)\\s*=\\s*(require)\\s*\\((.*)\\)"
captures:
"1":
name: "keyword.other.ts"
"2":
name: "variable.type.ts"
"3":
name: "keyword.other.ts"
"4":
name: "require.path.quoted.string"
}
{
comment: "Match <amd-module"
match: "(\\/\\/\\/\\s*<amd-module\\s*name\\s*=)(.*)(\\/>)"
captures:
"1":
name: "keyword.other.ts"
"2":
name: "amd.path.quoted.string"
"3":
name: "keyword.other.ts"
}
{
comment: "Match <amd-dependency"
match: "(\\/\\/\\/\\s*<amd-dependency\\s*path\\s*=)(.*)(\\/>)"
captures:
"1":
name: "keyword.other.ts"
"2":
name: "amd.path.quoted.string"
"3":
name: "keyword.other.ts"
}
{
comment: "Match full triple slash reference comments"
match: "(\\/\\/\\/\\s*<reference\\s*path\\s*=)(.*)(\\/>)"
captures:
"1":
name: "keyword.other.ts"
"2":
name: "reference.path.quoted.string"
"3":
name: "keyword.other.ts"
}
{
comment: "Match debugger statement"
match: "\\b(debugger)\\b"
captures:
"1":
name: "keyword.debugger.ts"
}
{
include: "#for-in-simple"
}
{
include: "#string"
}
{
include: "#regex"
}
{
include: "#template-html"
}
{
include: "#template-css"
}
{
include: "#template"
}
{
include: "#comment"
}
{
include: "#literal"
}
{
include: "#paren-expression"
}
{
include: "#var-expr"
}
{
include: "#declaration"
}
{
include: "#cast"
}
{
include: "#new-expr"
}
{
include: "#switch-statement"
}
{
include: "#block"
}
{
include: "#expression-operator"
}
{
include: "#relational-operator"
}
{
include: "#arithmetic-operator"
}
{
include: "#logic-operator"
}
{
include: "#assignment-operator"
}
{
include: "#storage-keyword"
}
{
include: "#function-call"
}
{
include: "#case-clause"
}
{
include: "#control-statement"
}
]
"switch-expression":
name: "switch-expression.expr.ts"
begin: "\\b(switch)\\b\\s*\\("
beginCaptures:
"1":
name: "keyword.operator.ts"
end: "\\)"
patterns: [
{
include: "#expression"
}
]
"switch-block":
name: "switch-block.expr.ts"
begin: "{"
end: "(?=\\})"
patterns: [
{
include: "#expression"
}
]
"case-clause":
name: "case-clause.expr.ts"
begin: "(?<!\\.)\\b(case|default)\\b"
beginCaptures:
"1":
name: "keyword.control.ts"
end: ":"
patterns: [
{
include: "#expression"
}
]
"switch-statement":
name: "switch-statement.expr.ts"
begin: "(?=\\bswitch\\b\\s*\\()"
end: "}"
patterns: [
{
include: "#switch-expression"
}
{
include: "#switch-block"
}
]
"for-in-simple":
name: "forin.expr.ts"
match: "(?<=\\()\\s*\\b(var|let|const)\\s+([a-zA-Z_$][\\w$]*)\\s+(in|of)\\b"
captures:
"1":
name: "storage.type.ts"
"3":
name: "keyword.operator.ts"
"function-call":
name: "functioncall.expr.ts"
patterns: [
{
include: "#await-modifier"
}
{
include: "#type-parameters"
}
{
include: "#paren-expression"
}
]
cast:
name: "cast.expr.ts"
begin: "(?:(?<=return|throw|yield|await|[=(,:>]))\\s*(<)(?!<?\\=)"
beginCaptures:
"1":
name: "meta.brace.angle.ts"
end: ">"
endCaptures:
"0":
name: "meta.brace.angle.ts"
patterns: [
{
include: "#type"
}
]
"new-expr":
name: "new.expr.ts"
begin: "\\b(new)\\b"
beginCaptures:
"1":
name: "keyword.operator.ts"
end: "(?=[(;]|$)"
patterns: [
{
include: "#type"
}
{
include: "#comment"
}
]
"object-member":
name: "meta.object.member.ts"
begin: "[a-zA-Z_$][\\w$]*\\s*:"
end: "(?=,|\\})"
patterns: [
{
include: "#expression"
}
]
"expression-operator":
name: "keyword.operator.ts"
match: "=>|\\b(delete|export|import|from|in|instanceof|module|namespace|new|typeof|void|as)\\b"
"arithmetic-operator":
name: "keyword.operator.arithmetic.ts"
match: "\\*|/|\\-\\-|\\-|\\+\\+|\\+|%"
"relational-operator":
name: "keyword.operator.comparison.ts"
match: "===|==|=|!=|!==|<=|>=|<>|<|>"
"assignment-operator":
name: "keyword.operator.assignment.ts"
match: "<<=|>>=|>>>=|\\*=|(?<!\\()/=|%=|\\+=|\\-=|&=|\\^="
"logic-operator":
name: "keyword.operator.arithmetic.ts"
match: "\\!|&|~|\\||&&|\\|\\|"
"storage-keyword":
name: "storage.type.ts"
match: "\\b(number|boolean|string|any|var|let|function|const)\\b"
"paren-expression":
begin: "\\("
beginCaptures:
"0":
name: "meta.brace.paren.ts"
end: "\\)"
endCaptures:
"0":
name: "meta.brace.paren.ts"
patterns: [
{
include: "#expression"
}
]
"qstring-double":
name: "string.double.quoted.ts"
begin: "\""
end: "\"|(?=$)"
patterns: [
{
include: "#string-character-escape"
}
]
"qstring-single":
name: "string.single.quoted.ts"
begin: "'"
end: "'|(?=$)"
patterns: [
{
include: "#string-character-escape"
}
]
regex:
name: "string.quoted.regex.ts"
begin: "(?<=[=(:,\\[]|^|return|&&|\\|\\||!)\\s*(/)(?![/*+{}?])"
end: "$|(/)[igm]*"
patterns: [
{
name: "constant.character.escape.ts"
match: "\\\\."
}
{
name: "constant.character.class.ts"
match: "\\[(\\\\\\]|[^\\]])*\\]"
}
]
string:
name: "string.quoted.ts"
patterns: [
{
include: "#qstring-single"
}
{
include: "#qstring-double"
}
]
"template-html":
name: "meta.template.html.ts"
begin: "`<!---->"
beginCaptures:
"0":
name: "string.quoted.template.ts"
end:"`"
endCaptures:
"0":
name: "string.quoted.template.ts"
patterns: [
{
include: "text.html.basic"
}
]
"template-css":
name: "meta.template.css.ts"
begin: "`/\\*\\*/"
beginCaptures:
"0":
name: "string.quoted.template.ts"
end:"`"
endCaptures:
"0":
name: "string.quoted.template.ts"
patterns: [
{
include: "source.css"
}
]
template:
name: "meta.template.ts"
begin: "`"
beginCaptures:
"0":
name: "string.quoted.template.ts"
end: "`"
endCaptures:
"0":
name: "string.quoted.template.ts"
patterns: [
{
include: "#template-substitution-element"
}
{
include: "#template-string-contents"
}
]
"template-string-contents":
name: "string.quoted.template.ts"
begin: ".*?"
end: "(?=(\\$\\{|`))"
patterns: [
{
include: "#string-character-escape"
}
]
"string-character-escape":
name: "constant.character.escape"
match: "\\\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)"
"template-substitution-element":
name: "template.element.ts"
begin: "\\$\\{"
beginCaptures:
"0":
name: "keyword.operator.ts"
end: "\\}"
endCaptures:
"0":
name: "keyword.operator.ts"
patterns: [
{
include: "#expression"
}
]
comment:
name: "comment.ts"
patterns: [
{
include: "#comment-block-doc"
}
{
include: "#comment-block"
}
{
include: "#comment-line"
}
]
"comment-block-doc":
name: "comment.block.documentation.ts"
begin: "/\\*\\*(?!/)"
end: "\\*/"
"comment-block":
name: "comment.block.ts"
begin: "/\\*"
end: "\\*/"
"comment-line":
name: "comment.line.ts"
match: "(//).*$\\n?"
literal:
name: "literal.ts"
patterns: [
{
include: "#numeric-literal"
}
{
include: "#boolean-literal"
}
{
include: "#null-literal"
}
{
include: "#undefined-literal"
}
{
include: "#array-literal"
}
{
include: "#this-literal"
}
]
"array-literal":
name: "meta.array.literal.ts"
begin: "\\["
beginCaptures:
"0":
name: "meta.brace.square.ts"
end: "\\]"
endCaptures:
"0":
name: "meta.brace.square.ts"
patterns: [
{
include: "#expression"
}
]
"numeric-literal":
name: "constant.numeric.ts"
match: "\\b(?<=[^$])((0(x|X)[0-9a-fA-F]+)|([0-9]+(\\.[0-9]+)?))\\b"
"boolean-literal":
name: "constant.language.boolean.ts"
match: "\\b(false|true)\\b"
"null-literal":
name: "constant.language.null.ts"
match: "\\b(null)\\b"
"this-literal":
name: "constant.language.this.ts"
match: "\\b(this)\\b"
"undefined-literal":
name: "constant.language.ts"
match: "\\b(undefined)\\b"
"access-modifier":
name: "storage.modifier.ts"
match: "\\b(public|protected|private)\\b"
"static-modifier":
name: "keyword.other.ts"
match: "\\b(static)\\b"
"property-accessor":
name: "storage.type.property.ts"
match: "\\b(get|set)\\b"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment