-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathSublime JSON.sublime-syntax
More file actions
573 lines (492 loc) · 15.2 KB
/
Sublime JSON.sublime-syntax
File metadata and controls
573 lines (492 loc) · 15.2 KB
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
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
# This file serves as a shared repository for the various JSON-based resource files,
# because of how similar they are.
# As a result,
# the most specific scope node will just be named "sublime" instead of "sublime-menu",
# since it is most likely being used in multiple places.
#
# Also, I'm calling this "Sublime JSON" because it has a nicer ring to it
# and is shorter for importing purposes.
#
# Note that this is very context-push-based.
hidden: true
scope: source.json.sublime
variables:
number: |- # handles integer and decimal numbers
(?x:
-?
(?: 0
| [1-9] \d*
)
(?:
(?: \. \d+ )?
(?: [eE] [+-]? \d+ )?
)?
)
contexts:
main:
- include: comments
- include: any
#################################################
# Comments
#################################################
comments:
# - match: /\*\*(?!/)
# scope: punctuation.definition.comment.json
# push:
# - meta_scope: comment.block.documentation.json
# - match: \*/
# pop: true
- match: /\*
scope: punctuation.definition.comment.begin.json
push:
- meta_scope: comment.block.json
- match: \*/
scope: punctuation.definition.comment.end.json
pop: true
- include: merge-conflict-markers
- match: (//).*$\n?
scope: comment.line.double-slash.js
captures:
1: punctuation.definition.comment.json
- include: merge-conflict-markers
only-comments:
- include: comments
- match: '[^/\s]+'
scope: invalid.illegal.expected-comment-or-eof.sublime
#################################################
# Merge Conflict Markers
#################################################
merge-conflict-markers:
# see also: Diff.sublime-syntax#conflict-markers
- match: ^(<{7})(?:\s+(\S.*?))?$\n?
scope: meta.block.conflict.begin.diff
captures:
1: punctuation.section.block.begin.diff
2: entity.name.section.diff
- match: ^(>{7})(?:\s+(\S.*?))?$\n?
scope: meta.block.conflict.end.diff
captures:
1: punctuation.section.block.end.diff
2: entity.name.section.diff
- match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n?
scope: meta.block.conflict.separator.diff
captures:
1: punctuation.section.block.diff
2: entity.name.section.diff
#################################################
# Any
#################################################
any:
- include: number
- include: string
- include: boolean
- include: 'null'
- include: sequence
- include: mapping
expect-any:
- include: number-pop
- include: string-pop
- include: boolean-pop
- include: null-pop
- include: sequence-pop
- include: mapping-pop
- match: \s*(?=[},\]])
scope: invalid.illegal.expected-value.sublime
pop: true
expect-any-value:
- include: comments
- include: expect-number-value-only
- include: expect-string-value-only
- include: expect-boolean-value-only
- include: expect-null-value-only
- include: expect-sequence-value-only
- include: expect-mapping-value-only
- match: \s*(?=[},\]])
scope: invalid.illegal.expected-value.sublime
pop: true
#################################################
# Number
#################################################
number:
- match: '{{number}}'
scope: constant.numeric.json
expect-number:
- include: number-pop
- include: expect-number-rest
expect-number-value:
- include: expect-number-value-only
- include: expect-number-rest
expect-number-value-only:
- match: '(?={{number}})'
set: [mapping-value-meta, number-pop]
expect-number-rest:
- include: comments
- match: \s*(?=[},\]])
scope: invalid.illegal.expected-number.sublime
pop: true
- match: '"([^"]|\\.)*"'
scope: invalid.illegal.expected-number.sublime
- match: \S
scope: invalid.illegal.expected-number.sublime
number-pop:
- match: '{{number}}'
scope: constant.numeric.json
pop: true
#################################################
# String
#################################################
string:
- match: '"'
scope: punctuation.definition.string.begin.json
push: inside-string
expect-string:
- include: string-pop
- include: expect-string-rest
expect-string-value:
- include: expect-string-value-only
- include: expect-string-rest
expect-string-value-only:
- match: (?=")
set: [mapping-value-meta, string-pop]
expect-string-rest:
- include: comments
- match: \{
set:
- meta_scope: invalid.illegal.expected-string.sublime
- include: in-mapping-ignored
- match: \[
set:
- meta_scope: invalid.illegal.expected-string.sublime
- include: in-sequence-ignored
- match: \s*(?=[},\]])
scope: invalid.illegal.expected-string.sublime
pop: true
- match: \S
scope: invalid.illegal.expected-string.sublime
string-pop:
- match: '"'
scope: punctuation.definition.string.begin.json
set: inside-string
inside-string:
- meta_scope: string.quoted.double.json
- match: '"'
scope: punctuation.definition.string.end.json
pop: true
- match: $\n?
scope: invalid.illegal.unclosed-string.json
pop: true
- include: string-escape
inside-interpolated-string:
- match: '"'
scope: string.quoted.double.json punctuation.definition.string.end.json
pop: true
- match: $\n?
scope: string.quoted.double.json invalid.illegal.unclosed-string.json
pop: true
- include: string-escape
string-escape:
- match: |-
(?x:
\\
(?:
["\\/bfnrt]
| u [0-9a-fA-F]{4}
)
)
scope: constant.character.escape.json
- match: \\.
scope: invalid.illegal.unrecognized-string-escape.json
#################################################
# Boolean
#################################################
boolean:
- match: \b(?:true|false)\b
scope: constant.language.boolean.json
expect-boolean:
- include: boolean-pop
- include: expect-boolean-rest
expect-boolean-value:
- include: expect-boolean-value-only
- include: expect-boolean-rest
expect-boolean-value-only:
- match: \b(?=true|false\b)
set: [mapping-value-meta, boolean-pop]
expect-boolean-rest:
- include: comments
- match: \s*(?=[},\]])
scope: invalid.illegal.expected-boolean.sublime
pop: true
- match: \S
scope: invalid.illegal.expected-boolean.sublime
boolean-pop:
- match: \b(?:true|false)\b
scope: constant.language.boolean.json
pop: true
#################################################
# Null
#################################################
'null':
- match: \bnull\b
scope: constant.language.null.json
expect-null:
- include: null-pop
- include: expect-null-rest
expect-null-value:
- include: expect-null-value-only
- include: expect-null-rest
expect-null-value-only:
- match: \b(?=null\b)
set: [mapping-value-meta, null-pop]
expect-null-rest:
- include: comments
- match: \s*(?=[},\]])
scope: invalid.illegal.expected-null.sublime
pop: true
- match: \S
scope: invalid.illegal.expected-null.sublime
null-pop:
- match: \bnull\b
scope: constant.language.null.json
pop: true
#################################################
# Sequence
#################################################
sequence:
- match: (?=\[)
push: sequence-pop
expect-sequence-value:
- include: expect-sequence-value-only
- include: expect-sequence-rest
expect-sequence-value-only:
- match: (?=\[)
set: [mapping-value-meta, sequence-pop]
expect-sequence-rest:
- include: comments
- match: \{
set:
- meta_scope: invalid.illegal.expected-sequence.sublime
- include: in-mapping-ignored
- match: \s*(?=[},\]])
scope: invalid.illegal.expected-sequence.sublime
pop: true
- match: \S
scope: invalid.illegal.expected-sequence.sublime
sequence-pop:
- match: \[
scope: punctuation.section.sequence.begin.json
set:
- meta_scope: meta.sequence.json
- include: comments
- match: \]
scope: punctuation.section.sequence.end.json
pop: true
- match: (?=\S)
push: [in-sequence-expect-comma, expect-any]
in-sequence-expect-comma:
- match: (?=\])
pop: true
- include: comments
- match: ','
scope: punctuation.separator.sequence.json
pop: true
- match: \s*(?=[{"\d\[]|true|false|null)
scope: invalid.illegal.expected-comma.inside-sequence.json
pop: true
- match: \S
scope: invalid.illegal.expected-comma.inside-sequence.json
in-sequence-ignored:
- match: \]
pop: true
- match: \[
push: in-sequence-ignored
#################################################
# Mapping
#################################################
mapping:
- match: (?=\{)
push: mapping-pop
expect-mapping:
- include: comments
- match: (?=\{)
set: mapping-pop
- include: expect-mapping-rest
expect-mapping-value:
- include: expect-mapping-value-only
- include: expect-mapping-rest
expect-mapping-value-only:
- match: (?=\{)
set: [mapping-value-meta, mapping-pop]
expect-mapping-rest:
- include: comments
- match: \[
set:
- meta_scope: invalid.illegal.expected-mapping.sublime
- include: in-sequence-ignored
- match: \s*(?=[},\]])
scope: invalid.illegal.expected-mapping.sublime
pop: true
- match: \S
scope: invalid.illegal.expected-mapping.sublime
mapping-pop:
- match: \{
scope: punctuation.section.mapping.begin.json
set:
- meta_scope: meta.mapping.json
- match: \}
scope: punctuation.section.mapping.end.json
pop: true
- include: key
- include: expect-key-rest
key:
- match: (?=")
push: [in-mapping-expect-comma, key-pop]
expect-key-rest:
- include: comments
- match: \s*(?=[\]])
scope: invalid.illegal.expected-key.json
pop: true
# Try to match only valid "values" as invalid,
# not any bare words.
- match: (,|{{number}}|\b(true|false|null))
scope: invalid.illegal.expected-key.json
- match: \s*(?=\[)
scope: invalid.illegal.expected-key.json
push: sequence-pop
- match: \s*(?=\{)
scope: invalid.illegal.expected-key.json
push: mapping-pop
key-pop:
- clear_scopes: 1 # clear the "meta.mapping.json" scope
- match: \"
scope: punctuation.definition.string.begin.json
set: [expect-any-value, expect-colon, inside-key]
inside-key:
- clear_scopes: 1 # clear the "meta.mapping.json" scope
- meta_scope: meta.mapping.key.json string.quoted.double.json
- match: '"'
scope: punctuation.definition.string.end.json
pop: true
- include: inside-string
expect-colon:
- include: comments
- match: ':'
scope: punctuation.separator.mapping.key-value.json
pop: true
- match: \s*(?=[},\]"])
scope: invalid.illegal.expected-colon.json
pop: true
- match: \S
scope: invalid.illegal.expected-colon.json
in-mapping-expect-comma:
- match: ''
set:
- meta_scope: meta.expect-comma.sublime
- include: comments
- match: ','
scope: punctuation.separator.mapping.pair.json
pop: true
- match: (?=})
pop: true
- match: \s*(?=")
scope: invalid.illegal.expected-comma.inside-mapping.json
pop: true
- match: \S
scope: invalid.illegal.expected-comma.inside-mapping.json
mapping-value-meta:
- clear_scopes: 1
- meta_scope: meta.mapping.value.json
- match: ''
pop: true
in-mapping-ignored:
- match: \}
pop: true
- match: \{
push: in-mapping-ignored
#################################################
# Special Values
#################################################
expect-command-name-value:
- match: (?=")
set: [mapping-value-meta, command-name-pop]
- include: expect-string-rest
command-name-pop:
- match: (\")([a-z_\d]+)(\")
scope: meta.command-name.sublime string.quoted.double.json
captures:
1: punctuation.definition.string.begin.json
2: support.constant.command-name.sublime
3: punctuation.definition.string.end.json
pop: true
- match: \" # probably illegal command name
scope: punctuation.definition.string.begin.json
set:
- meta_scope: meta.command-name.sublime string.quoted.double.json
- meta_content_scope: invalid.illegal.invalid-command.sublime
- match: \"
scope: punctuation.definition.string.end.json
pop: true
- include: string-escape
- match: $\n?
scope: invalid.illegal.unclosed-string.json
pop: true
expect-scope-string-value:
- match: (?=")
set: [mapping-value-meta, scope-string-pop]
- include: expect-string-rest
scope-string-pop:
- match: '"'
scope: punctuation.definition.string.begin.json
set:
- meta_scope: meta.scope-selector.sublime string.quoted.double.json
- meta_content_scope: source.scope-selector
- include: scope:source.scope-selector
- match: '"'
scope: punctuation.definition.string.end.json
pop: true
expect-snippet-string-value:
- match: (?=")
set: [mapping-value-meta, snippet-string-pop]
- include: expect-string-rest
snippet-string-pop:
- match: \"
scope: punctuation.definition.string.begin.json punctuation.definition.snippet.begin.sublime
set:
- meta_scope: string.quoted.double.json
- match: '"'
scope: punctuation.definition.string.end.json punctuation.definition.snippet.end.sublime
pop: true
- match: $\n?
scope: invalid.illegal.unclosed-string.json
pop: true
- match: ''
push:
- meta_content_scope: source.sublime.snippet.embedded.json-string
- include: scope:source.sublime.snippet
with_prototype:
- match: (?="|$)
pop: true
- match: '(\\)(\\)([$}])'
captures:
1: constant.character.escape.json
2: constant.character.escape.json constant.character.escape.snippet
3: constant.character.escape.snippet
- include: string-escape
expect-caption-string-value:
- match: (?=")
set: [mapping-value-meta, caption-string-pop]
- include: expect-string-rest
caption-string-pop:
- match: \"
scope: punctuation.definition.string.begin.json punctuation.definition.snippet.begin.sublime
set:
- meta_scope: string.quoted.double.json meta.caption.sublime
- match: '"'
scope: punctuation.definition.string.end.json punctuation.definition.snippet.end.sublime
pop: true
- match: $\n?
scope: invalid.illegal.unclosed-string.json
pop: true
- include: string-escape