Ticket #4556: c.syntax

File c.syntax, 9.6 KB (added by MorthimerMcMare, 3 months ago)

"/misc/syntax/c.syntax"

Line 
1# Syntax rules for the C (and partially C++) programming languages.
2
3#
4# Rewritten and extended with defines by Morthimer McMare
5#    <mailto:morthimer_second@list.ru>
6#
7# Tab size: 4.
8# Feel free to improve the highlighting file.
9#
10# Date:
11#   Initial 2024.04.24;
12#   Updated 2024.06.26 (first public release. Classic Midnight Commander C-syntax theme set by default, added keywords from the C23 standard).
13#
14
15
16# For the default (blue) background.
17# The colors almost match the original "c.syntax" file, slightly extending it:
18define _punctuation             yellow
19define _punct_operator  brightcyan
20define _punct_semicolon brightmagenta
21define _punct_bracket   brightcyan
22define _punct_sqbracket brightcyan
23define _punct_field             yellow
24define _punct_comma             brightcyan
25define _punct_ternary   brightcyan
26define _punct_bitwise   brightmagenta
27define _label                   cyan
28define _preproc                 brightred
29define _preproc_str             red
30define _preproc_nl_esc  red
31define _preproc_indent  brightmagenta
32define _keyword                 yellow
33define _datatype                yellow
34define _datatype_void   yellow
35define _datatype_mod    yellow
36define _datatype_scope  yellow
37define _const                   lightgray
38define _num_integer             lightgray
39define _num_hex                 lightgray
40define _num_oct                 lightgray
41define _num_float               lightgray
42define _string                  green
43define _string_specsymb brightgreen
44define _string_escchar  brightgreen
45define _char                    brightgreen
46define _comment                 brown
47define _comment_word    black brown
48define _comment_exmark  black yellow
49define _comment_qnmark  black brown
50
51# I think this highlighting is easier for the eyes for the black background themes. Can be also used with the blue background:
52#define _punctuation            yellow
53#define _punct_operator         brightmagenta
54#define _punct_semicolon        brightmagenta
55#define _punct_bracket          yellow
56#define _punct_sqbracket        brown
57#define _punct_field            yellow
58#define _punct_comma            yellow
59#define _punct_ternary          white
60#define _punct_bitwise          yellow
61#define _label                  brightcyan
62#define _preproc                        lightgray
63#define _preproc_str            white
64#define _preproc_nl_esc         white
65#define _preproc_indent         lightgray
66#define _keyword                        brightcyan
67#define _datatype               brightcyan
68#define _datatype_void          brightcyan
69#define _datatype_mod           brightcyan
70#define _datatype_scope         brightblue
71#define _const                  lightgray
72#define _num_integer            red
73#define _num_hex                        red
74#define _num_oct                        red
75#define _num_float              magenta
76#define _string                 brightgreen
77#define _string_specsymb        brightcyan
78#define _string_escchar         brightcyan
79#define _char                   brightgreen
80#define _comment                        gray
81#define _comment_word           black gray
82#define _comment_exmark         black yellow
83#define _comment_qnmark         black brown
84
85
86context default
87    keyword whole asm _keyword
88    keyword whole break _keyword
89    keyword whole case _keyword
90    keyword whole const _keyword
91    keyword whole continue _keyword
92    keyword whole do _keyword
93    keyword whole else _keyword
94    keyword whole enum _keyword
95    keyword whole for _keyword
96    keyword whole goto _keyword
97    keyword whole if _keyword
98    keyword whole inline _keyword
99    keyword whole restrict _keyword
100    keyword whole return _keyword
101    keyword whole sizeof _keyword
102    keyword whole struct _keyword
103    keyword whole switch _keyword
104    keyword whole typedef _keyword
105    keyword whole union _keyword
106    keyword whole volatile _keyword
107    keyword whole while _keyword
108
109    # C11/C23 extensions:
110    keyword whole alignas _keyword
111    keyword whole alignof _keyword
112    keyword whole constexpr _keyword
113    keyword whole typeof _keyword
114    keyword whole typeof_unqual _keyword
115    keyword whole static_assert _keyword
116    keyword whole thread_local _keyword
117    keyword whole _Alignas _keyword
118    keyword whole _Alignof _keyword
119    keyword whole _Atomic _keyword
120    keyword whole _Bool _keyword
121    keyword whole _Complex _keyword
122    keyword whole _Decimal32 _keyword
123    keyword whole _Decimal64 _keyword
124    keyword whole _Decimal128 _keyword
125    keyword whole _Generic _keyword
126    keyword whole _Imaginary _keyword
127    keyword whole _Noreturn _keyword
128    keyword whole _Static_assert _keyword
129    keyword whole _Thread_local _keyword
130
131    keyword whole auto _datatype_scope
132    keyword whole extern _datatype_scope
133    keyword whole register _datatype_scope
134    keyword whole static _datatype_scope
135
136    keyword whole void _datatype_void
137    keyword whole int _datatype
138    keyword whole char _datatype
139    keyword whole float _datatype
140    keyword whole double _datatype
141    keyword whole wchar_t _datatype
142    keyword whole short _datatype_mod
143    keyword whole long _datatype_mod
144    keyword whole signed _datatype_mod
145    keyword whole unsigned _datatype_mod
146    keyword whole wchar_t _datatype
147    keyword whole ... _keyword
148
149    keyword NULL _const
150    # Since C23:
151    keyword true _const
152    keyword false _const
153    keyword nullptr _const
154
155    keyword linestart \{\s\t\}\[\s\t\]#*\n _preproc_indent
156    keyword whole linestart \[\s\t\]\{ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz\}\[0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz\]: _label
157    keyword whole \[\s\t\]default _keyword
158
159    # Comments:
160    keyword /\* _comment
161    keyword \*/ _comment
162    keyword // _comment
163
164    # Characters:
165    keyword '\\\{"abtnvfr\}' _char
166    keyword '\\\{0123\}\{01234567\}\{01234567\}' _char
167    keyword '\\'' _char
168    keyword '\\\\' _char
169    keyword '\\0' _char
170    keyword '\{\s!"#$%&()\*\+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ\}' _char
171
172    # Punctuation characters, sorted by ASCII code:
173    keyword ! _punctuation
174    keyword % _punctuation
175    keyword && _punctuation
176    # Note: the '&' symbol uses both in the reference/address and in the bitwise operation.
177    keyword & _punct_bitwise
178    keyword ( _punct_bracket
179    keyword ) _punct_bracket
180    keyword \* _punctuation
181    keyword \+ _punctuation
182    keyword , _punct_comma
183    keyword . _punct_field
184    keyword -> _punct_field
185    keyword - _punctuation
186    keyword / _punctuation
187    keyword : _punct_ternary
188    keyword ; _punct_semicolon
189    keyword < _punctuation
190    keyword = _punctuation
191    keyword > _punctuation
192    keyword ? _punct_ternary
193    keyword [ _punct_sqbracket
194    keyword ] _punct_sqbracket
195    keyword ^ _punct_bitwise
196    keyword { _punct_operator
197    keyword || _punctuation
198    keyword | _punct_bitwise
199    keyword } _punct_operator
200    keyword ~ _punct_bitwise
201
202    # Numbers:
203    wholechars abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.
204
205    keyword whole 0x\{0123456789abcdefABCDEF_\}\[0123456789abcdefABCDEF_\] _num_hex
206    keyword whole 0\{01234567_\}\[01234567_\] _num_oct
207    keyword whole 0 _num_integer
208    keyword whole 0\{lu\} _num_integer
209    keyword whole \{123456789_\}\[0123456789_\] _num_integer
210    keyword whole \{123456789_\}\[0123456789_\]\{lu\} _num_integer
211    # Float-point values:
212    keyword whole \[0123456789_\]\.\{0123456789_\}\[0123456789_\] _num_float
213    keyword whole \{0123456789_\}\[0123456789_\]\.\[0123456789_\] _num_float
214    keyword whole \{0123456789_\}\[0123456789_\]\{eE\}\{0123456789_\}\[0123456789_\] _num_float
215    keyword whole \{0123456789_\}\[0123456789_\]\{eE\}\{\-\+\}\{0123456789_\}\[0123456789_\] _num_float
216    keyword whole \{0123456789_\}\[0123456789_\]\.\{0123456789_\}\[0123456789_\]\{eE\}\{0123456789_\}\[0123456789_\] _num_float
217    keyword whole \{0123456789_\}\[0123456789_\]\.\{0123456789_\}\[0123456789_\]\{eE\}\{\-\+\}\{0123456789_\}\[0123456789_\] _num_float
218    # Explicit float (not double):
219    keyword whole \[0123456789_\]\.\{0123456789_\}\[0123456789_\]f _num_float
220    keyword whole \{0123456789_\}\[0123456789_\]\.\[0123456789_\]f _num_float
221    keyword whole \{0123456789_\}\[0123456789_\]\{eE\}\{0123456789_\}\[0123456789_\]f _num_float
222    keyword whole \{0123456789_\}\[0123456789_\]\{eE\}\{\-\+\}\{0123456789_\}\[0123456789_\]f _num_float
223    keyword whole \{0123456789_\}\[0123456789_\]\.\{0123456789_\}\[0123456789_\]\{eE\}\{0123456789_\}\[0123456789_\]f _num_float
224    keyword whole \{0123456789_\}\[0123456789_\]\.\{0123456789_\}\[0123456789_\]\{eE\}\{\-\+\}\{0123456789_\}\[0123456789_\]f _num_float
225
226
227context exclusive /\* \*/ _comment
228    keyword whole BUG   _comment_word
229    keyword whole FixMe _comment_word
230    keyword whole FIXME _comment_word
231    keyword whole Note  _comment_word
232    keyword whole NOTE  _comment_word
233    keyword whole ToDo  _comment_word
234    keyword whole TODO  _comment_word
235    keyword !!\[!\]     _comment_exmark
236    keyword ??\[?\]     _comment_qnmark
237    spellcheck
238
239context exclusive // \n _comment
240    keyword whole BUG:          _comment_word
241    keyword whole FixMe:        _comment_word
242    keyword whole FIXME:        _comment_word
243    keyword whole Note:         _comment_word
244    keyword whole NOTE:         _comment_word
245    keyword whole ToDo:         _comment_word
246    keyword whole TODO:         _comment_word
247    keyword !!\[!\]             _comment_exmark
248    keyword ??\[?\]             _comment_qnmark
249    spellcheck
250
251context linestart # \n _preproc
252    keyword \\\n _preproc_nl_esc
253    keyword /\**\*/ _comment
254    keyword //*\n _comment
255    keyword "+" _preproc_str
256    keyword <+> _preproc_str
257
258context " " _string
259    spellcheck
260    keyword \\" _string_escchar
261    keyword %% _string_specsymb
262    keyword %\[#0\s-\+,\]\[0123456789\*\]\[.\]\[0123456789\*\]\[L\]\{eEfgGoxX\} _string_specsymb
263    keyword %\[0\s-\+,\]\[0123456789\*\]\[.\]\[0123456789\*\]\[hl\]\{diuxX\} _string_specsymb
264    keyword %\[hl\]n _string_specsymb
265    keyword %\[-\]\[0123456789\*\]\[.\]\[0123456789\*\]s _string_specsymb
266    keyword %[*] _string_specsymb
267    keyword %c _string_specsymb
268    keyword %p _string_specsymb
269    keyword \\\{0123\}\{01234567\}\{01234567\} _string_specsymb
270    keyword \\\\ _string_escchar
271    keyword \\' _string_escchar
272    keyword \\\{abtnvfr\} _string_escchar