Skip to content

Commit 7ff6211

Browse files
committed
Add new defs for switch case
1 parent f036ee3 commit 7ff6211

File tree

3 files changed

+112
-23
lines changed

3 files changed

+112
-23
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ repository:
2525
name: keyword.control.ts
2626
match: (?<!\.)\b(break|catch|continue|debugger|declare|do|else|finally|for|if|return|switch|throw|try|while|with|super|case|default)\b
2727

28-
switch-case:
29-
name: case.expr.ts
30-
begin: '(?<!\.)\b(case|default)\b'
31-
beginCaptures:
32-
'1': { name: keyword.control.ts }
33-
end: ':'
34-
patterns:
35-
- include: '#expression'
36-
3728
declaration:
3829
name: meta.declaration.ts
3930
patterns:
@@ -158,7 +149,7 @@ repository:
158149
'5': { name: keyword.operator.ts }
159150
'6': { name: entity.name.function.ts }
160151
'7': { name: keyword.operator.ts }
161-
end: '(?=\}|;|,|$)|(?<=\})'
152+
end: '(?=\}|;|,)|(?<=\})'
162153
patterns:
163154
- include: '#comment'
164155
- include: '#type-parameters'
@@ -388,17 +379,51 @@ repository:
388379
- include: '#declaration'
389380
- include: '#cast'
390381
- include: '#new-expr'
382+
- include: '#switch-expression'
391383
- include: '#block'
392384
- include: '#expression-operator'
393385
- include: '#relational-operator'
394386
- include: '#arithmetic-operator'
395387
- include: '#logic-operator'
396388
- include: '#assignment-operator'
389+
- include: '#switch-case'
397390
- include: '#storage-keyword'
398391
- include: '#function-call'
399-
- include: '#switch-case'
400392
- include: '#control-statement'
401393

394+
switch-variable:
395+
name: switch-variable.expr.ts
396+
begin: \b(switch)\b\s*\(
397+
beginCaptures:
398+
'1': { name: keyword.operator.ts }
399+
end: \)
400+
patterns:
401+
- include: '#expression'
402+
403+
switch-block:
404+
name: switch-block.expr.ts
405+
begin: '{'
406+
end: (?=\})
407+
patterns:
408+
- include: '#expression'
409+
410+
switch-case:
411+
name: case.expr.ts
412+
begin: '(?<!\.)\b(case|default)\b'
413+
beginCaptures:
414+
'1': { name: keyword.control.ts }
415+
end: ':'
416+
patterns:
417+
- include: '#expression'
418+
419+
switch-expression:
420+
name: switch-expr.expr.ts
421+
begin: (?=\bswitch\b\s*\()
422+
end: '}'
423+
patterns:
424+
- include: '#switch-variable'
425+
- include: '#switch-block'
426+
402427
for-in-simple:
403428
name: forin.expr.ts
404429
match: (?<=\()\s*\b(var|let|const)\s+([a-zA-Z_$][\w$]*)\s+(in|of)\b

TypeScript.tmLanguage

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@
335335
<key>include</key>
336336
<string>#new-expr</string>
337337
</dict>
338+
<dict>
339+
<key>include</key>
340+
<string>#switch-expression</string>
341+
</dict>
338342
<dict>
339343
<key>include</key>
340344
<string>#block</string>
@@ -361,15 +365,15 @@
361365
</dict>
362366
<dict>
363367
<key>include</key>
364-
<string>#storage-keyword</string>
368+
<string>#switch-case</string>
365369
</dict>
366370
<dict>
367371
<key>include</key>
368-
<string>#function-call</string>
372+
<string>#storage-keyword</string>
369373
</dict>
370374
<dict>
371375
<key>include</key>
372-
<string>#switch-case</string>
376+
<string>#function-call</string>
373377
</dict>
374378
<dict>
375379
<key>include</key>
@@ -723,7 +727,7 @@
723727
</dict>
724728
</dict>
725729
<key>end</key>
726-
<string>(?=\}|;|,|$)|(?&lt;=\})</string>
730+
<string>(?=\}|;|,)|(?&lt;=\})</string>
727731
<key>name</key>
728732
<string>meta.method.declaration.ts</string>
729733
<key>patterns</key>
@@ -1221,6 +1225,22 @@
12211225
<key>name</key>
12221226
<string>constant.character.escape</string>
12231227
</dict>
1228+
<key>switch-block</key>
1229+
<dict>
1230+
<key>begin</key>
1231+
<string>{</string>
1232+
<key>end</key>
1233+
<string>(?=\})</string>
1234+
<key>name</key>
1235+
<string>switch-block.expr.ts</string>
1236+
<key>patterns</key>
1237+
<array>
1238+
<dict>
1239+
<key>include</key>
1240+
<string>#expression</string>
1241+
</dict>
1242+
</array>
1243+
</dict>
12241244
<key>switch-case</key>
12251245
<dict>
12261246
<key>begin</key>
@@ -1245,6 +1265,50 @@
12451265
</dict>
12461266
</array>
12471267
</dict>
1268+
<key>switch-expression</key>
1269+
<dict>
1270+
<key>begin</key>
1271+
<string>(?=\bswitch\b\s*\()</string>
1272+
<key>end</key>
1273+
<string>}</string>
1274+
<key>name</key>
1275+
<string>switch-expr.expr.ts</string>
1276+
<key>patterns</key>
1277+
<array>
1278+
<dict>
1279+
<key>include</key>
1280+
<string>#switch-variable</string>
1281+
</dict>
1282+
<dict>
1283+
<key>include</key>
1284+
<string>#switch-block</string>
1285+
</dict>
1286+
</array>
1287+
</dict>
1288+
<key>switch-variable</key>
1289+
<dict>
1290+
<key>begin</key>
1291+
<string>\b(switch)\b\s*\(</string>
1292+
<key>beginCaptures</key>
1293+
<dict>
1294+
<key>1</key>
1295+
<dict>
1296+
<key>name</key>
1297+
<string>keyword.operator.ts</string>
1298+
</dict>
1299+
</dict>
1300+
<key>end</key>
1301+
<string>\)</string>
1302+
<key>name</key>
1303+
<string>switch-variable.expr.ts</string>
1304+
<key>patterns</key>
1305+
<array>
1306+
<dict>
1307+
<key>include</key>
1308+
<string>#expression</string>
1309+
</dict>
1310+
</array>
1311+
</dict>
12481312
<key>template</key>
12491313
<dict>
12501314
<key>begin</key>

tests/baselines/Issue335.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
[17, 2]: source.ts meta.declaration.object.ts meta.object.body.ts storage.modifier.ts
66
[17, 10]: source.ts meta.declaration.object.ts meta.object.body.ts keyword.other.ts
77
[24, 5]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts
8-
[25, 13]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts
9-
[26, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts meta.block.ts case.expr.ts keyword.control.ts
10-
[27, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts meta.block.ts case.expr.ts keyword.control.ts
11-
[28, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts meta.block.ts case.expr.ts keyword.control.ts
8+
[25, 13]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts switch-expr.expr.ts switch-variable.expr.ts
9+
[26, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts switch-expr.expr.ts switch-block.expr.ts case.expr.ts keyword.control.ts
10+
[27, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts switch-expr.expr.ts switch-block.expr.ts case.expr.ts keyword.control.ts
11+
[28, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts switch-expr.expr.ts switch-block.expr.ts case.expr.ts keyword.control.ts
1212
[33, 2]: source.ts meta.declaration.object.ts meta.object.body.ts storage.modifier.ts
1313
[33, 10]: source.ts meta.declaration.object.ts meta.object.body.ts keyword.other.ts
1414
[40, 5]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts
15-
[41, 13]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts
16-
[42, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts meta.block.ts case.expr.ts keyword.control.ts
17-
[43, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts meta.block.ts case.expr.ts keyword.control.ts
18-
[44, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts meta.block.ts case.expr.ts keyword.control.ts
15+
[41, 13]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts switch-expr.expr.ts switch-variable.expr.ts
16+
[42, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts switch-expr.expr.ts switch-block.expr.ts case.expr.ts keyword.control.ts
17+
[43, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts switch-expr.expr.ts switch-block.expr.ts case.expr.ts keyword.control.ts
18+
[44, 4]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts meta.decl.block.ts switch-expr.expr.ts switch-block.expr.ts case.expr.ts keyword.control.ts
1919
[49, 2]: source.ts meta.declaration.object.ts meta.object.body.ts storage.modifier.ts
2020
[49, 10]: source.ts meta.declaration.object.ts meta.object.body.ts keyword.other.ts

0 commit comments

Comments
 (0)