From ec9dddd314c90dc726ee35a85f27b57198068d5a Mon Sep 17 00:00:00 2001 From: Stepan Mikhaylyuk Date: Tue, 20 Oct 2015 18:51:14 +0300 Subject: [PATCH] updated grammar for tsx @basarat, yesterday i fixed #666, but it breaks this grammar supports typescript (shameless copy [from sublime-typescript](https://github.com/Microsoft/TypeScript-Sublime-Plugin/blob/master/TypeScriptReact.YAML-tmLanguage) it's better then babel grammar because for typescript :) --- grammars/tsx.cson | 1105 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 1025 insertions(+), 80 deletions(-) diff --git a/grammars/tsx.cson b/grammars/tsx.cson index 3170d2dbe..ac2b390bc 100644 --- a/grammars/tsx.cson +++ b/grammars/tsx.cson @@ -1,137 +1,941 @@ name: "TypeScript (TSX)" -scopeName: "source.ts.tsx" +scopeName: "source.tsx" fileTypes: [ "tsx" ] patterns: [ { - include: "#pcdata" - } - { - include: "#literal-jsx" - } - { - include: "source.ts" + include: "#expression" } ] repository: - pcdata: + "var-expr": + name: "meta.var.expr.tsx" + begin: "(?|\\Wreturn|^return|^)(?=\\s*<[_$a-zA-Z])" - end: "(?<=/>|>)" + "control-statement": + name: "keyword.control.tsx" + match: "(?)|(/>)" - endCaptures: - "1": - name: "punctuation.definition.tag.begin.jsx" - "2": - name: "entity.name.tag.jsx" - "3": - name: "punctuation.definition.tag.end.jsx" - "4": - name: "punctuation.definition.tag.end.jsx" - patterns: [ - { - include: "#jsx-tag-end" - } - { - include: "#jsx-attributes" - } - ] + include: "#function-declaration" + } + { + include: "#object-declaration" } { - name: "invalid.illegal.tag.incomplete.jsx" - match: "<" + include: "#type-declaration" + } + { + include: "#enum-declaration" + } + ] + "type-declaration": + name: "meta.type.declaration.tsx" + begin: "\\b(type)\\b\\s+([a-zA-Z_$][\\w$]*)\\s*=\\s*" + beginCaptures: + "1": + name: "keyword.other.tsx" + "2": + name: "storage.type.tsx" + end: "(?=[,);>]|var|type|function|class|interface)" + patterns: [ + { + include: "#type" } ] - "jsx-tag-end": - begin: ">" + "enum-declaration": + name: "meta.enum.declaration.tsx" + match: "(?:\\b(const)\\s+)?\\b(enum)\\s+([a-zA-Z_$][\\w$]*)" + captures: + "1": + name: "storage.modifier.tsx" + "2": + name: "storage.type.tsx" + "3": + name: "entity.name.class.tsx" + "object-declaration": + name: "meta.declaration.object.tsx" + begin: "\\b(?:(export)\\s+)?\\b(?:(abstract)\\s+)?\\b(?])|(?<=[\\}>\\]\\)]|[a-zA-Z_$])\\s*(?=\\{)" + patterns: [ + { + include: "#type" + } + { + include: "#string" + } + { + include: "#comment" + } + ] + type: + name: "meta.type.tsx" + 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.tsx" + begin: "\\(" + beginCaptures: + "0": + name: "meta.brace.round.tsx" + end: "\\)" + endCaptures: + "0": + name: "meta.brace.round.tsx" + patterns: [ + { + include: "#comment" + } + { + include: "#parameter-name" + } + { + include: "#type-annotation" + } + { + include: "#variable-initializer" + } + ] + "type-primitive": + name: "meta.type.primitive.tsx" + match: "\\b(string|number|boolean|symbol|any|void)\\b" + captures: + "1": + name: "storage.type.tsx" + "type-paren-or-function-type-parameters": + name: "meta.type.paren.cover.tsx" + begin: "(?:\\b(new)\\b)?\\s*\\(" + beginCaptures: + "1": + name: "keyword.control.tsx" + end: "\\)" + patterns: [ + { + include: "#comment" + } + { + include: "#type" + } + { + include: "#function-type-parameters" + } + ] + "type-operator": + name: "keyword.operator.type.tsx" + match: "[.|]" + "type-function-return-type": + name: "meta.type.function.return.tsx" + begin: "=>" + beginCaptures: + "0": + name: "keyword.operator.tsx" + end: "(?=\\s*[,\\)\\{=;>]|//|$)" + patterns: [ + { + include: "#type" + } + ] + "type-tuple": + name: "meta.type.tuple.tsx" + begin: "\\[" + beginCaptures: + "0": + name: "meta.brace.square.tsx" + end: "\\]" endCaptures: "0": - name: "punctuation.definition.string.end.jsx" + name: "meta.brace.square.tsx" + patterns: [ + { + include: "#type" + } + { + include: "#comment" + } + ] + "type-name": + name: "meta.type.name.tsx" + match: "[a-zA-Z_$][.\\w$]*" + captures: + "1": + name: "entity.name.type.tsx" + "type-parameters": + name: "meta.type.parameters.tsx" + begin: "([a-zA-Z_$][\\w$]*)?(<)" + beginCaptures: + "1": + name: "entity.name.type.tsx" + "2": + name: "meta.brace.angle.tsx" + end: "(?=$)|(>)" + endCaptures: + "2": + name: "meta.brace.angle.tsx" + patterns: [ + { + name: "keyword.other.tsx" + match: "\\b(extends)\\b" + } + { + include: "#comment" + } + { + include: "#type" + } + ] + "variable-initializer": + begin: "(=)" + beginCaptures: + "1": + name: "keyword.operator.tsx" + end: "(?=$|[,);=])" + patterns: [ + { + include: "#expression" + } + ] + expression: + name: "meta.expression.tsx" + patterns: [ + { + include: "#jsx" + } + { + include: "#for-in-simple" + } + { + include: "#string" + } + { + include: "#regex" + } + { + include: "#template" + } + { + include: "#comment" + } + { + include: "#literal" + } + { + include: "#paren-expression" + } + { + include: "#var-expr" + } + { + include: "#declaration" + } + { + include: "#new-expr" + } + { + include: "#block" + } + { + include: "#expression-operator" + } + { + include: "#relational-operator" + } + { + include: "#arithmetic-operator" + } + { + include: "#logic-operator" + } + { + include: "#assignment-operator" + } + { + include: "#storage-keyword" + } + { + include: "#function-call" + } + { + include: "#switch-case" + } + { + include: "#control-statement" + } + ] + "for-in-simple": + name: "forin.expr.tsx" + match: "(?<=\\()\\s*\\b(var|let|const)\\s+([a-zA-Z_$][\\w$]*)\\s+(in|of)\\b" + captures: + "1": + name: "storage.type.tsx" + "3": + name: "keyword.operator.tsx" + "function-call": + name: "functioncall.expr.tsx" + patterns: [ + { + include: "#type-parameters" + } + { + include: "#paren-expression" + } + ] + "new-expr": + name: "new.expr.tsx" + begin: "\\b(new)\\b" + beginCaptures: + "1": + name: "keyword.operator.tsx" + end: "(?=[(;]|$)" + patterns: [ + { + include: "#type" + } + ] + "object-member": + name: "meta.object.member.tsx" + begin: "[a-zA-Z_$][\\w$]*\\s*:" + end: "(?=,|\\})" + patterns: [ + { + include: "#expression" + } + ] + "expression-operator": + name: "keyword.operator.tsx" + match: "=>|\\b(delete|export|import|in|instanceof|module|namespace|new|typeof|void|as)\\b" + "arithmetic-operator": + name: "keyword.operator.arithmetic.tsx" + match: "\\*|/|\\-\\-|\\-|\\+\\+|\\+|%" + "relational-operator": + name: "keyword.operator.comparison.tsx" + match: "===|==|=|!=|!==|<=|>=|<>|<|>" + "assignment-operator": + name: "keyword.operator.assignment.tsx" + match: "<<=|>>=|>>>=|\\*=|(?|/\\*|//) + ''' + captures: + "1": + name: "entity.other.attribute-name.tsx" + "jsx-tag-attribute-assignment": + name: "keyword.operator.assignment.tsx" + match: "=(?=\\s*(?:'|\"|{|/\\*|//|\\n))" + "jsx-string-double-quoted": + name: "string.quoted.double.tsx" + begin: "\"" + end: "\"" + beginCaptures: + "0": + name: "punctuation.definition.string.begin.tsx" + endCaptures: + "0": + name: "punctuation.definition.string.end.tsx" + patterns: [ + { + include: "#jsx-entities" + } + ] + "jsx-string-single-quoted": + name: "string.quoted.single.tsx" + begin: "'" + end: "'" + beginCaptures: + "0": + name: "punctuation.definition.string.begin.tsx" + endCaptures: + "0": + name: "punctuation.definition.string.end.tsx" patterns: [ { include: "#jsx-entities" @@ -140,11 +944,152 @@ repository: "jsx-entities": patterns: [ { - name: "constant.character.entity.jsx" - match: "&(?:[a-zA-Z0-9]+|#\\d+|#x\\h+);" + name: "constant.character.entity.tsx" + match: "(&)([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;)" + captures: + "1": + name: "punctuation.definition.entity.tsx" + "3": + name: "punctuation.definition.entity.tsx" + } + { + name: "invalid.illegal.bad-ampersand.tsx" + match: "&" + } + ] + "jsx-evaluated-code": + name: "meta.brace.curly.tsx" + begin: "{" + end: "}" + beginCaptures: + "0": + name: "punctuation.definition.brace.curly.start.tsx" + endCaptures: + "0": + name: "punctuation.definition.brace.curly.end.tsx" + patterns: [ + { + include: "#expression" } + ] + "jsx-tag-attributes-illegal": + name: "invalid.illegal.attribute.tsx" + match: "\\S+" + "jsx-tag-without-attributes": + name: "tag.without-attributes.tsx" + begin: "(<)([_$a-zA-Z][-$\\w.]*(?)" + end: "()" + beginCaptures: + "1": + name: "punctuation.definition.tag.begin.tsx" + "2": + name: "entity.name.tag.tsx" + "3": + name: "punctuation.definition.tag.end.tsx" + endCaptures: + "1": + name: "punctuation.definition.tag.begin.tsx" + "2": + name: "entity.name.tag.tsx" + "3": + name: "punctuation.definition.tag.end.tsx" + patterns: [ + { + include: "#jsx-children" + } + ] + "jsx-tag-open": + name: "tag.open.tsx" + begin: ''' + (?x) + (<) + ([_$a-zA-Z][-$\\w.]*(?) + ''' + end: "(/?>)" + beginCaptures: + "1": + name: "punctuation.definition.tag.begin.tsx" + "2": + name: "entity.name.tag.tsx" + endCaptures: + "1": + name: "punctuation.definition.tag.end.tsx" + patterns: [ + { + include: "#comment" + } + { + include: "#jsx-tag-attributes" + } + { + include: "#jsx-tag-attributes-illegal" + } + ] + "jsx-tag-close": + name: "tag.close.tsx" + begin: "()" + beginCaptures: + "1": + name: "punctuation.definition.tag.begin.tsx" + "2": + name: "entity.name.tag.tsx" + endCaptures: + "1": + name: "punctuation.definition.tag.end.tsx" + patterns: [ + { + include: "#comment" + } + ] + "jsx-tag-invalid": + name: "invalid.illegal.tag.incomplete.tsx" + match: "<\\s*>" + "jsx-children": + patterns: [ { - name: "invalid.illegal.bad-ampersand.jsx" - match: "&\\S*;" + include: "#jsx-tag-without-attributes" + } + { + include: "#jsx-tag-open" + } + { + include: "#jsx-tag-close" + } + { + include: "#jsx-tag-invalid" + } + { + include: "#jsx-evaluated-code" + } + { + include: "#jsx-entities" + } + ] + jsx: + name: "meta.jsx.tsx" + patterns: [ + { + include: "#jsx-tag-without-attributes" + } + { + include: "#jsx-tag-open" + } + { + include: "#jsx-tag-close" + } + { + include: "#jsx-tag-invalid" + } + { + name: "meta.jsx.children.tsx" + begin: "(?<=(?:'|\"|})>)" + end: "(?=