vala.lang 13.1 KB
Newer Older
1
2
3
<?xml version="1.0" encoding="UTF-8"?>
<!--

4
5
 This file is part of GtkSourceView

6
7
8
9
10
 Author: John Luke <jluke@cfl.rr.com>
 Copyright (C) 2003 John Luke <jluke@cfl.rr.com>
 Copyright (C) 2004 Jeroen Zwartepoorte <jeroen@xs4all.nl>
 Copyright (C) 2004 Alessio Frusciante <algol@firenze.linux.it>
 Copyright (C) 2005 Brion Vibber <brion@pobox.com>
11
 Copyright (C) 2011 Marco Trevisan <mail@3v1n0.net>
12

13
 GtkSourceView is free software; you can redistribute it and/or
14
 modify it under the terms of the GNU Lesser General Public
15
 License as published by the Free Software Foundation; either
16
 version 2.1 of the License, or (at your option) any later version.
17

18
 GtkSourceView is distributed in the hope that it will be useful,
19
20
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
 Lesser General Public License for more details.
22

23
24
 You should have received a copy of the GNU Lesser General Public License
 along with this library; if not, see <http://www.gnu.org/licenses/>.
25
26

-->
27
<language id="vala" name="Vala" version="2.0" _section="Source">
28
29
  <metadata>
    <property name="mimetypes">text/x-vala</property>
30
    <property name="globs">*.vala;*.vapi</property>
31
32
33
    <property name="line-comment-start">//</property>
    <property name="block-comment-start">/*</property>
    <property name="block-comment-end">*/</property>
34
    <property name="suggested-suffix">.vala</property>
35
36
37
  </metadata>

  <styles>
38
39
40
41
42
43
44
    <style id="comment" name="Comment" map-to="def:comment"/>
    <style id="error" name="Error" map-to="def:error"/>
    <style id="type" name="Data Type" map-to="def:type"/>
    <style id="string" name="String" map-to="def:string"/>
    <style id="keyword" name="Keyword" map-to="def:keyword"/>
    <style id="boolean" name="Boolean value" map-to="def:boolean"/>
    <style id="null-value" name="Null Value" map-to="def:special-constant"/>
45
46
47
    <style id="directive" name="Directives" map-to="def:preprocessor"/>
    <style id="attributes" name="Vala Attributes" map-to="def:function"/>
    <style id="string-template" name="Vala String template" map-to="def:function"/>
48
49
    <style id="regex" name="Regular Expression" map-to="def:string"/>
    <style id="escape" name="Escaped Character" map-to="def:special-char"/>
50
51
52
  </styles>

  <definitions>
53
54
55
    <define-regex id="preproc-start">^\s*#\s*</define-regex>
    <define-regex id="identifier">[_a-zA-Z][_a-zA-Z0-9]*</define-regex>
    <define-regex id="type_name">[_a-zA-Z][_a-zA-Z0-9.]*</define-regex>
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    <!--regex-->
    <define-regex id="regex-opts">[gim]*</define-regex>

    <!--contexts NOT used in the main context-->
    <context id="escape" style-ref="escape">
      <match>\\((0-7){3}|(x[a-fA-F0-9]{2})|(c\S)|([CM]-\S)|(M-C-\S)|.)</match>
    </context>

    <context id="regex-bracketed" style-ref="escape" style-inside="true">
      <start>(?&lt;!\\)[[]</start>
      <end>(?&lt;!\\)]</end>
    </context>

    <!--contexts used in the main context-->
    <context id="regex-simple" style-ref="regex">
      <start extended="true">
        ((?&lt;=([(]|\s))|^)
JCWasmx86's avatar
JCWasmx86 committed
74
        ?\/
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
        (?=
          ([^/\\]*(\\.))*
          [^/]*
          \/
          \%{regex-opts}
          \s*
          ([),;.\/\]:}]|$)
        )</start>
      <end>\/\%{regex-opts}</end>
      <include>
        <context ref="escape"/>
        <context ref="def:line-continue"/>
        <context ref="regex-bracketed"/>
      </include>
    </context>

91
    <context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" class-disabled="no-spell-check">
92
93
94
95
96
97
      <start>//</start>
      <include>
        <context ref="def:in-line-comment"/>
      </include>
    </context>

98
    <context id="multiline-comment" style-ref="comment" class="comment" class-disabled="no-spell-check">
99
100
101
102
103
104
105
106
107
108
109
      <start>/\*</start>
      <end>\*/</end>
      <include>
        <context ref="def:in-comment"/>
      </include>
    </context>

    <context id="close-comment-outside-comment" style-ref="error">
      <match>\*/(?!\*)</match>
    </context>

110
111
112
113
114
115
116
117
118
119
	<context id="multiline-double-quoted-string" class="string" style-ref="string" class-disabled="no-spell-check">
      <start>"""</start>
      <end>"""</end>
      <include>
        <context ref="c:printf"/>
        <context ref="c:escaped-character"/>
        <context ref="def:line-continue"/>
      </include>
    </context>

120
    <context id="multiline-string" style-ref="string" class="string" class-disabled="no-spell-check">
121
122
123
124
125
126
127
128
129
130
131
      <start>"</start>
      <end>"</end>
      <include>
        <context ref="c:printf"/>
        <context ref="c:escaped-character"/>
        <context ref="def:line-continue"/>
      </include>
    </context>

    <context id="multiline-string-templates" style-ref="string" class="string" class-disabled="no-spell-check">
      <start>@"</start>
132
133
      <end>"</end>
      <include>
134
135
        <context ref="c:printf"/>
        <context ref="c:escaped-character"/>
136
        <context ref="def:line-continue"/>
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
        <context id="string-templates" style-ref="string-template">
            <match>\$\%{identifier}</match>
        </context>
        <context id="string-templates-brackets" style-ref="string-template">
          <start>\$\(</start>
          <end>\)</end>
          <include>
            <context id="in-string-templates-brackets">
              <include>
                <context>
                  <start>\(</start>
                  <end>\)</end>
                  <include>
                    <context ref="in-string-templates-brackets"/>
                  </include>
                </context>
              </include>
            </context>
          </include>
        </context>
157
158
159
      </include>
    </context>

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
    <context id="if0-comment" style-ref="comment">
        <start>\%{preproc-start}if\b\s*(0|false|\!true|\!1)\b</start>
        <end>(\%{preproc-start}endif)|(\%{preproc-start}(else|elif).*)\b</end>
        <include>
            <context sub-pattern="2" where="end" style-ref="directive"/>
            <context id="if-in-if0">
                <start>\%{preproc-start}if\b</start>
                <end>\%{preproc-start}endif\b</end>
                <include>
                    <context ref="if-in-if0"/>
                    <context ref="def:in-comment"/>
                </include>
            </context>
            <context ref="def:in-comment"/>
        </include>
    </context>

    <context id="directive" style-ref="directive" end-at-line-end="true">
        <start extended="true">
                \%{preproc-start}
                (if|else|elif|endif)
                \b
        </start>
        <include>
            <context ref="boolean"/>
        </include>
    </context>

    <context id="at-identifier">
        <match>@\%{identifier}</match>
    </context>

192
193
194
195
    <context id="keywords" style-ref="keyword">
      <keyword>class</keyword>
      <keyword>delegate</keyword>
      <keyword>enum</keyword>
196
      <keyword>errordomain</keyword>
197
198
199
200
201
202
203
      <keyword>interface</keyword>
      <keyword>namespace</keyword>
      <keyword>signal</keyword>
      <keyword>struct</keyword>
      <keyword>using</keyword>
      <!-- modifiers -->
      <keyword>abstract</keyword>
204
      <keyword>async</keyword>
205
      <keyword>const</keyword>
206
207
208
      <keyword>dynamic</keyword>
      <keyword>extern</keyword>
      <keyword>inline</keyword>
209
      <keyword>internal</keyword>
210
211
      <keyword>out</keyword>
      <keyword>override</keyword>
212
      <keyword>owned</keyword>
213
214
215
216
      <keyword>private</keyword>
      <keyword>protected</keyword>
      <keyword>public</keyword>
      <keyword>ref</keyword>
217
      <keyword>sealed</keyword>
218
      <keyword>static</keyword>
219
      <keyword>unowned</keyword>
220
      <keyword>virtual</keyword>
221
      <keyword>volatile</keyword>
222
223
224
225
226
227
228
229
230
231
      <keyword>weak</keyword>
      <!-- others -->
      <keyword>as</keyword>
      <keyword>base</keyword>
      <keyword>break</keyword>
      <keyword>case</keyword>
      <keyword>catch</keyword>
      <keyword>construct</keyword>
      <keyword>continue</keyword>
      <keyword>default</keyword>
232
      <keyword>delete</keyword>
233
234
      <keyword>do</keyword>
      <keyword>else</keyword>
235
      <keyword>ensures</keyword>
236
237
238
239
240
241
242
      <keyword>finally</keyword>
      <keyword>for</keyword>
      <keyword>foreach</keyword>
      <keyword>get</keyword>
      <keyword>if</keyword>
      <keyword>in</keyword>
      <keyword>is</keyword>
243
      <keyword>lock</keyword>
244
      <keyword>new</keyword>
245
      <keyword>params</keyword>
246
      <keyword>requires</keyword>
247
248
249
250
251
252
253
254
255
      <keyword>return</keyword>
      <keyword>set</keyword>
      <keyword>sizeof</keyword>
      <keyword>switch</keyword>
      <keyword>this</keyword>
      <keyword>throw</keyword>
      <keyword>throws</keyword>
      <keyword>try</keyword>
      <keyword>typeof</keyword>
256
      <keyword>unlock</keyword>
257
258
259
      <keyword>value</keyword>
      <keyword>var</keyword>
      <keyword>while</keyword>
260
      <keyword>with</keyword>
261
      <keyword>yield</keyword>
262
263
264
265
266
267
268
269
    </context>

    <context id="primitives" style-ref="type">
      <keyword>bool</keyword>
      <keyword>char</keyword>
      <keyword>double</keyword>
      <keyword>float</keyword>
      <keyword>int</keyword>
270
      <keyword>int8</keyword>
271
272
273
274
275
      <keyword>int16</keyword>
      <keyword>int32</keyword>
      <keyword>int64</keyword>
      <keyword>long</keyword>
      <keyword>short</keyword>
276
277
      <keyword>size_t</keyword>
      <keyword>ssize_t</keyword>
278
      <keyword>string</keyword>
279
280
281
      <keyword>string16</keyword>
      <keyword>string32</keyword>
      <keyword>time_t</keyword>
282
283
      <keyword>uchar</keyword>
      <keyword>uint</keyword>
284
      <keyword>uint8</keyword>
285
286
287
288
      <keyword>uint16</keyword>
      <keyword>uint32</keyword>
      <keyword>uint64</keyword>
      <keyword>ulong</keyword>
289
      <keyword>unichar</keyword>
290
      <keyword>unichar2</keyword>
291
      <keyword>ushort</keyword>
292
      <keyword>va_list</keyword>
293
294
295
296
297
298
299
300
301
302
303
304
305
      <keyword>void</keyword>
    </context>

    <define-regex id="attributes-names" extended="true">
      Assert|
      CCode|
      SimpleType|
      BooleanType|
      IntegerType|
      FloatingType|
      Signal|
      Deprecated|
      Description|
306
307
      Experimental|
      Version|
308
309
      DBus|
      Compact|
310
311
      ConcreteAccessor|
      DestroysInstance|
312
313
314
      Diagnostics|
      ErrorBase|
      Flags|
315
316
      FormatArg|
      GenericAccessors|
317
      GIR|
318
319
320
      GtkCallback|
      GtkChild|
      GtkTemplate|
321
322
323
324
325
326
327
328
329
330
331
332
333
      HasEmitter|
      Immutable|
      ModuleInit|
      NoAccessorMethod|
      NoArrayLength|
      NoReturn|
      NoThrow|
      NoWrapper|
      PointerType|
      Print|
      PrintfFormat|
      ReturnsModifiedPointer|
      ScanfFormat|
334
      SingleInstance|
335
336
337
338
339
340
341
342
343
344
345
346
347
      ThreadLocal
    </define-regex>

    <context id="attributes" style-ref="attributes">
        <start>\[\s*(\%{attributes-names})</start>
        <end>\]</end>
        <include>
            <context sub-pattern="1" where="start" style-ref="type"/>
            <context ref="boolean"/>
            <context ref="multiline-string"/>
            <context ref="c:float"/>
            <context ref="c:decimal"/>
        </include>
348
349
350
351
352
353
354
355
356
357
358
    </context>

    <context id="null-value" style-ref="null-value">
      <keyword>null</keyword>
    </context>

    <context id="boolean" style-ref="boolean">
      <keyword>false</keyword>
      <keyword>true</keyword>
    </context>

359
360
361
362
363
364
365
366
367
    <define-regex id="type-prefixes" extended="true">
      class|
      delegate|
      enum|
      errordomain|
      interface|
      namespace|
      struct
    </define-regex>
368

369
370
371
372
373
374
375
376
377
	<context id="type-declaration">
        <start>(\%{type-prefixes})\s+(\%{type_name})(\s*&lt;[^&gt;]&gt;)?\s*(\s*:\s*(\%{type_name}))?</start>
        <end>\s</end>
        <include>
            <context sub-pattern="1" where="start" style-ref="keyword"/>
            <context sub-pattern="2" where="start" style-ref="type"/>
            <context sub-pattern="5" where="start" style-ref="type"/>
            <context ref="vala"/>
        </include>
378
379
    </context>

380
381
382
383
384
385
386
387
<!-- Function support, disabled by default.
    <context id="function">
        <start>(\%{identifier})\s*\(</start>
        <end>\)</end>
        <include>
            <context sub-pattern="1" where="start" style-ref="def:function"/>
            <context ref="vala"/>
        </include>
388
    </context>
389
-->
390

391
    <context id="vala" class="no-spell-check">
392
      <include>
393
        <context ref="gtk-doc:inline-docs-section"/>
394
395
396
        <context ref="line-comment"/>
        <context ref="multiline-comment"/>
        <context ref="close-comment-outside-comment"/>
397
398
        <context ref="multiline-string-templates"/>
        <context ref="multiline-double-quoted-string"/>
399
        <context ref="multiline-string"/>
400
401
        <context ref="at-identifier"/>
        <context ref="type-declaration"/>
402
403
        <context ref="keywords"/>
        <context ref="primitives"/>
404
        <context ref="attributes"/>
405
406
        <context ref="null-value"/>
        <context ref="boolean"/>
407
408
409
410
411
412
413
        <context ref="c:char"/>
        <context ref="c:decimal"/>
        <context ref="c:hexadecimal"/>
        <context ref="c:float"/>
        <context ref="c:octal"/>
        <context ref="if0-comment"/>
        <context ref="directive"/>
414
        <context ref="regex-simple"/>
415
        <!-- <context ref="function"/> -->
416
417
418
419
      </include>
    </context>
  </definitions>
</language>