-
Notifications
You must be signed in to change notification settings - Fork 589
/
JSON.sublime-syntax
235 lines (203 loc) · 5.9 KB
/
JSON.sublime-syntax
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
%YAML 1.2
---
name: JSON
scope: source.json
version: 2
file_extensions:
- json
- jsonc
- sublime-build
- sublime-color-scheme
- sublime-commands
- sublime-completions
- sublime-keymap
- sublime-macro
- sublime-menu
- sublime-mousemap
- sublime-project
- sublime-settings
- sublime-theme
- sublime-merge-theme
- sublime-workspace
- ipynb
- gltf
- avsc
hidden_file_extensions:
- Pipfile.lock
- hidden-color-scheme
- sublime_session
first_line_match: |-
(?xi:
^ \s* // .*? -\*- .*? \bjsonc?\b .*? -\*- # editorconfig
)
contexts:
prototype:
- include: comments
main:
- include: values
values:
- include: constants
- include: floats
- include: integers
- include: strings
- include: arrays
- include: objects
###[ COMMENTS ]################################################################
comments:
- include: block-comments
- include: line-comments
block-comments:
# empty block comments
- match: /\*\*+/
scope: comment.block.empty.json punctuation.definition.comment.json
# documentation block comments
- match: /\*\*+
scope: punctuation.definition.comment.begin.json
push: block-comment-documentation-body
# normal block comments
- match: /\*
scope: punctuation.definition.comment.begin.json
push: block-comment-body
block-comment-documentation-body:
- meta_include_prototype: false
- meta_scope: comment.block.documentation.json
- match: \*+/
scope: punctuation.definition.comment.end.json
pop: 1
- match: ^\s*(\*)(?![*/])
captures:
1: punctuation.definition.comment.json
block-comment-body:
- meta_include_prototype: false
- meta_scope: comment.block.json
- match: \*/
scope: punctuation.definition.comment.end.json
pop: 1
- match: ^\s*(\*)(?![*/])
captures:
1: punctuation.definition.comment.json
line-comments:
- match: //
scope: punctuation.definition.comment.json
push: line-comment-body
line-comment-body:
- meta_include_prototype: false
- meta_scope: comment.line.double-slash.json
- match: $\n?
pop: 1
###[ ARRAYS ]##################################################################
arrays:
- match: \[
scope: punctuation.section.sequence.begin.json
push: array-body
array-body:
- meta_scope: meta.sequence.json
- match: \]
scope: punctuation.section.sequence.end.json
pop: 1
- match: ','
scope: punctuation.separator.sequence.json
- include: values
- match: \S
scope: invalid.illegal.expected-sequence-separator.json
###[ OBJECTS ]#################################################################
objects:
- match: \{
scope: punctuation.section.mapping.begin.json
push: object-body
object-body:
- meta_scope: meta.mapping.json
- match: \}
scope: punctuation.section.mapping.end.json
pop: 1
- match: \"
scope: punctuation.definition.string.begin.json
push: object-key-body
- match: ':'
scope: punctuation.separator.key-value.json
push: expect-object-value
- match: \S
scope: invalid.illegal.expected-mapping-key.json
object-key-body:
- clear_scopes: 1
- meta_include_prototype: false
- meta_scope: meta.mapping.key.json string.quoted.double.json
- include: double-quoted-string-body
expect-object-value:
- meta_include_prototype: false
- include: comments
- match: ',|\s?(?=\})'
scope: invalid.illegal.expected-mapping-value.json
pop: 1
- match: (?=\S)
set: object-value-body
object-value-body:
- clear_scopes: 1
- meta_scope: meta.mapping.value.json
- include: values
- match: ''
set: object-value-end
object-value-end:
- meta_include_prototype: false
- include: comments
- match: (?=\s*\})
pop: 1
- match: ','
scope: punctuation.separator.sequence.json
pop: 1
- match: \s(?!/[/*])(?=[^\s,])|[^\s,]
scope: invalid.illegal.expected-mapping-separator.json
pop: 1
###[ LITERALS ]################################################################
constants:
- match: \bfalse\b
scope: constant.language.boolean.false.json
- match: \btrue\b
scope: constant.language.boolean.true.json
- match: \bnull\b
scope: constant.language.null.json
floats:
- match: (-?)((?:0|[1-9]\d*)(?:(?:(\.)\d+)(?:[eE][-+]?\d+)?|(?:[eE][-+]?\d+)))
scope: meta.number.float.decimal.json
captures:
1: keyword.operator.arithmetic.json
2: constant.numeric.value.json
3: punctuation.separator.decimal.json
integers:
- match: (-?)(0|[1-9]\d*)
scope: meta.number.integer.decimal.json
captures:
1: keyword.operator.arithmetic.json
2: constant.numeric.value.json
strings:
- match: \"
scope: punctuation.definition.string.begin.json
push: double-quoted-string-body
double-quoted-string-body:
- meta_include_prototype: false
- meta_scope: meta.string.json string.quoted.double.json
- match: \"
scope: punctuation.definition.string.end.json
pop: 1
- match: \n
scope: invalid.illegal.unclosed-string.json
pop: 1
- include: string-prototype
- include: string-escapes
# for use by inheriting syntaxes to easily inject string interpolation
# in any kind of quoted or unquoted string
string-prototype: []
string-escapes:
- match: |-
(?x: # turn on extended mode
\\ # a literal backslash
(?: # ...followed by...
["\\/bfnrt] # one of these characters
| # ...or...
u # a u
[0-9a-fA-F]{4} # and four hex digits
)
)
scope: constant.character.escape.json
- match: \\.
scope: invalid.illegal.unrecognized-string-escape.json