TypeScript-TmLanguage/TypeScriptReact.YAML-tmLang...

209 строки
6.4 KiB
Plaintext
Исходник Обычный вид История

2016-08-12 01:38:31 +03:00
# [PackageDev] target_format: plist, ext: tmLanguage
2015-11-06 00:14:57 +03:00
# Similar to TypeScript.YAML-tmLanguage except:
# - Remove type assertion (cast.expr.tsx)
2015-11-06 00:14:57 +03:00
# - Add JSX expression (HTML-like expression).
---
name: TypeScriptReact
scopeName: source.tsx
fileTypes: [tsx]
uuid: 805375ec-d614-41f5-8993-5843fe63ea82
repository:
2016-09-20 22:25:38 +03:00
# Additions:
# expression repository need to include jsx first followed by whaterver ts grammar says
expressionWithoutIdentifiers:
patterns:
- include: '#jsx'
2016-03-17 20:49:23 +03:00
2016-09-20 22:25:38 +03:00
# Overrides:
2016-09-20 22:25:38 +03:00
# We need to override this to make sure cast is not matched from typescript
# We can safely include jsx because thats the first rule matched anyways so it wont impact at all
cast:
2015-11-06 00:14:57 +03:00
patterns:
2016-09-20 22:25:38 +03:00
- include: '#jsx'
2015-11-06 00:14:57 +03:00
# jsx syntax is taken from https://github.com/babel/babel-sublime
jsx:
2015-11-06 00:14:57 +03:00
patterns:
- include: '#jsx-tag-without-attributes-in-expression'
- include: '#jsx-tag-in-expression'
2015-11-06 00:14:57 +03:00
#jsx tags
jsx-tag-without-attributes-in-expression:
begin: |-
(?x)
(?<=[({\[,?=>:*]|&&|\|\||\?|{{lookBehindReturn}}|{{lookBehindDefault}}|^)\s*
2017-10-19 02:39:27 +03:00
(?=(<)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))?\s*(>))
end: (?!\s*(<)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))?\s*(>))
patterns:
- include: '#jsx-tag-without-attributes'
2015-11-06 00:14:57 +03:00
jsx-tag-without-attributes:
name: meta.tag.without-attributes.tsx
2017-10-19 02:39:27 +03:00
begin: (<)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))?\s*(>)
end: (</)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))?\s*(>)
2015-11-06 00:14:57 +03:00
beginCaptures:
'1': {name: punctuation.definition.tag.begin.tsx}
'2': {name: entity.name.tag.tsx}
2017-05-05 02:55:39 +03:00
'3': {name: support.class.component.tsx}
'4': {name: punctuation.definition.tag.end.tsx}
2015-11-06 00:14:57 +03:00
endCaptures:
'1': {name: punctuation.definition.tag.begin.tsx}
'2': {name: entity.name.tag.tsx}
2017-05-05 02:55:39 +03:00
'3': {name: support.class.component.tsx}
'4': {name: punctuation.definition.tag.end.tsx}
contentName: meta.jsx.children.tsx
2015-11-06 00:14:57 +03:00
patterns:
- include: '#jsx-children'
jsx-tag-in-expression:
# We need to differentiate between the relational '<' operator and the beginning of a tag using the surrounding context.
2016-11-19 02:29:38 +03:00
begin: |-
2015-11-06 00:14:57 +03:00
(?x)
(?<=[({\[,?=>:*]|&&|\|\||\?|{{lookBehindReturn}}|{{lookBehindDefault}}|^)\s*
2016-09-22 02:29:02 +03:00
(?!<\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=>])|,)) # look ahead is not type parameter of arrow
(?=(<)\s*
2015-11-06 00:14:57 +03:00
([_$a-zA-Z][-$\w.]*(?<!\.|-))
(?=\s+(?!\?)|/?>))
2017-05-05 02:55:39 +03:00
end: (/>)|(?:(</)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))\s*(>))
2015-11-06 00:14:57 +03:00
endCaptures:
'0': { name: meta.tag.tsx }
'1': { name: punctuation.definition.tag.end.tsx }
'2': { name: punctuation.definition.tag.begin.tsx }
'3': { name: entity.name.tag.tsx }
2017-05-05 02:55:39 +03:00
'4': { name: support.class.component.tsx }
'5': { name: punctuation.definition.tag.end.tsx }
patterns:
- include: '#jsx-tag'
jsx-child-tag:
# Because this would be included from the jsx-children, this doesnt need to inspect surrounding context
2016-11-19 02:29:38 +03:00
begin: |-
(?x)
(?=(<)\s*
([_$a-zA-Z][-$\w.]*(?<!\.|-))
(?=\s+(?!\?)|/?>))
2017-05-05 02:55:39 +03:00
end: (/>)|(?:(</)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))\s*(>))
endCaptures:
'0': { name: meta.tag.tsx }
'1': { name: punctuation.definition.tag.end.tsx }
'2': { name: punctuation.definition.tag.begin.tsx }
'3': { name: entity.name.tag.tsx }
2017-05-05 02:55:39 +03:00
'4': { name: support.class.component.tsx }
'5': { name: punctuation.definition.tag.end.tsx }
patterns:
- include: '#jsx-tag'
jsx-tag:
name: meta.tag.tsx
2016-11-19 02:29:38 +03:00
begin: |-
(?x)
(?=(<)\s*
([_$a-zA-Z][-$\w.]*(?<!\.|-))
(?=\s+(?!\?)|/?>))
end: (?=(/>)|(?:(</)\s*([_$a-zA-Z][-$\w.]*(?<!\.|-))\s*(>)))
patterns:
2016-11-19 02:29:38 +03:00
- begin: |-
(?x)
2016-09-22 02:29:02 +03:00
(<)\s*
2017-05-05 02:55:39 +03:00
((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))
(?=\s+(?!\?)|/?>)
beginCaptures:
'1': { name: punctuation.definition.tag.begin.tsx }
'2': { name: entity.name.tag.tsx }
2017-05-05 02:55:39 +03:00
'3': { name: support.class.component.tsx }
end: (?=[/]?>)
contentName: meta.tag.attributes.tsx
patterns:
- include: '#comment'
- include: '#jsx-tag-attributes'
- include: '#jsx-tag-attributes-illegal'
- begin: (>)
beginCaptures:
'1': { name: punctuation.definition.tag.end.tsx }
end: (?=</)
contentName: meta.jsx.children.tsx
patterns:
- include: '#jsx-children'
2015-11-06 00:14:57 +03:00
#jsx children
2015-11-06 00:14:57 +03:00
jsx-children:
patterns:
- include: '#jsx-tag-without-attributes'
- include: '#jsx-child-tag'
2015-11-06 00:14:57 +03:00
- include: '#jsx-evaluated-code'
- include: '#jsx-entities'
#entities and evaluated code
jsx-evaluated-code:
name: meta.embedded.expression.tsx
begin: \{
end: \}
beginCaptures:
'0': { name: punctuation.section.embedded.begin.tsx }
endCaptures:
'0': { name: punctuation.section.embedded.end.tsx }
2015-11-06 00:14:57 +03:00
patterns:
- include: '#expression'
jsx-entities:
patterns:
- 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 attributes
jsx-tag-attributes:
patterns:
- include: '#jsx-tag-attribute-name'
- include: '#jsx-tag-attribute-assignment'
- include: '#jsx-string-double-quoted'
- include: '#jsx-string-single-quoted'
- include: '#jsx-evaluated-code'
jsx-tag-attribute-name:
match: |-
(?x)
\s*
([_$a-zA-Z][-$\w]*)
(?=\s|=|/?>|/\*|//)
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'
jsx-tag-attributes-illegal:
name: invalid.illegal.attribute.tsx
match: \S+
2015-11-06 00:14:57 +03:00
2016-02-02 04:10:11 +03:00
...