-
Notifications
You must be signed in to change notification settings - Fork 0
/
C Next.sublime-syntax
573 lines (507 loc) · 16.4 KB
/
C Next.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
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
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: C Next
file_extensions:
- c
- h
first_line_match: '-[*]-( Mode:)? C -[*]-'
scope: source.c11
variables:
c90_keywords: 'auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while'
c99_keywords: '{{c90_keywords}}|inline|restrict|_Bool|_Complex|_Imaginary'
c11_keywords: '{{c99_keywords}}|_Alignas|_Alignof|_Atomic|_Generic|_Noreturn|_Static_assert|_Thread_local'
identifier: '\b[[:alpha:]_][[:alnum:]_]*\b'
identifier_lookahead: '(?=\b[[:alpha:]_])'
basic_types: 'void|char|short|int|long|float|double|signed|unsigned|_Bool|_Complex|_Imaginary'
int_types: 'u?int((_(least|fast))?(8|16|32|64)|max|ptr)_t|__int128|__u?int128_t|s?size_t|ptrdiff_t|wchar_t'
atomic_types: 'atomic_(?:bool|char(?:16_t|32_t)?|u?int(?:_(?:(?:(?:fast|least)(?:8|16|32|64))|max|ptr)_t)?|llong|long|ptrdiff_t|schar|short|size_t|uchar|ullong|ulong|ushort|wchar_t)'
known_types: '{{basic_types}}|{{int_types}}|{{atomic_types}}'
control_keywords: 'break|case|continue|default|do|else|for|goto|if|return|switch|while'
storage_classes: 'static|extern|auto|register|_Thread_local'
storage_classes_extended: 'thread_local'
type_qualifier: 'const|restrict|volatile|_Atomic'
function_specifiers: 'inline|_Noreturn'
compiler_directive: 'inline|__restrict__|__restrict|_Noreturn'
compiler_directive_extended: 'noreturn'
modifiers: '{{storage_classes}}|{{type_qualifier}}|{{compiler_directive}}'
preprocessors: 'if|ifdef|ifndef|else|endif|define|include|pragma|error|warning'
compiler_macros: '__asm__|__volatile__|__attribute__'
compiler_macros_extended: 'asm'
non_storage_keywords: 'auto|break|case|continue|default|do|else|for|goto|if|return|sizeof|switch|while|_Alignof|_Generic|_Static_assert|{{compiler_macros}}'
non_modifier_keywords: '{{non_storage_keywords}}|{{known_types}}'
struct_or_union: 'struct|union'
type_context_lookahead: '{{modifiers}}|{{known_types}}|{{struct_or_union}}|enum|_Atomic|_Alignas'
contexts:
# prototypes
prototype:
- include: comments
main:
- include: global
global:
- include: preprocessors
- include: typedef_declaration
- include: non_storage_keywords
- include: strong_declaration
- include: statement_group
- include: expressions
- scope: punctuation.terminator
match: ';'
- scope: punctuation.unmatched
match: '\}'
# preprocessors
preprocessors:
- scope: punctuation.preprocessor.c
match: '^\s*#'
with_prototype:
- include: inline_escape
push:
- scope: meta.preprocessor.incomplete.c
match: '\bi(nc?)?\b'
- scope: keyword.control.import.include.c
match: \b(include)\b
set:
- meta_scope: meta.preprocessor.c
- scope: punctuation.definition.string.begin.c
match: '"'
set: string_content
with_prototype:
- scope: punctuation.definition.string.end.c
match: '"'
pop: true
- scope: punctuation.definition.string.begin.c
match: '<'
set: string_content
with_prototype:
- scope: punctuation.definition.string.end.c
match: '>'
pop: true
- scope: keyword.control.import.define.c
match: \b(define)\b
set: [preprocessor_expressions, after_macro_define, define_identifier]
- scope: keyword.control.import.other.c
match: \b({{preprocessors}})\b
set:
- meta_scope: meta.preprocessor.c
# modules
statements:
- include: typedef_declaration
- include: declaration
- scope: storage.modifier
match: '\b(?:{{modifiers}})\b'
- scope: keyword
match: '\b(?:{{control_keywords}})\b'
- include: expressions
statement_group:
- scope: punctuation.section.block.begin
match: '\{'
push:
- scope: punctuation.section.block.end
match: '\}'
pop: true
- include: statement_group
- include: preprocessors
- include: statements
expressions:
- include: punctuations
- scope: keyword.operator
match: '[+\-*/=!%\^&|:?><~]'
- include: types
- scope: keyword.operator.word.c
match: '\b(?:sizeof)\b'
- scope: keyword.other
match: '\b(?:{{c11_keywords}}|{{compiler_macros}})\b'
- include: constants
- include: strings
- include: numbers
- match: '(?={{identifier}}\s*\()'
push:
- include: scope:source.c#c99
- scope: variable.function
match: '{{identifier}}'
- include: easy_pop
punctuations:
- scope: punctuation.statement-group
match: '[\{\}]'
- scope: punctuation.subscript
match: '[\[\]]'
- scope: punctuation.delimiter.comma
match: '[,]'
- scope: punctuation.terminator
match: '[;]'
- scope: punctuation.accessor
match: '[\.]'
- scope: punctuation
match: '[,;.]'
- scope: punctuation
match: '->|<:|:>|<%|%>'
- scope: punctuation.section.arguments.begin
match: '\('
push:
- scope: punctuation.section.arguments.end
match: '\)'
pop: true
- include: expressions
- scope: meta.identifier
match: '{{identifier}}'
- include: easy_pop
strings:
- include: scope:source.c#strings
numbers:
- include: scope:source.c#numbers
constants:
- scope: constant.language.c
match: \b(NULL|TRUE|FALSE|EOF)\b
non_storage_keywords:
- scope: keyword.other
match: '\b(?:{{non_storage_keywords}})\b'
comments:
- scope: comment.block.c
match: ^/\* =(\s*.*?)\s*= \*/$\n?
captures:
1: meta.toc-list.banner.block.c
- scope: punctuation.definition.comment.c
match: /\*
push:
- meta_scope: comment.block.c
- scope: punctuation.definition.comment.c
match: \*/
pop: true
- scope: invalid.illegal.stray-comment-end.c
match: \*/(?!\*)
- scope: comment.line.banner.c
match: ^// =(\s*.*?)\s*=\s*$\n?
captures:
1: meta.toc-list.banner.line.c
- scope: punctuation.definition.comment.c
match: //
push:
- meta_scope: comment.line.double-slash.c
- match: '(\\)$\n'
captures:
1: punctuation.separator.continuation.c
- match: (?=\n)
pop: true
declaration:
- match: '(?=\b({{type_context_lookahead}})\b)'
push: [declarator_comma, after_declarator, declarator_context, type_context]
strong_declaration:
- match: '{{identifier_lookahead}}'
push: [declarator_comma, after_declarator, declarator_context, type_context]
typedef_declaration:
- scope: keyword
match: '\b(typedef)\b'
push: [typedef_declarator_comma, after_declarator, typedef_declarator_context, type_context]
types:
- match: '(?=\b({{type_context_lookahead}})\b)'
push: type_context
# components
string_content:
- meta_scope: string
- meta_include_prototype: false
preprocessor_expressions:
- meta_scope: meta.preprocessor.macro.c
- include: statements
std_types:
- scope: keyword.atomic
match: '\b(?:_Atomic(?=\s*\())\b'
set: [after_type_specifier, expression_group]
- scope: keyword.modifiers
match: '\b(?:{{modifiers}})\b'
- scope: storage.type
match: '\b(?:{{known_types}})\b'
set: after_type_specifier
- scope: storage.type
match: '\b(?:{{struct_or_union}})\b'
set: [after_type_specifier, structlike_block, structlike_tag]
- scope: storage.type
match: '\b(?:enum)\b'
set: [after_type_specifier, enum_block, enum_tag]
- include: alignas_specifier
alignas_specifier:
- scope: keyword.alignas
match: '\b(?:_Alignas|alignas)\b'
push: [after_type_specifier, expression_group]
type_modifiers:
- scope: storage
match: '\*'
- scope: keyword
match: '\b(?:{{modifiers}})\b'
expression_group:
- scope: punctuation.section.group.begin
match: '\('
push: expression_group_context
- include: easy_pop
parameter_group:
- scope: punctuation.section.parameters.begin
match: '\((?=.+\)\s*;)'
set: param_context
- scope: punctuation.section.parameters.begin
match: '\('
set: universal_param_context
- include: easy_pop
simple_parameter_group:
- scope: punctuation.section.parameters.begin
match: '\('
set: simple_param_context
- include: easy_pop
structlike_tag:
- match: '(?={{c11_keywords}})'
pop: true
- scope: meta.tag
match: '{{identifier}}(?=\s*[^\s\{])'
pop: true
- scope: entity.name.struct
match: '{{identifier}}'
pop: true
- include: easy_pop
enum_tag:
- match: '(?={{c11_keywords}})'
pop: true
- scope: meta.tag
match: '{{identifier}}(?=\s*[^\s\{])'
pop: true
- scope: entity.name.enum
match: '{{identifier}}'
pop: true
- include: easy_pop
structlike_block:
- scope: punctuation.begin
match: '\{'
set:
- scope: punctuation.end
match: '\}'
pop: true
- include: strong_declaration
- scope: punctuation.terminator
match: ';'
- include: easy_pop
enum_block:
- scope: punctuation.begin
match: '\{'
set:
- scope: punctuation.end
match: '\}'
pop: true
- scope: keyword.operator
match: '='
- include: expressions
- scope: punctuation.separator
match: ','
- include: easy_pop
easy_pop:
- match: '(?=\S)'
pop: true
keyword_pop:
- match: '(?=\b(?:{{non_storage_keywords}})\b)'
pop: true
strict_keyword_pop:
- match: '(?=\b(?:{{non_modifier_keywords}})\b)'
pop: true
# contexts
# types
type_context:
- include: std_types
- include: keyword_pop
- scope: meta.storage
match: '{{identifier}}(?!\s*[,;\)=])'
set: after_type_specifier
- include: easy_pop
strong_type_context:
- include: std_types
- include: keyword_pop
- scope: meta.storage.maybe
match: '{{identifier}}'
set: after_type_specifier
- include: easy_pop
after_type_specifier:
- include: alignas_specifier
- include: type_modifiers
- scope: storage.type
match: '\b(?:{{basic_types}})\b'
- include: easy_pop
declarator_context:
- include: strict_keyword_pop
- match: '{{identifier}}(?=\s*\()'
scope: entity.name.function
set: after_function_declarator
- match: '{{identifier}}'
scope: entity.name.variable
pop: true
- scope: punctuation.declarator
match: '\('
set: [after_declarator, declarator_parentheses_context]
- include: easy_pop
typedef_declarator_context:
- include: keyword_pop
- scope: entity.name.type
match: '{{identifier}}'
pop: true
- scope: punctuation.declarator
match: '\('
set: [after_declarator, typedef_declarator_parentheses_context]
- include: easy_pop
param_declarator_context:
- scope: variable.parameter
match: '{{identifier}}'
pop: true
- scope: punctuation.declarator
match: '\('
set: [after_declarator, param_declarator_parentheses_context]
- include: easy_pop
param_declarator_context_fake:
- scope: variable.fake_parameter
match: '{{identifier}}'
pop: true
- scope: punctuation.declarator
match: '\('
set: [after_declarator, param_declarator_parentheses_context]
- include: easy_pop
declarator_parentheses_context:
- include: type_modifiers
- scope: punctuation.declarator
match: '\)'
pop: true
- scope: punctuation.declarator
match: '\('
push: [after_declarator, declarator_parentheses_context]
- include: strict_keyword_pop
- match: '{{identifier}}(?=\s*\()'
scope: entity.name.function
push: [after_declarator, after_function_declarator]
- match: '{{identifier}}'
scope: entity.name
push: after_declarator
- match: '(?=\S)'
set: expression_group_context
typedef_declarator_parentheses_context:
- include: type_modifiers
- scope: punctuation.declarator
match: '\)'
pop: true
- scope: punctuation.declarator
match: '\('
push: [after_declarator, typedef_declarator_parentheses_context]
- scope: entity.name.type
match: '{{identifier}}'
push: after_declarator
param_declarator_parentheses_context:
- include: type_modifiers
- scope: punctuation.declarator
match: '\)'
pop: true
- scope: punctuation.declarator
match: '\('
push: [after_declarator, param_declarator_parentheses_context]
- scope: variable.parameter
match: '{{identifier}}'
push: after_declarator
- match: '(?=\S)'
set: expression_group_context
after_declarator:
- scope: punctuation.section
match: '\['
set: [after_declarator, bracket_context]
- scope: punctuation.section.parameters.begin
match: '\('
set: [after_declarator, simple_param_context]
- include: easy_pop
after_function_declarator:
- scope: punctuation.section.parameters.begin
match: '\((?=[\s[:alnum:]_,\*\/]+(\)[\s\*\/]*([[:alnum:]_]|\{|$)|$))'
set: [after_declarator, universal_param_context]
- scope: punctuation.section.parameters.begin
match: '\(' # match: '\((?=.*[^\s[:alnum:]_,].*\)[^\{]*(\{|$))'
set: [after_declarator, param_context]
- include: easy_pop
bracket_context:
- scope: punctuation.end
match: '\]'
pop: true
- scope: punctuation.begin
match: '\['
push: bracket_context
- include: expressions
expression_group_context:
- scope: punctuation.end
match: '\)'
pop: true
- scope: punctuation.begin
match: '\('
push: expression_group_context
- include: expressions
declarator_comma:
- scope: punctuation.delimiter.comma
match: ','
set: [declarator_comma, after_declarator, declarator_context]
- include: easy_pop
typedef_declarator_comma:
- scope: punctuation.delimiter.comma
match: ','
set: [typedef_declarator_comma, after_declarator, typedef_declarator_context]
- include: easy_pop
param_context:
- meta_scope: meta.param
- scope: keyword.punctuation
match: '\.\.\.'
- scope: punctuation.separator
match: ','
- scope: punctuation.section.parameters.end
match: '\)'
pop: true
- match: '{{identifier_lookahead}}'
set: [param_context, after_declarator, param_declarator_context, strong_type_context]
universal_param_context:
- meta_scope: meta.param.universal
- scope: punctuation.delimiter.comma
match: ','
- scope: punctuation.section.parameters.end
match: '\)'
pop: true
- match: '(?=\b({{type_context_lookahead}})\b)'
set: [param_context, after_declarator, param_declarator_context, strong_type_context]
- match: '(?={{identifier}}\s*[\*[:alnum:]])'
set: [param_context, after_declarator, param_declarator_context, strong_type_context]
- scope: variable.parameter
match: '{{identifier}}'
simple_param_context:
- meta_scope: meta.param
- scope: punctuation.delimiter.comma
match: ','
- scope: punctuation
match: '\)'
pop: true
- match: '{{identifier_lookahead}}'
set: [simple_param_context, after_declarator, param_declarator_context_fake, strong_type_context]
# preprocessors
inline_escape:
- scope: punctuation.separator.continuation.c
match: '\\\n'
- match: '(?=\n)'
pop: true
macro_parameter_group:
- scope: punctuation.definition.group.begin.c
match: '\('
with_prototype:
- scope: punctuation.definition.group.end.c
match: '\)'
pop: true
set: macro_param_content
macro_param_content:
- scope: punctuation.delimiter.comma
match: ','
- scope: variable.parameter
match: '{{identifier}}'
define_identifier:
- match: '{{identifier}}(?=\()'
scope: entity.name.function.preprocessor.c
pop: true
- match: '{{identifier}}'
scope: entity.name.constant.preprocessor.c
pop: true
- include: easy_pop
after_macro_define:
- match: '(?=\()'
set: macro_parameter_group
- match: '\s+'
pop: true