forked from nxp-archive/JCShell-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JCShell Tools.YAML-tmLanguage
663 lines (616 loc) · 23.9 KB
/
JCShell Tools.YAML-tmLanguage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# [PackageDev] target_format: plist, ext: tmLanguage
---
name: JCShell Tools
scopeName: source.jcsh
fileTypes: [jcsh]
uuid: 18d303a3-9fdd-4503-8eba-e8c0b283ddc1
version: 1.0.1
# Define here variables to be re-used in the file for ease of modification
yaml_variable: &CMD_LIST_SLASH_BUILTIN
match: (?<=^|:|\()\s*([@\-])?(/)(app|applet|atr|c-v|cap-clear|cap-del-auth|cap-extrdt-auth|cap-info|cap-inst-auth|cap-load-auth|cap-reg-update|cap-sign|card|change-protocol|channel|clear-vars|close|echo|error|exchange-poweroff|exchange-warmreset|exec|expr|glob|identify|l-r|l-v|list-readers|list-vars|manage-channel|mode|printf|r-echo|register|s-v|select|send|set-channel|set-var|sleep|start-timer|stop-timer|term|terminal)(?=\s|\)|#|$)
yaml_variable: &CMD_LIST_BUILTIN
match: (?<=^|:|\()\s*([@\-])?(>|\?|auth|card-info|delete|delete-key|ext-auth|extradite|flush|get-cplc|get-crs-state|get-data|get-sd-cert|help|init-upd|init-update|install|internal-authenticate|ls|mutual-authenticate|perform-security-operation|personalize|print-key|put-key|put-key-ecc|put-keyset|put-pub-key|quit|registry-update|select|send|session-info|set-applet|set-crs-state|set-key|set-scp|set-sd-state|set-security|set-state|store-aid|store-data|store-keyset|upload|upload-install-make-selectable|version)(?=\s|\)|#|$)
yaml_variable: &CMD_LIST_CRYPTO
match: (?<=^|:|\()\s*([@\-])?(decrypt|encrypt|hash|keygen|mac|pad|sign|unpad)(?=\s|\)|#|$)
yaml_variable: &VAR_LIST_BUILTIN
match: (?<=\{)\s*(?:[Aa]rgv|[Cc]hannel|ECC_CURVEPARAM_A|ECC_CURVEPARAM_B|ECC_CURVEPARAM_G|ECC_CURVEPARAM_N|ECC_CURVEPARAM_P|ECC_SharedSecret|exec\.dir|exec\.errorlog|exec\.output|JCOPDIR|KEY_ECC_PrivateKey|KEY_ECC_PublicKeyX|KEY_ECC_PublicKeyY|KEY_RSA_PrivateKey|KEY_RSA_PrivateKey_dP|KEY_RSA_PrivateKey_dQ|KEY_RSA_PrivateKey_P|KEY_RSA_PrivateKey_PQ|KEY_RSA_PrivateKey_Q|KEY_RSA_PublicKey|last\.apdu\.executiontime|last\.apdu\.executiontime\.unit|last\.error|last\.errorlog|last\.executiontime|last\.executiontime\.unit|last\.response\.data|last\.response\.status|last\.return|logfile\.list|[Pp]ath|[Pp]lugin|random|[Rr]esponse|script\.dir|script\.line|script\.name|scrtimer\.exec\.time|SIGNATURE_ECDSA_R|SIGNATURE_ECDSA_S|SIGNATURE_RSA|timer\.execution\.time|timer\.id|[Tt]erminal|time|VERIFY_SIGN|[Vv]ersion)\s*(?=[\[;\}])
yaml_variable: # Clear the node (variable)
patterns:
- include: '#empty-line'
- include: '#comment'
- include: '#label'
- include: '#line-continuation'
- include: '#comment-line'
- include: '#return-statement'
- include: '#function-definition'
- include: '#if-block'
- include: '#while-block'
- include: '#for-block'
- include: '#try-block'
- include: '#flow-statement'
- include: '#assignment-operator'
- include: '#assignment-command'
- include: '#string'
- include: '#call'
- include: '#invalid-character'
repository:
empty-line:
patterns:
- comment: Line containing only whitespace
name: meta.empty.jcsh
match: ^\s*(\\)?$
comment-line:
patterns:
- comment: Line containing only whitespace and a single-line comment starting
with '#'
name: meta.comment.line.full.jcsh
match: ^\s*((#).*)$
captures:
'1': {name: comment.line.jcsh}
'2': {name: punctuation.definition.comment.jcsh}
comment:
patterns:
- comment: In-line comment starting with '#'
name: meta.comment.line.jcsh
match: \s*(?<=\s)((#).*)$
captures:
'1': {name: comment.line.jcsh}
'2': {name: punctuation.definition.comment.jcsh}
invalid-character:
patterns:
- comment: Match anything not matched yet
name: invalid.character.jcsh
match: .
line-continuation:
patterns:
- comment: Line continuation
name: meta.line-continuation.jcsh
begin: (\\)\s*$
beginCaptures:
'1': {name: punctuation.line-continuation.jcsh}
end: $
patterns:
- include: '#invalid-character'
label:
patterns:
- comment: Leading label that can be jumped to using goto. Labels can be placed at the beginning of any line and cannot contain variables
match: ^\s*(\w[\w\-\.]*)\s*(:)
captures:
'1': {name: keyword.control.label.definition.jcsh}
'2': {name: punctuation.definition.label.jcsh}
assignment-command:
patterns:
- comment: Variable assignment with explicit command, only a label can be placed in front
name: meta.assignment.jcsh
begin: (?:^|(?<=.:))\s*(/set-var|/s-v)\s((?:\s*(?:-d|--def|-g|--global|-q|--quote)\s)*)
beginCaptures:
'1': {name: keyword.assignment.command.jcsh}
'2': {name: variable.parameter.flag.jcsh}
end: (?=(?:\s#[^\(])|$|\\)
patterns:
- comment: Match the newly defined variable name (consume up to the next space). We have to rematch the beginning of the line to make sure we only take the first word after the space (and that the regex is not applied to each word on the line)
begin: (?<=(?:/set-var\s|/s-v\s|-d\s|--def\s|-g\s|--global\s|-q\s|--quote\s))\s*
end: (?<=\S)\s+(?=.*|(?:\s#[^\(])|$|\\)
patterns:
- comment: Handle the subscript first (array '[]')
include: '#subscript'
- comment: Then the newly defined variable name
include: '#assignment-name'
- comment: Process the value assigned (after the first space)
include: '#expression'
- comment: Spaces are legit for variable assignment
match: \s
- include: '#invalid-character'
assignment-operator:
patterns:
- comment: "Variable assignment with operator ('='). Avoid assignment detection if the following operators are formed with the '=': <= >= == != =~ or if a space or quote is present. Only a label can be placed in front"
name: meta.assignment.jcsh
begin: (?:^|(?<=.:))\s*(?=[^\s\"\']*[^<>\=\!]\=[^~\=])
end: (?<=.)\s*(?=(?:\s#[^\(])|$|\\)
patterns:
- comment: Consume everything after the first '='
begin: (?<=\=)
end: (?=(?:\s#[^\(])|$|\\)
patterns:
- comment: Process the value assigned (after the '=')
include: '#expression'
- comment: Spaces are legit for variable assignment
match: \s
- include: '#invalid-character'
- comment: Match the newly defined variable name (consume up to the '=')
begin: (?<=(?:.|^))(?=.*\=)
end: (=)(?=.|(?:\s#[^\(])|$|\\)
endCaptures:
'1': {name: keyword.assignment.operator.jcsh}
patterns:
- comment: Handle the subscript first (array '[]')
include: '#subscript'
- comment: Then the newly defined variable name
include: '#assignment-name'
- include: '#invalid-character'
assignment-name:
patterns:
- comment: Name of the variable newly created (that can contains variables calls inside)
patterns:
- include: '#variable'
- include: '#nested-call'
- match: \S
name: variable.other.assigned.jcsh
- include: '#invalid-character'
variable:
patterns:
- comment: Bracket-style variable reference
name: meta.reference.variable.jcsh
begin: (\$)(\{)
beginCaptures:
'1': {name: punctuation.definition.variable.reference.head.jcsh}
'2': {name: punctuation.definition.variable.reference.begin.jcsh}
end: \}
endCaptures:
'0': {name: punctuation.definition.variable.reference.end.jcsh}
patterns:
- include: '#subscript'
- include: '#plugin-modifier'
- include: '#modifier'
- include: '#variable-name'
- include: '#invalid-character'
subscript:
patterns:
- comment: Variable subscript (array '[]')
begin: (\[)
beginCaptures:
'1': {name: string.unquoted.subscript.jcsh punctuation.definition.subscript.begin.jcsh}
end: (\])
endCaptures:
'1': {name: string.unquoted.subscript.jcsh punctuation.definition.subscript.end.jcsh}
patterns:
- comment: Inside the '[]' (no space allowed)
- comment: Match '[*]' to color the '*'
match: (?<=\[)\*(?=\])
name: support.constant.subscript.asterisk.jcsh punctuation.subscript.content.asterisk.jcsh
- comment: Match '[#]' to color the '#', only if it's not part of a variable call
match: (?<=\[)\#(?=\](?:\s|=))
name: support.constant.subscript.number-sign.jcsh punctuation.subscript.content.number-sign.jcsh
- include: '#variable'
- include: '#nested-call'
- include: '#operator'
- comment: Float numbers are not allowed thus only include hex and dec
include: '#number-hex'
- include: '#number-dec'
- include: '#invalid-character'
variable-name:
patterns:
- comment: Variable name. May contain replaced variables and interpolations
begin: (?<=\{)
end: (?=[:\[;\}])
name: meta.variable.name.jcsh
patterns:
- include: '#variable-name-builtin'
- include: '#variable-name-positional'
- include: '#variable-name-environment'
- include: '#variable-name-user'
- include: '#invalid-character'
variable-name-builtin:
patterns:
- comment: Name of a JCShell built-in variable.
name: support.constant.builtin.jcsh
<<: *VAR_LIST_BUILTIN
variable-name-positional:
patterns:
- comment: Name of a positional variable
name: support.constant.positional.jcsh
match: (?<=\{)\d+(?=[\[;\}])
variable-name-environment:
patterns:
- comment: Name of an environment variable (starting with '*')
name: variable.other.environment.jcsh
match: (?<=\{)(\*)[\w.]+(?=[\[;\}])
captures:
'1': {name: support.constant.environment.jcsh punctuation.definition.variable.name.environment.jcsh}
variable-name-user:
patterns:
- comment: User-defined variable name
name: meta.variable.other.user.jcsh
begin: (?<=\{)
end: (?=[:\[;\}])
patterns:
- include: '#variable'
- include: '#nested-call'
- match: \S
name: variable.other.user.jcsh
- include: '#invalid-character'
modifier:
patterns:
- comment: Variable modifier (no space allowed)
name: meta.variable.modifier.jcsh
begin: ;
beginCaptures:
'0': {name: keyword.modifier.separator.jcsh punctuation.separator.variable.modifier.jcsh}
end: (?=[;\}])
patterns:
- include: '#builtin-modifier'
- include: '#variable'
- include: '#nested-call'
- include: '#invalid-character'
builtin-modifier:
patterns:
- comment: Built-in variable modifier name (no space allowed)
name: meta.modifier.name.builtin.jcsh
match: (?<=;)([Dd]irname|[Ff]ilename|[Bb]asename|[Ee]xtension|[Ll]|[Qq]|[Qq]q|[Ll]c|[Uu]c)(?=[;\}])
captures:
'0': {name: keyword.modifier.variable.jcsh}
- comment: Built-in hex variable modifier ('h')
begin: (?<=;)(h)
beginCaptures:
'1': {name: keyword.modifier.variable.jcsh}
end: \s*(?=[;\}])
patterns:
- include: '#builtin-modifier-value'
- comment: Built-in substring variable modifier ('s')
begin: (?<=;)(s)
beginCaptures:
'1': {name: keyword.modifier.variable.jcsh}
end: (?=[;\}])
patterns:
- comment: First argument of substring variable modifier
begin: (?<=s)
end: (?=[,;\}])
patterns:
- include: '#builtin-modifier-value'
- comment: Second argument of substring variable modifier
begin: (,)
beginCaptures:
'1': {name: punctuation.separator.variable.modifier.jcsh}
end: (?=[;\}])
patterns:
- include: '#builtin-modifier-value'
- comment: Built-in assigned variable modifier for Time ('time')
begin: (?<={time;)(fmt)(\=)
beginCaptures:
'1': {name: keyword.modifier.variable.jcsh}
'2': {name: keyword.assignment.operator.jcsh}
end: \s*(?=[;\}])
patterns:
- include: '#string'
- include: '#variable'
- include: '#nested-call'
- name: string.unquoted.assigned-modifier.jcsh
match: .
- include: '#invalid-character'
- comment: Built-in assigned variable modifier for Random ('random')
begin: (?<={random;)(max|len)(\=)
beginCaptures:
'1': {name: keyword.modifier.variable.jcsh}
'2': {name: keyword.assignment.operator.jcsh}
end: (?=[;\}])
patterns:
- include: '#builtin-modifier-value'
builtin-modifier-value:
patterns:
- comment: Values that can be given to a modifier (number)
- include: '#variable'
- include: '#nested-call'
- comment: Either decimal or hexadecimal are accepted
match: (0x[\da-fA-F]*)|(\d*)
captures:
'1': {name: constant.numeric.hexadecimal.jcsh }
'2': {name: constant.numeric.decimal.jcsh }
- include: '#invalid-character'
plugin-modifier:
patterns:
- comment: Modifier for accessing plugin variables
name: meta.variable.plugin-modifier.jcsh
begin: ':'
beginCaptures:
'0': {name: support.class.plugin.variable.jcsh punctuation.separator.variable.modifier.plugin.jcsh}
end: (?=[\[;\}])
patterns:
- include: '#variable'
- include: '#nested-call'
- name: support.class.plugin.variable.jcsh support.variable.name.plugin.jcsh
match: \s*\w[\w\-\.]*\s*
- include: '#invalid-character'
call:
patterns:
- comment: Call to a built-in command, function or external script. Only a label can be placed in front
name: meta.control.call.jcsh
begin: (?:^|(?<=.:))
end: (?<=.)\s*(?=\)|#[^//(]|$|\\)
patterns:
- include: '#callable'
- include: '#argument'
- match: \s
- include: '#invalid-character'
callable:
patterns:
- comment: Callable built-in command, function or external script
name: meta.callable.jcsh
begin: (?<=^|:|\()
# Make sure we do not match 0-length result or ST2 hang with infinite loop
end: (?<!^|:|\(|\s)(?=\s|\)|\s#|$)
patterns:
- comment: JCShell built-in slash command
name: meta.support.function.builtin.slash.jcsh
<<: *CMD_LIST_SLASH_BUILTIN
captures:
'1': {name: string.unquoted.call-modifier.jcsh punctuation.call-modifier.builtin.jcsh}
'2': {name: support.function.builtin.slash.jcsh punctuation.definition.callable.builtin.slash.jcsh}
'3': {name: support.function.builtin.slash.jcsh}
- comment: JCShell built-in command
name: meta.support.function.builtin.jcsh
<<: *CMD_LIST_BUILTIN
captures:
'1': {name: string.unquoted.call-modifier.jcsh punctuation.call-modifier.builtin.jcsh}
'2': {name: support.function.builtin.jcsh}
- comment: JCShell Crypto Plugin command
name: meta.support.function.plugin.crypto.jcsh
<<: *CMD_LIST_CRYPTO
captures:
'1': {name: string.unquoted.call-modifier.jcsh punctuation.call-modifier.builtin.jcsh}
'2': {name: support.function.plugin.crypto.jcsh}
- comment: User-defined callable
name: meta.callable.user.jcsh
begin: (?<=^|:|\()
# Make sure we do not match 0-length result or ST2 hang with infinite loop
end: (?<!^|:|\(|\s)(?=\s|\)|\s#|$)
patterns:
- match: (?<=^|:|\()\s*([@\-])?
captures:
'1': {name: string.unquoted.call-modifier.jcsh punctuation.call-modifier.user.jcsh}
- include: '#variable'
- include: '#nested-call'
- match: \S
name: entity.name.function.jcsh
- include: '#invalid-character'
- include: '#invalid-character'
argument:
patterns:
- comment: Argument of a call
name: meta.argument.jcsh
begin: (?<=\s)\s*
end: (?<=\S)(?=\s|\)|$|\\)
patterns:
- include: '#flag'
- include: '#expression'
- include: '#invalid-character'
flag:
patterns:
- comment: Flag argument of a call
name: meta.flag.jcsh
begin: (?<=\s)(--?)(?=\w)
beginCaptures:
'1': {name: variable.parameter.flag.jcsh punctuation.definition.flag.jcsh}
end: (?<=[\}\)\w])(?=\)|\s|#|$)
patterns:
- include: '#variable'
- include: '#nested-call'
- name: variable.parameter.flag.jcsh
match: \w[\w\-\.]*
- include: '#invalid-character'
expression:
patterns:
- include: '#string'
- include: '#variable'
- include: '#nested-call'
- include: '#operator'
- include: '#number'
- comment: Process the content of parenthesis the same way
begin: (#|%)?(\()
beginCaptures:
'1': {name: keyword.modifier.length.jcsh punctuation.parentheses.modifier.jcsh}
'2': {name: punctuation.parentheses.begin.jcsh}
end: \)
endCaptures:
'0': {name: punctuation.parentheses.end.jcsh}
patterns:
- include: '#expression'
- name: string.unquoted.expression.jcsh
match: '[\w\-\.\=,!:;\[\]#]'
nested-call:
patterns:
- comment: Nested call ('$()')
name: meta.nested-call.jcsh
begin: (\$)(\()
beginCaptures:
'1': {name: keyword.control.nested-call.jcsh punctuation.definition.nested-call.head.jcsh}
'2': {name: string.unquoted.nested-call.jcsh punctuation.definition.nested-call.begin.jcsh}
end: \)
endCaptures:
'0': {name: string.unquoted.nested-call.jcsh punctuation.definition.nested-call.end.jcsh}
patterns:
- begin: (?<=\()
end: (?<=.)\s*(?=\)|#[^\(]|$|(\\))
patterns:
- include: '#callable'
- include: '#argument'
- match: \s
- include: '#invalid-character'
- include: '#invalid-character'
number:
patterns:
- comment: Number are detected if not part of a word
- include: '#number-hex'
- include: '#number-float'
- include: '#number-dec'
number-hex:
patterns:
- comment: Detect hex numbers starting with '0x'
name: constant.numeric.hexadecimal.jcsh
match: (?<!\w)0x[\da-fA-F]+(?!\w|(?:\.[^\.]))
number-float:
patterns:
- comment: "Detect floats numbers (e.g.: 2.2 .2 or 2.) excluding cases of operators '..' (e.g.: [2..3])"
name: constant.numeric.float.jcsh
match: (?:\d*(?<!\.)\.\d+)|(?:\d+\.(?!\.)\d*)
number-dec:
patterns:
- comment: Detect decimal numbers (separated by word boundary, so not in the middle of a word)
name: constant.numeric.decimal.jcsh
match: \b\d+\b
string:
patterns:
- comment: Single-quoted string literal without variable replacement and interpolation
name: string.quoted.single.jcsh
begin: "'"
beginCaptures:
'0': {name: punctuation.definition.string.single.begin.jcsh}
end: "'"
endCaptures:
'0': {name: punctuation.definition.string.single.end.jcsh}
patterns:
- name: constant.character.escape.jcsh
match: \\['\\nrt]
- match: .
- comment: Double-quoted string literal with variable replacement and interpolation
name: string.quoted.double.jcsh
begin: '"'
beginCaptures:
'0': {name: punctuation.definition.string.double.begin.jcsh}
end: '"'
endCaptures:
'0': {name: punctuation.definition.string.double.end.jcsh}
patterns:
- include: '#variable'
- include: '#nested-call'
- name: constant.character.escape.jcsh
match: \\["\\\$nrt]
- match: .
operator:
patterns:
- name: keyword.operator.jcsh
match: -|\*|/|%|\+|<<|>>>|>>|<=|<|>=|>|==|!=|!|=~|~|&|\^|\||\.\.|\?
if-block:
patterns:
- comment: If block, only a label can be placed in front
name: meta.control.if.jcsh
begin: (?:^|(?<=.:))\s*(if)(?=\s+[^\s\\#])
beginCaptures:
'1': {name: keyword.control.if.jcsh}
end: ^\s*(end)\s*(?=\s|$)
endCaptures:
'1': {name: keyword.control.end.if.jcsh}
patterns:
- include: '#elseif-clause'
- include: '#else-clause'
- include: '#flow-expression'
- include: $self
flow-expression:
patterns:
- comment: "Expression check for flow control blocks: if, for, while, elseif, catch, return"
begin: (?<=for|if|elseif|while|catch|return)\s+
end: \s*(?:\s((#).*)?$|(\\))
endCaptures:
'1': {name: comment.line.jcsh}
'2': {name: punctuation.definition.comment.jcsh}
patterns:
- comment: The 'for' block as an additional iterator provided
match: (?<=for\s)\s*(\w[\w\-\.]*)
name: variable.parameter.iterator.jcsh
- include: '#expression'
- match: \s
- include: '#invalid-character'
elseif-clause:
patterns:
- comment: Elseif clause
name: meta.control.elseif.jcsh
match: ^\s*(elseif)(?=\s+[^\s\\#])
captures:
'1': {name: keyword.control.elseif.jcsh}
else-clause:
patterns:
- comment: Else clause
name: meta.control.else.jcsh
match: ^\s*(else)\s*(?=\s|$)
captures:
'1': {name: keyword.control.else.jcsh}
try-block:
patterns:
- comment: Try block, only a label can be placed in front
name: meta.control.try.jcsh
begin: (?:^|(?<=.:))\s*(try)\s*(?=\s|$)
beginCaptures:
'1': {name: keyword.control.try.jcsh}
end: ^\s*(end)\s*(?=\s|$)
endCaptures:
'1': {name: keyword.control.end.try.jcsh}
patterns:
- include: '#catch-clause'
- include: '#flow-expression'
- include: $self
catch-clause:
patterns:
- comment: Catch clause
name: meta.control.catch.jcsh
match: ^\s*(catch)(?=\s+[^\s\\#])
captures:
'1': {name: keyword.control.catch.jcsh}
for-block:
patterns:
- comment: For block, only a label can be placed in front
name: meta.control.for.jcsh
begin: (?:^|(?<=.:))\s*(for)(?=\s+[^\s\\#])
beginCaptures:
'1': {name: keyword.control.for.jcsh}
end: ^\s*(end)\s*(?=\s|$)
endCaptures:
'1': {name: keyword.control.end.for.jcsh}
patterns:
- include: '#flow-expression'
- include: $self
flow-statement:
patterns:
- comment: Break, continue or goto statement, only a label can be placed in front. Goto requires a label after. This is check before callable, thus we enforce keywords continue, goto and break to not be used as function/script name even though JCShell is not actively forbidding it (outside loops)
name: meta.control.flow.jcsh
begin: (?:^|(?<=.:))\s*(?:(break)|(continue)|(?:(goto)(?=\s+\S)))
beginCaptures:
'1': {name: keyword.control.break.jcsh}
'2': {name: keyword.control.continue.jcsh}
'3': {name: keyword.control.goto.jcsh}
end: \s*(?=(?:\s#.*)|$|\\)
patterns:
- include: '#variable'
- include: '#nested-call'
- comment: If the target label is a string, highlight it specially
match: \S
name: keyword.control.label.target.jcsh
- comment: Discard any remaining spaces
match: \s
- include: '#invalid-character'
while-block:
patterns:
- comment: While block, only a label can be placed in front
name: meta.control.while.jcsh
begin: (?:^|(?<=.:))\s*(while)(?=\s+[^\s\\#])
beginCaptures:
'1': {name: keyword.control.while.jcsh}
end: ^\s*(end)\s*(?=\s|$)
endCaptures:
'1': {name: keyword.control.end.while.jcsh}
patterns:
- include: '#flow-expression'
- include: $self
function-definition:
patterns:
- comment: DEFUN function definition. 'GLOBAL' is the only value allowed after function name (with comments)
name: meta.function-definition.jcsh
begin: ^\s*(DEFUN)\s+(\S+)(\s*GLOBAL)?(?=\s|$)
beginCaptures:
'1': {name: keyword.function.definition.begin.jcsh}
'2': {name: entity.name.function.definition.jcsh}
'3': {name: variable.parameter.definition.jcsh}
end: ^\s*(END)\s*(?=\s|$)
endCaptures:
'1': {name: keyword.function.definition.end.jcsh}
patterns:
- include: $self
return-statement:
patterns:
- comment: Return statement, only a label can be placed in front
name: meta.control.return.jcsh
begin: (?:^|(?<=.:))\s*(return)
beginCaptures:
'1': {name: keyword.control.return.jcsh}
end: \s*(?=(?:\s#.*)|$|\\)
patterns:
- include: '#flow-expression'
...