-
Notifications
You must be signed in to change notification settings - Fork 0
/
C Parse.sublime-syntax
417 lines (313 loc) · 11 KB
/
C Parse.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
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
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: C Parse
file_extensions:
- c
- h
first_line_match: '-[*]-( Mode:)? C -[*]-'
scope: source.c1x
variables:
_basic_types: 'void|signed|unsigned|char|short|int|long|float|double|signed|unsigned|_Bool|_Complex|_Imaginary'
_aggregate_types: 'struct|union|enum'
_simple_types: '{{_basic_types}}|{{_aggregate_types}}'
_storage_classes: 'static|extern|auto|register|_Thread_local'
_type_qualifiers: 'const|restrict|volatile|_Atomic'
_compiler_directives: 'inline|__restrict__|__restrict|_Noreturn'
_type_modifiers: '{{_storage_classes}}|{{_type_qualifiers}}|{{_compiler_directives}}'
_control_keywords: 'return|if|else|switch|case|default|goto|for|do|while|break|continue'
_word_operators: 'sizeof'
invalid_identifier: '\b(?:{{_simple_types}}|{{_type_modifiers}}|{{_control_keywords}}|{{_word_operators}})\b'
identifier: '\b[[:alpha:]_][[:alnum:]_]*\b'
type_modifier: '\b(?:{{_type_modifiers}})\b'
type_basic: '\b(?:{{_basic_types}})\b'
struct_like: '\b(?:struct|union)\b'
test_declar: '{{type_modifier}}|{{type_basic}}|{{struct_like}}'
contexts:
prototype:
- include: comments
main:
- include: global
global:
- include: preprocessors
- include: test_declar
- include: fallback
# test expr
test_expr_context:
- match: '(?=\S)'
set:
- include: expr_literals
- match: ''
pop: true
subscript_context:
- match: '(?=\S)'
set:
- include: subscripts
- match: ''
pop: true
subscripts:
- scope: punctuation.operator.subscript.begin
match: '\['
push:
- scope: punctuation.operator.subscript.end
match: '\]'
pop: true
- include: expr_fallback
# test declar
test_declar:
- match: '(?={{test_declar}})'
push: [test_declar_after_specifier_context, test_specifier_context]
parameter_declar_context:
- match: '(?={{test_declar}})'
set: [parameter_declarator_context, test_specifier_context]
- include: fallpop
parameter2_declar_context:
- match: '(?={{test_declar}})'
set: [parameter2_declarator_context, test_specifier_context]
- include: fallpop
test_declar_after_specifier_context:
- match: ''
set: [test_declar_scope_context, test_declar_declarator_comma_context, test_declar_declarator_context]
test_declar_scope_context:
- meta_scope: invalid.illegal.test2.test_declar_scope_context
- include: fallpop
test_declar_declarator_comma_context:
- match: '(?=,)'
set: [test_declar_declarator_comma_context, test_declar_declarator_context, punctuation_comma_context]
- include: fallpop
test_declar_declarator_context:
- match: '(?=\*)'
set: [test_declar_declarator_context, pointer_definition_context]
- match: '(?!{{invalid_identifier}})(?={{identifier}})'
set: [test_declar_after_declarator_context, test_declar_declarator_identifier_context]
- match: '(?=\()'
set: [parameter_after_declarator_context, test_declar_declarator_group_end_context, test_declar_declarator_context, test_declar_declarator_group_context_begin]
- include: fallpop
parameter_declarator_context:
- match: '(?=\*)'
set: [parameter_declarator_context, pointer_definition_context]
- match: '(?!{{invalid_identifier}})(?={{identifier}})'
set: [parameter_after_declarator_context, parameter_identifier_context]
- match: '(?=\()'
set: [parameter_after_declarator_context, test_declar_declarator_group_end_context, parameter_declarator_context, test_declar_declarator_group_context_begin]
- include: fallpop
parameter2_declarator_context:
- match: '(?=\*)'
set: [parameter2_declarator_context, pointer_definition_context]
- match: '(?!{{invalid_identifier}})(?={{identifier}})'
set: [parameter_after_declarator_context, parameter2_identifier_context]
- match: '(?=\()'
set: [parameter_after_declarator_context, test_declar_declarator_group_end_context, parameter2_declarator_context, test_declar_declarator_group_context_begin]
- include: fallpop
test_declar_after_declarator_context:
- include: assign_initializer_fragment
- match: '(?=\[)'
set: [test_declar_after_declarator_context, subscript_context]
- match: '(?=\()'
set: [parameter_after_declarator_context, parameter_group_context_end, parameter_list, parameter_group_context_begin]
- include: fallpop
parameter_after_declarator_context:
- include: assign_initializer_fragment
- match: '(?=\[)'
set: [parameter_after_declarator_context, subscript_context]
- match: '(?=\()'
set: [parameter_after_declarator_context, parameter_group_context_end, parameter2_list, parameter_group_context_begin]
- include: fallpop
test_declar_declarator_identifier_context:
- scope: entity.name.function
match: '{{identifier}}(?=\s*\()'
pop: true
- scope: meta.identifier.declarator
match: '{{identifier}}'
pop: true
parameter_identifier_context:
- scope: variable.parameter
match: '{{identifier}}'
pop: true
parameter2_identifier_context:
- scope: meta.variable.parameter
match: '{{identifier}}'
pop: true
test_declar_declarator_group_context_begin:
- scope: punctuation.section.group.begin
match: '\('
pop: true
test_declar_declarator_group_end_context:
- scope: punctuation.section.group.end
match: '\)'
pop: true
# - include: fallpop
pointer_definition_context:
- scope: storage.modifier.pointer
match: '\*'
pop: true
assign_initializer_fragment:
- scope: keyword.operator.assignment.initializer
match: '\='
set: test_initializer_expr_context
punctuation_comma_context:
- include: punctuation_commas
- include: fallpop
test_initializer_expr_context:
- match: '(?=\{)'
set: test_initializer_fragment
- include: test_expr_context
test_initializer_fragment:
- scope: punctuation.definition.initializer.begin
match: '\{'
set:
- scope: punctuation.definition.initializer.end
match: '\}'
pop: true
- include: expr_fallback
parameter_group_context_begin:
- scope: punctuation.section.parameters.begin
match: '\('
pop: true
parameter_group_context_end:
- scope: punctuation.section.parameters.end
match: '\)'
pop: true
parameter_comma_context:
- scope: punctuation.separator.parameter
match: ','
set: parameter_list
- include: fallpop
parameter_list:
- match: ''
set: [parameter_comma_context, parameter_declar_context]
parameter2_comma_context:
- scope: punctuation.separator.parameter2
match: ','
set: parameter2_list
- include: fallpop
parameter2_list:
- match: ''
set: [parameter2_comma_context, parameter2_declar_context]
# test specifier
test_specifier_context:
- include: test_specifier_fragment
- include: fallpop
test_specifier_fragment:
- match: '(?={{type_modifier}})'
set: [test_specifier_scope_context_modifier_start, type_basic_and_aggregate_context, type_modifier_context]
- match: '(?={{type_basic}}|{{struct_like}})'
set: [test_specifier_scope_context_type_start, type_basic_and_aggregate_context]
test_specifier_scope_context_modifier_start:
- meta_scope: meta.test_specifier_modifier
- include: fallpop
test_specifier_scope_context_type_start:
- meta_scope: meta.test_specifier_type
- include: fallpop
type_modifier_context:
- include: type_modifiers
- include: fallpop
# basic and aggregate
type_basic_and_aggregate_context:
- include: type_basic_fragment
- include: test_struct_like_fragment
- include: fallpop
type_basic_context:
- include: type_basic_fragment
- include: fallpop
type_basic_fragment:
- match: '(?={{type_basic}})'
set: [modifiers_after_type_basic_context, type_basic_fragment_content]
type_basic_fragment_content:
- include: basic_types
- include: fallpop
modifiers_after_type_basic_context:
- match: '(?=\b(?:{{_type_qualifiers}}|{{_compiler_directives}}|{{_type_modifiers}})\b)'
set: [type_basic_context, type_modifier_context]
- include: fallpop
# test struct like
test_struct_like_fragment:
- match: '(?={{struct_like}})'
set: [type_modifier_context, test_struct_like_keyword]
test_struct_like_keyword:
- scope: storage.type.struct
match: '\b(?:struct)\b'
set: test_struct_like_after_keyword
- scope: storage.type.union
match: '\b(?:union)\b'
set: test_struct_like_after_keyword
- include: fallpop
test_struct_like_after_keyword:
- scope: invalid.illegal.identifier
match: '{{identifier}}'
set: test_struct_like_after_tag
- include: test_struct_like_after_tag
test_struct_like_after_tag:
- match: '(?=\{)'
set: [test_struct_like_block_end, test_struct_like_block_content, test_struct_like_block_begin]
- include: fallpop
test_struct_like_block_begin:
- scope: punctuation.section.struct-like.begin
match: '\{'
pop: true
test_struct_like_block_end:
- scope: punctuation.section.struct-like.end
match: '\}'
pop: true
test_struct_like_block_content:
- include: test_declar
- include: punctuation_terminators
- include: fallpop
# util
fallback:
- scope: keyword.control
match: '\b(?:{{_control_keywords}})\b'
- include: basic_types
- include: aggregate_types
- scope: keyword.typedef
match: '\b(?:typedef)\b'
- include: type_modifiers
- include: expr_fallback
expr_fallback:
- scope: keyword.operator.word
match: '\b(?:{{_word_operators}})\b'
- include: expr_literals
- scope: punctuation
match: '[\(\)\[\]\{\}]'
- scope: punctuation.accessor
match: '\.|\->'
- include: punctuation_commas
- include: punctuation_terminators
- scope: keyword.operator
match: '[\+\-\*\/\%\^\&\|\~\=\<\>\!]'
expr_literals:
- include: strings
- include: numbers
- include: constants
basic_types:
- scope: storage.type.c
match: '{{type_basic}}'
aggregate_types:
- scope: storage.type.aggregate.c
match: '\b(?:{{_aggregate_types}})\b'
type_modifiers:
- scope: storage.modifier.storage.c
match: '\b(?:{{_storage_classes}})\b'
- scope: storage.modifier.qualifier.c
match: '\b(?:{{_type_qualifiers}})\b'
- scope: storage.modifier.directive.c
match: '\b(?:{{_compiler_directives}})\b'
punctuation_commas:
- scope: punctuation.delimiter
match: ','
punctuation_terminators:
- scope: punctuation.terminator
match: ';'
strings:
- include: scope:source.c11#strings
numbers:
- include: scope:source.c11#numbers
constants:
- include: scope:source.c11#constants
preprocessors:
- include: scope:source.c11#preprocessors
comments:
- include: scope:source.c11#comments
fallpop:
- match: '(?=\S)'
pop: true