Some restructuring in react grammar

This commit is contained in:
Sheetal Nandi 2018-03-13 13:17:19 -07:00
Родитель aef7be5c6d
Коммит cd961ac97a
2 изменённых файлов: 52 добавлений и 134 удалений

Просмотреть файл

@ -16,6 +16,7 @@ variables:
jsxClosingTag: (</){{jsxTagName}}?\s*(>)
jsxTagStart: (<){{jsxTagName}}(?=(?:\s*{{typeArguments}})?\s+(?!\?)|\/?>)
jsxTagStartLookahead: (?={{jsxTagStart}})
jsxLookBehindInExpression: (?<=[({\[,?=>:*]|&&|\|\||\?|{{lookBehindReturn}}|{{lookBehindDefault}}|^)\s*
repository:
# Additions:
@ -40,11 +41,8 @@ repository:
#jsx tags
jsx-tag-without-attributes-in-expression:
begin: |-
(?x)
(?<=[({\[,?=>:*]|&&|\|\||\?|{{lookBehindReturn}}|{{lookBehindDefault}}|^)\s*
(?={{jsxOpeningTagWithoutAttributes}})
end: (?!\s*{{jsxOpeningTagWithoutAttributes}})
begin: '{{jsxLookBehindInExpression}}(?={{jsxOpeningTagWithoutAttributes}})'
end: (?!{{jsxOpeningTagWithoutAttributes}})
patterns:
- include: '#jsx-tag-without-attributes'
@ -74,28 +72,18 @@ repository:
# We need to differentiate between the relational '<' operator and the beginning of a tag using the surrounding context.
begin: |-
(?x)
(?<=[({\[,?=>:*]|&&|\|\||\?|{{lookBehindReturn}}|{{lookBehindDefault}}|^)\s*
{{jsxLookBehindInExpression}}
(?!<\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=>])|,)) # look ahead is not type parameter of arrow
{{jsxTagStartLookahead}}
end: (/>)|(?:{{jsxClosingTag}})
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.namespace.tsx }
'4': { name: punctuation.separator.namespace.tsx }
'5': { name: entity.name.tag.tsx }
'6': { name: support.class.component.tsx }
'7': { name: punctuation.definition.tag.end.tsx }
end: (?!{{jsxTagStart}})
patterns:
- include: '#jsx-tag'
jsx-child-tag:
# Because this would be included from the jsx-children, this doesnt need to inspect surrounding context
jsx-tag:
name: meta.tag.tsx
begin: '{{jsxTagStartLookahead}}'
end: (/>)|(?:{{jsxClosingTag}})
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.namespace.tsx }
@ -104,13 +92,6 @@ repository:
'6': { name: support.class.component.tsx }
'7': { name: punctuation.definition.tag.end.tsx }
patterns:
- include: '#jsx-tag'
jsx-tag:
name: meta.tag.tsx
begin: '{{jsxTagStartLookahead}}'
end: (?=(/>)|(?:{{jsxClosingTag}}))
patterns:
- begin: '{{jsxTagStart}}'
beginCaptures:
'1': { name: punctuation.definition.tag.begin.tsx }
@ -137,7 +118,8 @@ repository:
jsx-children:
patterns:
- include: '#jsx-tag-without-attributes'
- include: '#jsx-child-tag'
# Because this would be included from the jsx-children, this doesnt need to inspect surrounding context
- include: '#jsx-tag'
- include: '#jsx-evaluated-code'
- include: '#jsx-entities'

Просмотреть файл

@ -6926,11 +6926,9 @@
<key>jsx-tag-without-attributes-in-expression</key>
<dict>
<key>begin</key>
<string>(?x)
(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|^return|[^\._$[:alnum:]]return|^default|[^\._$[:alnum:]]default|^)\s*
(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<string>(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|^return|[^\._$[:alnum:]]return|^default|[^\._$[:alnum:]]default|^)\s*(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<key>end</key>
<string>(?!\s*(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<string>(?!(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<key>patterns</key>
<array>
<dict>
@ -7031,107 +7029,7 @@
(?!&lt;\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=&gt;])|,)) # look ahead is not type parameter of arrow
(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=(?:\s*&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;|\&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;)*(?!=)\&gt;)*(?!=)&gt;)?\s+(?!\?)|\/?&gt;))</string>
<key>end</key>
<string>(/&gt;)|(?:(&lt;/)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>meta.tag.tsx</string>
</dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.tag.end.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.definition.tag.begin.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>entity.name.tag.namespace.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>punctuation.separator.namespace.tsx</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>entity.name.tag.tsx</string>
</dict>
<key>6</key>
<dict>
<key>name</key>
<string>support.class.component.tsx</string>
</dict>
<key>7</key>
<dict>
<key>name</key>
<string>punctuation.definition.tag.end.tsx</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#jsx-tag</string>
</dict>
</array>
</dict>
<key>jsx-child-tag</key>
<dict>
<key>begin</key>
<string>(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=(?:\s*&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;|\&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;)*(?!=)\&gt;)*(?!=)&gt;)?\s+(?!\?)|\/?&gt;))</string>
<key>end</key>
<string>(/&gt;)|(?:(&lt;/)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>meta.tag.tsx</string>
</dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.tag.end.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.definition.tag.begin.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>entity.name.tag.namespace.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>punctuation.separator.namespace.tsx</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>entity.name.tag.tsx</string>
</dict>
<key>6</key>
<dict>
<key>name</key>
<string>support.class.component.tsx</string>
</dict>
<key>7</key>
<dict>
<key>name</key>
<string>punctuation.definition.tag.end.tsx</string>
</dict>
</dict>
<string>(?!(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=(?:\s*&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;|\&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;)*(?!=)\&gt;)*(?!=)&gt;)?\s+(?!\?)|\/?&gt;))</string>
<key>patterns</key>
<array>
<dict>
@ -7147,7 +7045,45 @@
<key>begin</key>
<string>(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=(?:\s*&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;|\&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;)*(?!=)\&gt;)*(?!=)&gt;)?\s+(?!\?)|\/?&gt;))</string>
<key>end</key>
<string>(?=(/&gt;)|(?:(&lt;/)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;)))</string>
<string>(/&gt;)|(?:(&lt;/)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.tag.end.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.definition.tag.begin.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>entity.name.tag.namespace.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>punctuation.separator.namespace.tsx</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>entity.name.tag.tsx</string>
</dict>
<key>6</key>
<dict>
<key>name</key>
<string>support.class.component.tsx</string>
</dict>
<key>7</key>
<dict>
<key>name</key>
<string>punctuation.definition.tag.end.tsx</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
@ -7240,7 +7176,7 @@
</dict>
<dict>
<key>include</key>
<string>#jsx-child-tag</string>
<string>#jsx-tag</string>
</dict>
<dict>
<key>include</key>