Merge: gtksourceview: Rewrite the language definition
[nit.git] / misc / gtksourceview / nit.lang
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3         This file is part of NIT ( http://www.nitlanguage.org ).
4
5         Licensed under the Apache License, Version 2.0 (the "License");
6         you may not use this file except in compliance with the License.
7         You may obtain a copy of the License at
8
9                 http://www.apache.org/licenses/LICENSE-2.0
10
11         Unless required by applicable law or agreed to in writing, software
12         distributed under the License is distributed on an "AS IS" BASIS,
13         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14         See the License for the specific language governing permissions and
15         limitations under the License.
16 -->
17 <language id="nit" _name="Nit" version="2.0" _section="Source">
18         <metadata>
19                 <!-- TODO: Register the media type -->
20                 <property name="mimetypes">text/x-nit</property>
21                 <property name="globs">*.nit</property>
22                 <property name="line-comment-start">#</property>
23         </metadata>
24
25         <styles>
26                 <style id="attribute"          _name="Attribute"             map-to="def:builtin"/>
27                 <style id="boolean"            _name="Boolean value"         map-to="def:boolean"/>
28                 <style id="binary"             _name="Binary number"         map-to="def:base-n-integer"/>
29                 <style id="builtin-annotation" _name="Built-in Annotation"   map-to="def:keyword"/>
30                 <style id="character"          _name="Character"             map-to="def:character"/>
31                 <style id="decimal"            _name="Decimal number"        map-to="def:decimal"/>
32                 <style id="escaped-character"  _name="Escaped Character"     map-to="def:special-char"/>
33                 <style id="extern-code"        _name="Extern Code"           map-to="def:preprocessor"/>
34                 <style id="floating-point"     _name="Floating point number" map-to="def:floating-point"/>
35                 <style id="hexadecimal"        _name="Hexadecimal number"    map-to="def:base-n-integer"/>
36                 <style id="keyword"            _name="Keyword"               map-to="def:keyword"/>
37                 <style id="octal"              _name="Octal number"          map-to="def:base-n-integer"/>
38                 <style id="module-handler"     _name="Module Handler"        map-to="def:preprocessor"/>
39                 <style id="null-value"         _name="Null Value"            map-to="def:special-constant"/>
40                 <style id="reserved"           _name="Reserved keyword"      map-to="def:reserved"/>
41                 <style id="special-variable"   _name="Special Variable"      map-to="def:builtin"/>
42                 <style id="string"             _name="String"                map-to="def:string"/>
43                 <style id="type"               _name="Data Type"             map-to="def:type"/>
44
45                 <!--
46                         The following styles do not inherit from `def` because most style
47                         schemes highlight them too much.
48                 -->
49                 <style id="operator"           _name="Operator"/>              <!-- "def:operator" -->
50                 <style id="variable"           _name="Variable or Method"/>    <!-- "def:identifier" -->
51
52                 <!-- TODO: Implement `bad_string` and `bad_char`?
53                 <style id="error"              _name="Error"                 map-to="def:error"/>
54                 -->
55         </styles>
56
57         <default-regex-options extended="true"/>
58         <keyword-char-class>[A-Za-z0-9_]</keyword-char-class>
59
60         <definitions>
61                 <define-regex id="space" extended="false">[ \n\r\t]</define-regex>
62
63                 <!-- Keywords and operators -->
64
65                 <context id="reserved" style-ref="reserved">
66                         <keyword>package</keyword>
67                         <keyword>yield</keyword>
68                 </context>
69
70                 <context id="kwimport" style-ref="module-handler">
71                         <keyword>import</keyword>
72                 </context>
73
74                 <context id="keyword" style-ref="keyword">
75                         <keyword>abort</keyword>
76                         <keyword>abstract</keyword>
77                         <keyword>as</keyword>
78                         <keyword>assert</keyword>
79                         <keyword>break</keyword>
80                         <keyword>catch</keyword>
81                         <keyword>class</keyword>
82                         <keyword>continue</keyword>
83                         <keyword>__debug__</keyword>
84                         <keyword>do</keyword>
85                         <keyword>else</keyword>
86                         <keyword>end</keyword>
87                         <keyword>enum</keyword>
88                         <keyword>extern</keyword>
89                         <keyword>for</keyword>
90                         <keyword>fun</keyword>
91                         <keyword>if</keyword>
92                         <keyword>init</keyword>
93                         <keyword>in</keyword>
94                         <keyword>interface</keyword>
95                         <keyword>intrude</keyword>
96                         <keyword>isa</keyword>
97                         <keyword>is</keyword>
98                         <keyword>isset</keyword>
99                         <keyword>label</keyword>
100                         <keyword>loop</keyword>
101                         <keyword>module</keyword>
102                         <keyword>new</keyword>
103                         <keyword>nullable</keyword>
104                         <keyword>once</keyword>
105                         <keyword>private</keyword>
106                         <keyword>protected</keyword>
107                         <keyword>public</keyword>
108                         <keyword>redef</keyword>
109                         <keyword>return</keyword>
110                         <keyword>subset</keyword>
111                         <keyword>super</keyword>
112                         <keyword>then</keyword>
113                         <keyword>type</keyword>
114                         <keyword>universal</keyword>
115                         <keyword>var</keyword>
116                         <keyword>while</keyword>
117                         <keyword>with</keyword>
118                 </context>
119
120                 <context id="builtin-annotation" style-ref="builtin-annotation">
121                         <keyword>autoinit</keyword>
122                         <keyword>auto_inspect</keyword>
123                         <keyword>cflags</keyword>
124                         <keyword>conditional</keyword>
125                         <keyword>deprecated</keyword>
126                         <keyword>fixed</keyword>
127                         <keyword>generated</keyword>
128                         <keyword>intern</keyword>
129                         <keyword>lateinit</keyword>
130                         <keyword>lazy</keyword>
131                         <keyword>ldflags</keyword>
132                         <keyword>light_ffi</keyword>
133                         <keyword>new_annotation</keyword>
134                         <keyword>noautoinit</keyword>
135                         <keyword>noinit</keyword>
136                         <keyword>nosuper</keyword>
137                         <keyword>no_warning</keyword>
138                         <keyword>old_style_init</keyword>
139                         <keyword>optional</keyword>
140                         <keyword>pkgconfig</keyword>
141                         <keyword>platform</keyword>
142                         <keyword>readonly</keyword>
143                         <keyword>writable</keyword>
144                 </context>
145
146                 <context id="boolean" style-ref="boolean">
147                         <keyword>true</keyword>
148                         <keyword>false</keyword>
149                 </context>
150
151                 <context id="special-variable" style-ref="special-variable">
152                         <keyword>self</keyword>
153                 </context>
154
155                 <context id="operator-keyword" style-ref="keyword">
156                         <keyword>and</keyword>
157                         <keyword>implies</keyword>
158                         <keyword>not</keyword>
159                         <keyword>or</keyword>
160                 </context>
161
162                 <context id="operator-punctuation" style-ref="operator">
163                         <match>
164                                 \^=? |
165                                 ~ |
166                                 &lt;&lt;?=? |
167                                 &lt;=&gt; |
168                                 ==? |
169                                 &gt;&gt;?=? |
170                                 \| |
171                                 -=? |
172                                 , |
173                                 ; |
174                                 ::? |
175                                 !=? |
176                                 /=? |
177                                 \.{1,3} |
178                                 \( |
179                                 \) |
180                                 \[ |
181                                 \] |
182                                 @ |
183                                 \*\*?=? |
184                                 &amp;=? |
185                                 %=? |
186                                 \+=?
187                         </match>
188                 </context>
189
190                 <!-- Identifiers -->
191
192                 <context id="attribute" style-ref="attribute">
193                         <match>\%[ _[a-z][A-Za-z0-9_]* \%]</match>
194                 </context>
195
196                 <context id="type" style-ref="type">
197                         <match>\%[ [A-Z][A-Za-z0-9_]* \%]</match>
198                 </context>
199
200                 <context id="variable" style-ref="variable">
201                         <match>\%[ [a-z][A-Za-z0-9_]* \%]</match>
202                 </context>
203
204                 <!-- Numbers -->
205
206                 <define-regex id="integer-suffix">
207                         (?:[iu](?:8|16|32))?
208                 </define-regex>
209
210                 <context id="binary" style-ref="binary">
211                         <match>[+-]?0[Bb][01_]+\%{integer-suffix}</match>
212                 </context>
213
214                 <context id="octal" style-ref="octal">
215                         <match>[+-]?0[Oo][0-7_]+\%{integer-suffix}</match>
216                 </context>
217
218                 <context id="hexadecimal" style-ref="hexadecimal">
219                         <match>[+-]?0[Xx][0-9A-Fa-f_]+\%{integer-suffix}</match>
220                 </context>
221
222                 <context id="decimal" style-ref="decimal">
223                         <match>[+-]?[0-9][0-9_]*\%{integer-suffix}</match>
224                 </context>
225
226                 <context id="floating-point" style-ref="floating-point">
227                         <match>[+-]?(?:[0-9]+|[0-9]*\.[0-9]+)(?:[Ee][+-]?[0-9]+)?</match>
228                 </context>
229
230                 <!-- Strings and characters -->
231
232                 <context id="escaped-apostrophe" style-ref="escaped-character">
233                         <match>\\'</match>
234                 </context>
235
236                 <context id="escaped-character" style-ref="escaped-character">
237                         <match>\\.</match>
238                 </context>
239
240                 <context id="interpolation" style-ref="escaped-character">
241                         <start>\{</start>
242                         <end>\}</end>
243                         <include>
244                                 <!-- FIXME: Reset style -->
245                                 <context ref="nit" />
246                         </include>
247                 </context>
248
249                 <context id="long-interpolation" style-ref="escaped-character">
250                         <start>\{\{\{</start>
251                         <end>\}\}\}</end>
252                         <include>
253                                 <!-- FIXME: Reset style -->
254                                 <context ref="nit" />
255                         </include>
256                 </context>
257
258                 <context id="long-string" style-ref="string" class="string">
259                         <start>"""|'''</start>
260                         <end>\%{0@start}</end>
261                         <include>
262                                 <context ref="escaped-character"/>
263                                 <context ref="long-interpolation"/>
264                         </include>
265                 </context>
266
267                 <context id="character" style-ref="character" class="string">
268                         <start>'</start>
269                         <end>'</end>
270                         <include>
271                                 <context ref="escaped-apostrophe"/>
272                         </include>
273                 </context>
274
275                 <context id="string" style-ref="string" class="string">
276                         <start>"</start>
277                         <end>"</end>
278                         <include>
279                                 <context ref="escaped-character"/>
280                                 <context ref="interpolation"/>
281                         </include>
282                 </context>
283
284                 <!-- Extern code -->
285
286                 <context id="extern-code-cpp" style-ref="extern-code">
287                         <start case-sensitive="false">
288                                 (?'cpp_kwin' in) \%{space}*
289                                 (?'cpp_language_name' "c\+\+(?: [^"]*)?") \%{space}*
290                                 `\{
291                         </start>
292                         <end>`\}</end>
293                         <include>
294                                 <context sub-pattern="cpp_kwin" where="start" style-ref="keyword"/>
295                                 <context sub-pattern="cpp_language_name" where="start"
296                                                 style-ref="string" class="string" />
297                                 <!-- FIXME: Reset style -->
298                                 <context ref="cpp:cpp"/>
299                         </include>
300                 </context>
301
302                 <context id="extern-code-java" style-ref="extern-code">
303                         <start case-sensitive="false">
304                                 (?'java_kwin' in) \%{space}*
305                                 (?'java_language_name' "java(?: [^"]*)?") \%{space}*
306                                 `\{
307                         </start>
308                         <end>`\}</end>
309                         <include>
310                                 <context sub-pattern="java_kwin" where="start" style-ref="keyword"/>
311                                 <context sub-pattern="java_language_name" where="start"
312                                                 style-ref="string" class="string" />
313                                 <!-- FIXME: Reset style -->
314                                 <context ref="java:java"/>
315                         </include>
316                 </context>
317
318                 <context id="extern-code-objc" style-ref="extern-code">
319                         <start case-sensitive="false">
320                                 (?'objc_kwin' in) \%{space}*
321                                 (?'objc_language_name' "objc(?: [^"]*)?") \%{space}*
322                                 `\{
323                         </start>
324                         <end>`\}</end>
325                         <include>
326                                 <context sub-pattern="objc_kwin" where="start" style-ref="keyword"/>
327                                 <context sub-pattern="objc_language_name" where="start"
328                                                 style-ref="string" class="string" />
329                                 <!-- FIXME: Reset style -->
330                                 <context ref="objc:objc"/>
331                         </include>
332                 </context>
333
334                 <context id="extern-code-default" style-ref="extern-code">
335                         <!-- By default, the embedded language is C. -->
336                         <start>`\{</start>
337                         <end>`\}</end>
338                         <include>
339                                 <!-- FIXME: Reset style -->
340                                 <context ref="c:c"/>
341                         </include>
342                 </context>
343
344                 <!-- Main context -->
345                 <context id="nit" class="no-spell-check">
346                         <include>
347                                 <context ref="def:shebang"/>
348                                 <context ref="def:shell-like-comment"/>
349                                 <context ref="extern-code-cpp"/>
350                                 <context ref="extern-code-java"/>
351                                 <context ref="extern-code-objc"/>
352                                 <context ref="extern-code-default"/>
353                                 <context ref="long-string"/>
354                                 <context ref="character"/>
355                                 <context ref="string"/>
356                                 <context ref="reserved"/>
357                                 <context ref="kwimport"/>
358                                 <context ref="keyword"/>
359                                 <context ref="builtin-annotation"/>
360                                 <context ref="boolean"/>
361                                 <context ref="special-variable"/>
362                                 <context ref="operator-keyword"/>
363                                 <context ref="attribute"/>
364                                 <context ref="type"/>
365                                 <context ref="variable"/>
366                                 <context ref="binary"/>
367                                 <context ref="octal"/>
368                                 <context ref="hexadecimal"/>
369                                 <context ref="decimal"/>
370                                 <context ref="floating-point"/>
371                                 <context ref="operator-punctuation"/>
372                         </include>
373                 </context>
374         </definitions>
375 </language>