Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 4fe3643

Browse files
MaximSokolovJohn Gardner
authored andcommitted
Clean up pattern groups
Closes #276.
1 parent 6e63fcc commit 4fe3643

File tree

1 file changed

+48
-42
lines changed

1 file changed

+48
-42
lines changed

grammars/javascript.cson

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
'name': 'JavaScript'
2121
'patterns': [
2222
{
23-
'comment': 'ES6 import'
23+
# ES6 import
2424
'begin': '(?<!\\.)\\b(import)(?!\\s*:)\\b'
2525
'beginCaptures':
2626
'1':
2727
'name': 'keyword.control.js'
28+
'end': '(?=;|$)'
29+
'name': 'meta.import.js'
2830
'patterns': [
2931
{
30-
'comment': '{ member1 , member2 as alias2 , [...] }'
32+
# { member1 , member2 as alias2 , [...] }
3133
'begin': '\\{'
3234
'beginCaptures':
3335
0:
@@ -38,7 +40,14 @@
3840
'name': 'punctuation.definition.modules.end.js'
3941
'patterns': [
4042
{
41-
'comment': '(default|name) as alias'
43+
# (default|name) as alias
44+
'match': '''(?x)
45+
(?: \\b(default)\\b | \\b([a-zA-Z_$][\\w$]*)\\b)
46+
\\s*
47+
(\\b as \\b)
48+
\\s*
49+
(?: (\\b default \\b | \\*) | \\b([a-zA-Z_$][\\w$]*)\\b)
50+
'''
4251
'captures':
4352
'1':
4453
'name': 'variable.language.default.js'
@@ -50,13 +59,6 @@
5059
'name': 'invalid.illegal.js'
5160
'5':
5261
'name': 'variable.other.module-alias.js'
53-
'match': '''(?x)
54-
(?: \\b(default)\\b | \\b([a-zA-Z_$][\\w$]*)\\b)
55-
\\s*
56-
(\\b as \\b)
57-
\\s*
58-
(?: (\\b default \\b | \\*) | \\b([a-zA-Z_$][\\w$]*)\\b)
59-
'''
6062
}
6163
{
6264
'match': ','
@@ -72,7 +74,14 @@
7274
]
7375
}
7476
{
75-
'comment': '(default|*|name) as alias'
77+
# (default|*|name) as alias
78+
'match': '''(?x)
79+
(?: \\b(default)\\b | (\\*) | \\b([a-zA-Z_$][\\w$]*)\\b)
80+
\\s*
81+
(\\b as \\b)
82+
\\s*
83+
(?: (\\b default \\b | \\*) | \\b([a-zA-Z_$][\\w$]*)\\b)
84+
'''
7685
'captures':
7786
'1':
7887
'name': 'variable.language.default.js'
@@ -86,13 +95,6 @@
8695
'name': 'invalid.illegal.js'
8796
'6':
8897
'name': 'variable.other.module-alias.js'
89-
'match': '''(?x)
90-
(?: \\b(default)\\b | (\\*) | \\b([a-zA-Z_$][\\w$]*)\\b)
91-
\\s*
92-
(\\b as \\b)
93-
\\s*
94-
(?: (\\b default \\b | \\*) | \\b([a-zA-Z_$][\\w$]*)\\b)
95-
'''
9698
}
9799
{
98100
'match': '\\*'
@@ -121,11 +123,9 @@
121123
'name': 'meta.delimiter.object.comma.js'
122124
}
123125
]
124-
'end': '(?=;|$)'
125-
'name': 'meta.import.js'
126126
}
127127
{
128-
'comment': 'ES6 export: `export default (variable|class|function, etc.)`'
128+
# ES6 export: export default (variable|class|function, etc.)
129129
'match': '''(?x)
130130
\\b(export)\\b\\s*
131131
\\b(default)\\b\\s*
@@ -142,17 +142,19 @@
142142
'name': 'variable.other.module.js'
143143
}
144144
{
145-
'comment': 'ES6 export, re-export: `export {member as alias, [...]} [from ...]`'
145+
# ES6 export, re-export: export {member as alias, [...]} [from ...]
146146
'begin': '(?<!\\.)\\b(export)(?!\\s*:)\\b'
147147
'beginCaptures':
148148
'1':
149149
'name': 'keyword.control.js'
150+
'end': '(?=;|\\bfunction\\b|\\bclass\\b|\\blet\\b|\\bvar\\b|\\bconst\\b|$)'
151+
'name': 'meta.export.js'
150152
'patterns': [
151153
{
152154
'include': '#numbers'
153155
}
154156
{
155-
'comment': '`{ member1 , member2 as alias2 , [...] }` inside re-export'
157+
# { member1 , member2 as alias2 , [...] } inside re-export
156158
'begin': '\\{(?=.*\\bfrom\\b)'
157159
'beginCaptures':
158160
0:
@@ -163,7 +165,14 @@
163165
'name': 'punctuation.definition.modules.end.js'
164166
'patterns': [
165167
{
166-
'comment': '(default|name) as alias'
168+
# (default|name) as alias
169+
'match': '''(?x)
170+
(?: \\b(default)\\b | \\b([a-zA-Z_$][\\w$]*)\\b)
171+
\\s*
172+
(\\b as \\b)
173+
\\s*
174+
(?: \\b(default)\\b | (\\*) | \\b([a-zA-Z_$][\\w$]*)\\b)
175+
'''
167176
'captures':
168177
'1':
169178
'name': 'variable.language.default.js'
@@ -177,13 +186,6 @@
177186
'name': 'invalid.illegal.js'
178187
'6':
179188
'name': 'variable.other.module-alias.js'
180-
'match': '''(?x)
181-
(?: \\b(default)\\b | \\b([a-zA-Z_$][\\w$]*)\\b)
182-
\\s*
183-
(\\b as \\b)
184-
\\s*
185-
(?: \\b(default)\\b | (\\*) | \\b([a-zA-Z_$][\\w$]*)\\b)
186-
'''
187189
}
188190
{
189191
'match': ','
@@ -199,7 +201,7 @@
199201
]
200202
}
201203
{
202-
'comment': '{ member1 , member2 as alias2 , [...] }'
204+
# { member1 , member2 as alias2 , [...] }
203205
'begin': '(?![a-zA-Z_$0-9])\\{'
204206
'beginCaptures':
205207
0:
@@ -210,7 +212,7 @@
210212
'name': 'punctuation.definition.modules.end.js'
211213
'patterns': [
212214
{
213-
'comment': 'name as (default|alias)'
215+
# name as (default|alias)
214216
'captures':
215217
'1':
216218
'name': 'invalid.illegal.js'
@@ -275,8 +277,6 @@
275277
'include': '#operators'
276278
}
277279
]
278-
'end': '(?=;|\\bfunction\\b|\\bclass\\b|\\blet\\b|\\bvar\\b|\\bconst\\b|$)'
279-
'name': 'meta.export.js'
280280
}
281281
{
282282
'match': '''(?x)
@@ -816,12 +816,12 @@
816816
'include': '#comments'
817817
}
818818
{
819+
'match': '(<!--|-->)'
819820
'captures':
820821
'0':
821822
'name': 'punctuation.definition.comment.html.js'
822823
'2':
823824
'name': 'punctuation.definition.comment.html.js'
824-
'match': '(<!--|-->)'
825825
'name': 'comment.block.html.js'
826826
}
827827
{
@@ -1114,13 +1114,13 @@
11141114
'name': 'meta.delimiter.method.period.js'
11151115
}
11161116
{
1117+
# Allows the special return snippet to fire.
1118+
'match': '({)(})'
11171119
'captures':
11181120
'1':
11191121
'name': 'punctuation.section.scope.begin.js'
11201122
'2':
11211123
'name': 'punctuation.section.scope.end.js'
1122-
'comment': 'Allows the special return snippet to fire.'
1123-
'match': '({)(})'
11241124
}
11251125
{
11261126
'begin': '{'
@@ -1751,23 +1751,29 @@
17511751
'patterns': [
17521752
{
17531753
'begin': '/\\*\\*(?!/)'
1754-
'captures':
1754+
'beginCaptures':
1755+
'0':
1756+
'name': 'punctuation.definition.comment.js'
1757+
'end': '\\*/'
1758+
'endCaptures':
17551759
'0':
17561760
'name': 'punctuation.definition.comment.js'
1761+
'name': 'comment.block.documentation.js'
17571762
'patterns': [
17581763
{
17591764
'include': '#docblock'
17601765
}
17611766
]
1762-
'end': '\\*/'
1763-
'name': 'comment.block.documentation.js'
17641767
}
17651768
{
17661769
'begin': '/\\*'
1767-
'captures':
1770+
'beginCaptures':
17681771
'0':
17691772
'name': 'punctuation.definition.comment.js'
17701773
'end': '\\*/'
1774+
'endCaptures':
1775+
'0':
1776+
'name': 'punctuation.definition.comment.js'
17711777
'name': 'comment.block.js'
17721778
}
17731779
{

0 commit comments

Comments
 (0)