File: lang-tutorial.xml

package info (click to toggle)
libgedit-gtksourceview 299.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 7,536 kB
  • sloc: ansic: 48,501; xml: 2,620; perl: 206; sh: 51; yacc: 45; makefile: 35; cobol: 20; objc: 19; javascript: 16; fortran: 14; python: 13; cpp: 8; ml: 3
file content (736 lines) | stat: -rw-r--r-- 23,293 bytes parent folder | download
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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
   "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
[
 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
 <!ENTITY % gtkdocentities SYSTEM "xml/gtkdocentities.ent">
 %gtkdocentities;
]>
<refentry id="lang-tutorial">
<refmeta>
<refentrytitle>Language Definition v2.0 Tutorial</refentrytitle>
</refmeta>

<refnamediv>
<refname>Language Definition v2.0 Tutorial</refname>
<refpurpose>
Guide to the libgedit-gtksourceview language definition file format
</refpurpose>
</refnamediv>

<refsect1 id="tutorial">
<title>A language definition for the C language</title>

<note>
  <para>
    The version 2 here refers to the language definition file format,
    not to the version of libgedit-gtksourceview.
  </para>
</note>

<para>
To describe the syntax of a language libgedit-gtksourceview uses an XML format
which defines nested context to be highlighted. Each context roughly corresponds
to a portion of the syntax which has to be highlighted (e.g. keywords, strings,
comments), and can contain nested contexts (e.g. escaped characters.)
</para>

<para>
In this tutorial we will analyze a simple example to highlight a subset of
C, based on the full C language definition.
</para>

<para>
Like every well formed XML document, the language description starts with a
XML declaration:
</para>

<programlisting>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
</programlisting>

<para>
After the usual preamble, the main tag is the <code>&lt;language&gt;</code> element:
</para>

<programlisting>
&lt;language id="c" name="C" version="2.0" _section="Source"&gt;
</programlisting>

<para>
The attribute <code>id</code> is used in external references and defines a standard
way to refer to this language definition, while the <code>name</code> attribute is
the name presented to the user.
</para>

<para>
The attribute <code>section</code> (it is translatable using gettext prepending
a <code>_</code>), tells the category where this language should be grouped when
it is presented to the user. Currently available categories in
libgedit-gtksourceview are "Source", "Script", "Markup", "Scientific" and
"Other".
</para>

<para>
The attribute <code>version</code> specifies the version of the xml syntax
used in your language definition file, so it should always be <code>2.0</code>.
</para>

<para>
The <code>&lt;language&gt;</code> element contains three sections:
<code>&lt;metadata&gt;</code>, <code>&lt;styles&gt;</code> and
<code>&lt;definitions&gt;</code>
</para>

<programlisting>
&lt;metadata&gt;
</programlisting>

<para>
The <code>&lt;metadata&gt;</code> element is optional and provides a collection
of properties which specify arbitrary information about the language definition
file itself. It is particularly important to specify the conventional
<code>mimetypes</code> and <code>globs</code> properties that
libgedit-gtksourceview uses to automatically detect which syntax highlighting to
use for a given file. They respectively contain a semi-colon separated list of
mimetypes and filename extensions.
</para>

<programlisting>
&lt;metadata&gt;
  &lt;property name="mimetypes"&gt;text/x-c;text/x-csrc&lt;/property&gt;
  &lt;property name="globs"&gt;*.c&lt;/property&gt;
&lt;/metadata&gt;
</programlisting>

<programlisting>
&lt;styles&gt;
</programlisting>

<para>
This element contains every association between the styles used in the
description and the defaults stored internally in libgedit-gtksourceview.
For each style there is a <code>&lt;style&gt;</code> element:
</para>

<programlisting>
&lt;style id="comment" name="Comment" map-to="def:comment"/&gt;
</programlisting>

<para>
This defines a <code>comment</code> style, which inherits the font
properties from the defaults style <code>def:comment</code>.
The <code>name</code> attribute is the name to show to the user (that string
could for example be used by a GUI tool to edit or create style schemes).
</para>

<para>
For each style used in the language definition there is a corresponding
<code>&lt;style&gt;</code> element; every style can be used in different
contexts, so they will share the same appearance.
</para>

<programlisting>
&lt;style id="string" name="String" map-to="def:string"/&gt;
&lt;style id="escaped-character" name="Escaped Character" map-to="def:special-char"/&gt;
&lt;style id="preprocessor" name="Preprocessor" map-to="def:preprocessor"/&gt;
&lt;style id="included-file" name="Included File" map-to="def:string"/&gt;
&lt;style id="char" name="Character" map-to="def:character"/&gt;
&lt;style id="keyword" name="Keyword" map-to="def:keyword"/&gt;
&lt;style id="type" name="Data Type" map-to="def:type"/&gt;
</programlisting>

<para>
Following the <code>&lt;styles&gt;</code> element there is the
<code>&lt;definitions&gt;</code> element, which contains the
description proper of the syntax:
</para>

<programlisting>
&lt;definitions&gt;
</programlisting>

<para>
Here we should define a main context, the one we enter at the beginning of
the file: to do so we use the <code>&lt;context&gt;</code> tag, with an
<code>id</code> equal to the <code>id</code> of the
<code>&lt;language&gt;</code> element:
</para>

<programlisting>
&lt;context id="c"&gt;
</programlisting>

<para>
The element <code>&lt;include&gt;</code> contains the list of sub-contexts
for the current context: as we are in the main context we should put here
the top level contexts for the C language:
</para>

<programlisting>
&lt;include&gt;
</programlisting>

<para>
The first context defined is the one for single-line C style comments: they
start with a double slash <code>//</code> and end at the end of the line:
</para>

<programlisting>
&lt;context id="comment" style-ref="comment"&gt;
  &lt;start&gt;\/\/&lt;/start&gt;
  &lt;end&gt;$&lt;/end&gt;
&lt;/context&gt;
</programlisting>

<para>
The <code>&lt;start&gt;</code> element contains the regular expression telling
the highlighting engine to enter in the defined context, until the terminating
regular expression contained in the <code>&lt;end&gt;</code> element is found.
</para>

<para>
Those regular expressions are PCRE regular expressions in the form
<code>/regex/options</code> (see the documentation of PCRE for details.) If
there are no options to be specified and you don't need to match the spaces at
the start and at the end of the regular expression, you can omit the slashes,
putting here only <code>regex</code>.
</para>

<para>
The possible options are:
</para>

<itemizedlist>
<listitem><para>
    <code>i</code>: case insensitive;
</para></listitem>

<listitem><para>
    <code>x</code>: extended (spaces are ignored and it is possible to put comments
    starting with <code>#</code> and ending at the end of the line);
</para></listitem>

<listitem><para>
    <code>s</code>: the metacharacter <code>.</code> matches the <code>\n</code>.
</para></listitem>
</itemizedlist>

<para>
You can set the default options using the <code>&lt;default-regex-options</code> tag
before the <code>&lt;definitions&gt;</code> element. To disable a group of options,
instead, you have to preced them with a hyphen (<code>-</code>).
[FIXME: add an example]
</para>

<para>
In libgedit-gtksourceview are available also some extensions to the standard
perl style regular expressions:
</para>

<itemizedlist>
<listitem><para>
    <code>\%[</code> and <code>\%]</code> are custom word boundaries, which can
    be redefined with the <code>&lt;keyword-char-class&gt;</code> tag (in
    contrast with <code>\b</code>);
</para></listitem>

<listitem><para>
    <code>\%{id}</code> will include the regular expression defined in the
    <code>&lt;define-regex&gt;</code> tag with the same id, useful if you have
    common portions of regular expressions used in different contexts;
</para></listitem>

<listitem><para>
    <code>\%{subpattern@start}</code> can be used only inside the
    <code>&lt;end&gt;</code> tag and will be substituted with the
    string matched in the corresponding
    sub-pattern (can be a number or a name if named sub-patterns are
    used) in the preceding <code>&lt;start&gt;</code> element. For an example
    see the implementation of here-documents in the <filename>sh.lang</filename>
    language description distribuited with libgedit-gtksourceview.
</para></listitem>
</itemizedlist>

<para>
The next context is for C-style strings. They start and end with a double
quote but they can contain escaped double quotes, so we sould make sure
we don't end the string prematurely:
</para>

<programlisting>
&lt;context id="string" end-at-line-end="true" style-ref="string"&gt;
</programlisting>

<para>
The <code>end-at-line-end</code> attribute tells the engine that the current context
should be forced to terminate at the end of the line, even if the ending
regular expression is not found, and that an error should be displayed.
</para>

<programlisting>
&lt;start&gt;"&lt;/start&gt;
&lt;end&gt;"&lt;/end&gt;
&lt;include&gt;
</programlisting>

<para>
To implement the escape handling we include a <code>escape</code> context:
</para>

<programlisting>
  &lt;context id="escape" style-ref="escaped-character"&gt;
    &lt;match&gt;\\.&lt;/match&gt;
  &lt;/context&gt;
</programlisting>

<para>
This is a simple context matching a single regular expression, contained in
the <code>&lt;match&gt;</code> element. This context will extend its parent, causing the
ending regular expression of the <code>"string"</code> context to not match the escaped
double quote.
</para>

<programlisting>
&lt;/include&gt;
&lt;/context&gt;
</programlisting>

<para>
Multiline C-style comment can span over multiple lines and cannot be
escaped, but to make things more interesting we want to highlight every
internet address contained:
</para>

<programlisting>
&lt;context id="comment-multiline" style-ref="comment"&gt;
  &lt;start&gt;\/\*&lt;/start&gt;
  &lt;end&gt;\*\/&lt;/end&gt;
  &lt;include&gt;
    &lt;context id="net-address" style-ref="net-address" extend-parent="false"&gt;
</programlisting>

<para>
In this case, the child should be terminated if the end of the parent is
found, so we use <code>false</code> in the <code>extend-parent</code> attribute.
</para>

<programlisting>
      &lt;match&gt;http:\/\/[^\s]*&lt;/match&gt;
    &lt;/context&gt;
  &lt;/include&gt;
&lt;/context&gt;
</programlisting>

<para>
For instance in the following comment the string <code>http://www.gnome.org*/</code>
matches the <code>net-address</code> context but it contains the end of the parent
context (<code>*/</code>.) As <code>extend-parent</code> is false,
only <code>http://www.gnome.org</code> is
highlighted as an address and <code>*/</code> is correctly recognized as the end of
the comment.
</para>

<programlisting>
/* This is a comment http://www.gnome.org */
</programlisting>

<para>
Character constants in C are delimited by single quotes (<code>'</code>) and can
contain escaped characters:
</para>

<programlisting>
&lt;context id="char" end-at-line-end="true" style-ref="string"&gt;
  &lt;start&gt;'&lt;/start&gt;
  &lt;end&gt;'&lt;/end&gt;
  &lt;include&gt;
    &lt;context ref="escape"/&gt;
</programlisting>

<para>
The <code>ref</code> attribute is used when we want to reuse a previously defined
context. Here we reuse the <code>escape</code> context defined in the <code>string</code>
context, without repeating its definition.
</para>

<programlisting>
  &lt;/include&gt;
&lt;/context&gt;
</programlisting>

<para>
Using <code>ref</code> it is also possible to refer to contexts defined in other
languages, preceding the id of the context with the id of the containing
language, separating them with a colon:
</para>

<programlisting>
&lt;context ref="def:decimal"/&gt;
&lt;context ref="def:float"/&gt;
</programlisting>

<para>
The definitions for decimal and float constants are in a external file,
with id <code>def</code>, which is not associated with any language but contains
reusable contexts wich every language definition can import.
</para>

<para>
The <code>def</code> language file contains an <code>in-comment</code> context that can contain
addresses and tags such as FIXME and TODO, so we can write a new version of
our <code>comment-multiline</code> context that uses the definitions from <code>def.lang</code>.
</para>

<programlisting>
&lt;context id="comment-multiline" style-ref="comment"&gt;
  &lt;start&gt;\/\*&lt;/start&gt;
  &lt;end&gt;\*\/&lt;/end&gt;
  &lt;include&gt;
    &lt;context ref="def:in-comment"/&gt;
</programlisting>

<programlisting>
  &lt;/include&gt;
&lt;/context&gt;
</programlisting>

<para>
Keywords can be grouped in a context using a list of <code>&lt;keyword&gt;</code>
elements:
</para>

<programlisting>
&lt;context id="keywords" style-ref="keyword"&gt;
  &lt;keyword&gt;if&lt;/keyword&gt;
  &lt;keyword&gt;else&lt;/keyword&gt;
  &lt;keyword&gt;for&lt;/keyword&gt;
  &lt;keyword&gt;while&lt;/keyword&gt;
  &lt;keyword&gt;return&lt;/keyword&gt;
  &lt;keyword&gt;break&lt;/keyword&gt;
  &lt;keyword&gt;switch&lt;/keyword&gt;
  &lt;keyword&gt;case&lt;/keyword&gt;
  &lt;keyword&gt;default&lt;/keyword&gt;
  &lt;keyword&gt;do&lt;/keyword&gt;
  &lt;keyword&gt;continue&lt;/keyword&gt;
  &lt;keyword&gt;goto&lt;/keyword&gt;
  &lt;keyword&gt;sizeof&lt;/keyword&gt;
&lt;/context&gt;
</programlisting>

<para>
Keywords with different meaning can be grouped in different context, making
possible to highlight them differently:
</para>

<programlisting>
&lt;context id="types" style-ref="type"&gt;
  &lt;keyword&gt;char&lt;/keyword&gt;
  &lt;keyword&gt;const&lt;/keyword&gt;
  &lt;keyword&gt;double&lt;/keyword&gt;
  &lt;keyword&gt;enum&lt;/keyword&gt;
  &lt;keyword&gt;float&lt;/keyword&gt;
  &lt;keyword&gt;int&lt;/keyword&gt;
  &lt;keyword&gt;long&lt;/keyword&gt;
  &lt;keyword&gt;short&lt;/keyword&gt;
  &lt;keyword&gt;signed&lt;/keyword&gt;
  &lt;keyword&gt;static&lt;/keyword&gt;
  &lt;keyword&gt;struct&lt;/keyword&gt;
  &lt;keyword&gt;typedef&lt;/keyword&gt;
  &lt;keyword&gt;union&lt;/keyword&gt;
  &lt;keyword&gt;unsigned&lt;/keyword&gt;
  &lt;keyword&gt;void&lt;/keyword&gt;
&lt;/context&gt;
</programlisting>

<para>
You can also set a prefix (or a suffix) common to every keyword using the
<code>&lt;prefix&gt;</code> and <code>&lt;suffix&gt;</code> tags:
</para>

<programlisting>
&lt;context id="preprocessor" style-ref="preprocessor"&gt;
  &lt;prefix&gt;^#&lt;/prefix&gt;
</programlisting>

<para>
If not specified, <code>&lt;prefix&gt;</code> and <code>&lt;suffix&gt;</code>
are set to, respectively, <code>\%[</code> and
<code>\%]</code>.
</para>

<programlisting>
  &lt;keyword&gt;define&lt;/keyword&gt;
  &lt;keyword&gt;undef&lt;/keyword&gt;
</programlisting>

<para>
Keep in mind that every keyword is a regular expression:
</para>

<programlisting>
  &lt;keyword&gt;if(n?def)?&lt;/keyword&gt;
  &lt;keyword&gt;else&lt;/keyword&gt;
  &lt;keyword&gt;elif&lt;/keyword&gt;
  &lt;keyword&gt;endif&lt;/keyword&gt;
&lt;/context&gt;
</programlisting>

<para>
In C, there is a common pratice to use <code>#if 0</code> to express multi-line
nesting comments. To make things easier to the user, we want to highlight
these pseudo-comments as comments:
</para>

<programlisting>
&lt;context id="if0-comment" style-ref="comment"&gt;
  &lt;start&gt;^#if 0\b&lt;/start&gt;
  &lt;end&gt;^#(endif|else|elif)\b&lt;/end&gt;
  &lt;include&gt;
</programlisting>

<para>
As <code>#if 0</code> comments are nesting, we should consider that inside a comment
we can find other <code>#if</code>s with the corresponding <code>#endif</code>s, avoiding
the termination of the comment on the wrong <code>#endif</code>. To do so we use a
nested context, that will extend the parent on every nested
<code>#if</code>/<code>#endif</code>:
</para>

<programlisting>
  &lt;context id="if-in-if0"&gt;
    &lt;start&gt;^#if(n?def)?\b&lt;/start&gt;
    &lt;end&gt;^#endif\b&lt;/end&gt;
    &lt;include&gt;
</programlisting>

<para>
Nested contexts can be recursive:
</para>

<programlisting>
      &lt;context ref="if-in-if0"/&gt;
    &lt;/include&gt;
  &lt;/context&gt;
  &lt;/include&gt;
&lt;/context&gt;
</programlisting>

<para>
Because contexts defined before have higher priority, <code>if0-comment</code> will
never be matched. To make things work we should move it before the
<code>preprocessor</code> context, thus giving <code>if0-comment</code> a higher priority.
</para>

<para>
For the <code>#include</code> preprocessor directive it could be useful to highlight
differently the included file:
</para>

<programlisting>
&lt;context id="include" style-ref="preprocessor"&gt;
  &lt;match&gt;^#include (".*"|&amp;lt;.*&amp;gt;)&lt;/match&gt;
  &lt;include&gt;
</programlisting>

<para>
To do this we use grouping sub-patterns in the regular expression,
associating them with a context with the <code>sub-pattern</code> attribute:
</para>

<programlisting>
    &lt;context id="included-file" sub-pattern="1"
             style-ref="included-file"/&gt;
</programlisting>

<para>
In the <code>sub-pattern</code> attribute we could use:
</para>

<itemizedlist>
<listitem><para>
    0: the whole regular expression;
</para></listitem>

<listitem><para>
    1: the first sub-pattern (a sub-espression enclosed in
    parenthesis);
</para></listitem>

<listitem><para>
    2: the second;
</para></listitem>

<listitem><para>
    ...
</para></listitem>

<listitem><para>
    <code>name</code>: a named sub-pattern with name <code>name</code> (see the PCRE
    documentation.)
</para></listitem>
</itemizedlist>

<para>
We could also use a <code>where</code> attribute with value
<code>start</code> or <code>end</code> to
specify the regular expression the context is referring, when we have both
the <code>&lt;start&gt;</code> and <code>&lt;end&gt;</code> element.
</para>

<programlisting>
  &lt;/include&gt;
&lt;/context&gt;
</programlisting>

<para>
Having defined a good subset of the C syntax we close every tag still open:
</para>

<programlisting>
&lt;/include&gt;
&lt;/context&gt;
&lt;/definitions&gt;
&lt;/language&gt;
</programlisting>

</refsect1>

<refsect1>
<title>The full language definition</title>
<para>
This is the full language definition for the subset of C taken in consideration
for this tutorial:
</para>

<programlisting>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;language id="c" name="C" version="2.0" _section="Source"&gt;
  &lt;metadata&gt;
    &lt;property name="mimetypes"&gt;text/x-c;text/x-csrc&lt;/property&gt;
    &lt;property name="globs"&gt;*.c&lt;/property&gt;
  &lt;/metadata&gt;
  &lt;styles&gt;
    &lt;style id="comment" name="Comment" map-to="def:comment"/&gt;
    &lt;style id="string" name="String" map-to="def:string"/&gt;
    &lt;style id="escaped-character" name="Escaped Character" map-to="def:special-char"/&gt;
    &lt;style id="preprocessor" name="Preprocessor" map-to="def:preprocessor"/&gt;
    &lt;style id="included-file" name="Included File" map-to="def:string"/&gt;
    &lt;style id="char" name="Character" map-to="def:character"/&gt;
    &lt;style id="keyword" name="Keyword" map-to="def:keyword"/&gt;
    &lt;style id="type" name="Data Type" map-to="def:type"/&gt;
  &lt;/styles&gt;
  &lt;definitions&gt;
    &lt;context id="c"&gt;
      &lt;include&gt;

        &lt;context id="comment" style-ref="comment"&gt;
          &lt;start&gt;\/\/&lt;/start&gt;
          &lt;end&gt;$&lt;/end&gt;
        &lt;/context&gt;

        &lt;context id="string" end-at-line-end="true" style-ref="string"&gt;
          &lt;start&gt;"&lt;/start&gt;
          &lt;end&gt;"&lt;/end&gt;
          &lt;include&gt;
            &lt;context id="escape" style-ref="escaped-character"&gt;
              &lt;match&gt;\\.&lt;/match&gt;
            &lt;/context&gt;
          &lt;/include&gt;
        &lt;/context&gt;

        &lt;context id="comment-multiline" style-ref="comment"&gt;
          &lt;start&gt;\/\*&lt;/start&gt;
          &lt;end&gt;\*\/&lt;/end&gt;
          &lt;include&gt;
            &lt;context ref="def:in-comment"/&gt;
          &lt;/include&gt;
        &lt;/context&gt;

        &lt;context id="char" end-at-line-end="true" style-ref="string"&gt;
          &lt;start&gt;'&lt;/start&gt;
          &lt;end&gt;'&lt;/end&gt;
          &lt;include&gt;
            &lt;context ref="escape"/&gt;
          &lt;/include&gt;
        &lt;/context&gt;

        &lt;context ref="def:decimal"/&gt;
        &lt;context ref="def:float"/&gt;

        &lt;context id="keywords" style-ref="keyword"&gt;
          &lt;keyword&gt;if&lt;/keyword&gt;
          &lt;keyword&gt;else&lt;/keyword&gt;
          &lt;keyword&gt;for&lt;/keyword&gt;
          &lt;keyword&gt;while&lt;/keyword&gt;
          &lt;keyword&gt;return&lt;/keyword&gt;
          &lt;keyword&gt;break&lt;/keyword&gt;
          &lt;keyword&gt;switch&lt;/keyword&gt;
          &lt;keyword&gt;case&lt;/keyword&gt;
          &lt;keyword&gt;default&lt;/keyword&gt;
          &lt;keyword&gt;do&lt;/keyword&gt;
          &lt;keyword&gt;continue&lt;/keyword&gt;
          &lt;keyword&gt;goto&lt;/keyword&gt;
          &lt;keyword&gt;sizeof&lt;/keyword&gt;
        &lt;/context&gt;

        &lt;context id="types" style-ref="type"&gt;
          &lt;keyword&gt;char&lt;/keyword&gt;
          &lt;keyword&gt;const&lt;/keyword&gt;
          &lt;keyword&gt;double&lt;/keyword&gt;
          &lt;keyword&gt;enum&lt;/keyword&gt;
          &lt;keyword&gt;float&lt;/keyword&gt;
          &lt;keyword&gt;int&lt;/keyword&gt;
          &lt;keyword&gt;long&lt;/keyword&gt;
          &lt;keyword&gt;short&lt;/keyword&gt;
          &lt;keyword&gt;signed&lt;/keyword&gt;
          &lt;keyword&gt;static&lt;/keyword&gt;
          &lt;keyword&gt;struct&lt;/keyword&gt;
          &lt;keyword&gt;typedef&lt;/keyword&gt;
          &lt;keyword&gt;union&lt;/keyword&gt;
          &lt;keyword&gt;unsigned&lt;/keyword&gt;
          &lt;keyword&gt;void&lt;/keyword&gt;
        &lt;/context&gt;

        &lt;context id="if0-comment" style-ref="comment"&gt;
          &lt;start&gt;^#if 0\b&lt;/start&gt;
          &lt;end&gt;^#(endif|else|elif)\b&lt;/end&gt;
          &lt;include&gt;
            &lt;context id="if-in-if0"&gt;
              &lt;start&gt;^#if(n?def)?\b&lt;/start&gt;
              &lt;end&gt;^#endif\b&lt;/end&gt;
              &lt;include&gt;
                &lt;context ref="if-in-if0"/&gt;
              &lt;/include&gt;
            &lt;/context&gt;
          &lt;/include&gt;
        &lt;/context&gt;

        &lt;context id="preprocessor" style-ref="preprocessor"&gt;
          &lt;prefix&gt;^#&lt;/prefix&gt;
          &lt;keyword&gt;define&lt;/keyword&gt;
          &lt;keyword&gt;undef&lt;/keyword&gt;
          &lt;keyword&gt;if(n?def)?&lt;/keyword&gt;
          &lt;keyword&gt;else&lt;/keyword&gt;
          &lt;keyword&gt;elif&lt;/keyword&gt;
          &lt;keyword&gt;endif&lt;/keyword&gt;
        &lt;/context&gt;

        &lt;context id="include" style-ref="preprocessor"&gt;
          &lt;match&gt;^#include (".*"|&amp;lt;.*&amp;gt;)&lt;/match&gt;
          &lt;include&gt;
            &lt;context id="included-file"
                     sub-pattern="1"
                     style-ref="included-file"/&gt;
          &lt;/include&gt;
        &lt;/context&gt;

      &lt;/include&gt;
    &lt;/context&gt;
  &lt;/definitions&gt;
&lt;/language&gt;
</programlisting>

</refsect1>

</refentry>