-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.sublime-syntax
191 lines (162 loc) · 5.95 KB
/
C.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
%YAML 1.2
---
# Author: Wojciech Bogócki
# Date: Dec 7 2019
# Repository: https://github.com/wbogocki/Simple-C-Syntax-for-Sublime-Text-3
name: C (Simple)
file_extensions: [c, h]
scope: source.c
variables:
identifiers: '[A-Za-z_][A-Za-z_0-9]*'
integer_literal_suffixes: 'u|U|l|L|ll|LL'
builtin_constants: 'NULL|true|false|__func__'
builtin_macros: '__STDC__|__STDC_VERSION__|__STDC_HOSTED__|__FILE__|__LINE__|__DATE__|__TIME__|__STDC_ISO_10646__|__STDC_IEC_559__|__STDC_IEC_559_COMPLEX__|__STDC_UTF_16__|__STDC_UTF_32__|__STDC_MB_MIGHT_NEQ_WC__|__STDC_ANALYZABLE__|__STDC_LIB_EXT1__|__STDC_NO_ATOMICS__|__STDC_NO_COMPLEX__|__STDC_NO_THREADS__|__STDC_NO_VLA__|__VA_ARG__'
control: 'if|else|for|while|do|switch|goto|break|continue|case|default|return'
operators: '\=|\+|\-|\*|\/|\%|\^|\!|~|\&|\%|\||\.|\<|\>|\?'
types: 'void|int|short|long|float|double|char|_Bool|bool|signed|unsigned|size_t|ptrdiff_t'
types_stdint: 'int8_t|int16_t|int32_t|int64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|intmax_t|intptr_t|uint8_t|uint16_t|uint32_t|uint64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|uintmax_t|uintmax_t'
types_struct: 'struct|enum|union'
types_my: 'i8|i16|i32|i64|isz|u8|u16|u32|u64|usz'
modifiers: 'const|auto|static|inline|extern|register|restrict|volatile|_Complex|complex|_Imaginary|imaginary|_Atomic|_Thread_local|thread_local|_Noreturn|noreturn'
contexts:
# We are in the global scope, any function-like thing here must be a declaration! Yay!
global_scope:
# Function declarations
- match: \b({{identifiers}})\s*(?=\()
scope: entity.name.function
# We are inside of something, goooooood! Now I can safely colour function calls! Ha!
local_scope:
# Function calls
- match: \b({{identifiers}})\s*(?=\()
scope: entity.name.function meta.function-call support.function
basic:
# Macros: include
- match: ^\s*(#\s*include)\s*((\<.*\>)|(\".*\"))$
captures:
1: keyword.other
2: string.quoted.other
# Macros: define
- match: ^\s*(#\s*define)\s*\b({{identifiers}})\b
captures:
1: keyword.other
2: entity.name.macro
push:
- match: (?<!\\)\n
pop: true
- include: basic
- include: local_scope
# Macros: if/ifdef/ifndef
- match: ^\s*#\s*\b(if|ifdef|ifndef)\b
scope: keyword.other
push:
- match: \bdefined\b
scope: keyword.other
- match: (?<!\\)\n
pop: true
- include: basic
- include: local_scope
# Macros: other
- match: ^\s*#\s*\b(undef|else|elif|endif|line|error|pragma)\b
scope: keyword.other
push:
- match: (?<!\\)\n
pop: true
- include: basic
- include: local_scope
# Block comments
- match: \/\*
push:
- match: \*\/
pop: true
- meta_scope: comment.block
# Line comments
- match: //.*
scope: comment.line
# Constants & macros
- match: \b({{builtin_constants}}|{{builtin_macros}})\b
scope: constant.language
# Int literals: decimal
- match: (?i)\b[1-9][0-9]*u?(l|ll)?\b
scope: constant.numeric.integer
# Int literals: octal
- match: (?i)\b0[0-7]*u?(l|ll)?\b
scope: constant.numeric.integer
# Int literals: hexadecimal
- match: (?i)\b0x[0-9A-F]+u?(l|ll)?\b
scope: constant.numeric.integer
# Float literals: decimal
- match: (?i)[\b^\.]([1-9][0-9]*)?((?<=\.)[0-9]+)?((?<![\b^\.])e[0-9]+)?(l|f)?\b
scope: constant.numeric.float
# Float literals: hexadecimal
- match: (?i)[\b^\.](0x[0-9A-F]+)?((?<=\.)[0-9A-F]+)?((?<![\b^\.])p[0-9A-F]+)?(l|f)?\b
scope: constant.numeric.float
# String literals
- match: \"
push:
- match: \\(?:\\|[abefnrtv\'"?]|[0-3][0-9]{0,2}|[4-7][0-9]?|x[a-fA-F0-9]+|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8})
scope: constant.character.escape
- match: \\.
scope: invalid.illegal
- match: |-
(?x)%
(\d+\$)? # field (argument #)
[#0\- +']* # flags
[,;:_]? # separator character (AltiVec)
((-?\d+)|\*(-?\d+\$)?)? # minimum field width
(\.((-?\d+)|\*(-?\d+\$)?)?)? # precision
(hh|h|ll|l|j|t|z|q|L|vh|vl|v|hv|hl)? # length modifier
(\[[^\]]+\]|[am]s|[diouxXDOUeEfFgGaACcSspn%]) # conversion type
scope: constant.other.placeholder
- match: (?<!\\)\"
pop: true
- meta_scope: string.quoted.double
# Character literals
- match: \'
push:
- match: \\.
scope: constant.character.escape
- match: \'
pop: true
- meta_scope: string.quoted.single
# String & character literal prefixes
- match: \b(L|u8|u|U)\b\s*(?=(\'|\"))
scope: storage.type
# Control
- match: \b({{control}})\b
scope: keyword.control
# Operators
- match: ({{operators}})
scope: keyword.operator
# Sizeof operator
- match: \bsizeof\b
scope: keyword.operator.word
# Typedef operator
- match: \btypedef\b
scope: storage.type
# Types
- match: \b({{types}}|{{types_stdint}}|{{types_struct}}|{{types_my}})\b
scope: storage.type
# Modifiers
- match: \b({{modifiers}})\b
scope: storage.modifier
# Brackets
- match: \(
push:
- match: \)
pop: true
- include: basic
- include: local_scope
- match: \)
scope: invalid.illegal
# Scopes
- match: \{
push:
- match: \}
pop: true
- include: basic
- include: local_scope
- match: \}
scope: invalid.illegal
main:
- include: basic
- include: global_scope