misc: gtksourceview nit syntax highlighting
[nit.git] / misc / gtksourceview / nit.lang
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3
4  Author: Alexis Laferrière <alexis.laf@xymus.net>
5  Copyright (C) 2009 Alexis Laferrière <alexis.laf@xymus.net>
6
7  Based on ruby.lang
8  Copyright (C) 2004 Archit Baweja <bighead@users.sourceforge.net>
9  Copyright (C) 2005 Michael Witrant <mike@lepton.fr>
10  Copyright (C) 2006 Gabriel Bauman <gbauman@gmail.com>
11
12  This library is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  GNU General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
26 -->
27 <language id="nit" _name="Nit" version="2.0" _section="Sources">
28   <metadata>
29     <property name="mimetypes">text/x-nit</property>
30     <property name="globs">*.nit</property>
31     <property name="line-comment-start">#</property>
32   </metadata>
33
34   <styles>
35     <style id="escape"               _name="Escaped Character"     map-to="def:special-char"/>
36     <style id="comment"              _name="Comment"               map-to="def:comment"/>
37     <style id="attribute-definition" _name="Attribute Definition"  map-to="def:statement"/>
38     <style id="module-handler"       _name="Module handler"        map-to="def:preprocessor"/>
39     <style id="keyword"              _name="Keyword"               map-to="def:keyword"/>
40     <style id="null-value"           _name="Nil Constant"          map-to="def:special-constant"/>
41     <style id="boolean"              _name="Boolean value"         map-to="def:boolean"/>
42     <style id="floating-point"       _name="Floating point number" map-to="def:floating-point"/>
43     <style id="decimal"              _name="Decimal number"        map-to="def:decimal"/>
44     <style id="base-n-integer"       _name="Base-N number"         map-to="def:base-n-integer"/>
45     <style id="string"               _name="String"                map-to="def:string"/>
46     <style id="builtin"              _name="Builtin"               map-to="def:type"/>
47     <style id="class-name"           _name="Constant"              map-to="def:type"/>
48     <style id="symbol"               _name="Symbol"                map-to="def:string"/>
49     <style id="special-variable"     _name="Special Variable"      map-to="def:identifier"/>
50     <style id="predefined-variable"  _name="Predefined Variable"   map-to="def:identifier"/>
51     <style id="variable"             _name="Variable"              map-to="def:identifier"/>
52   </styles>
53
54   <definitions>
55
56     <context id="escape" style-ref="escape">
57       <match>\\((0-7){3}|(x[a-fA-F0-9]{2})|(c\S)|([CM]-\S)|(M-C-\S)|.)</match>
58     </context>
59
60     <context id="multiline-comment" style-ref="comment">
61       <start>^=begin</start>
62       <end>^=end</end>
63       <include>
64         <context ref="escape"/>
65         <context ref="def:in-comment"/>
66       </include>
67     </context>
68
69     <context id="definitions" style-ref="keyword">
70       <keyword>class</keyword>
71       <keyword>fun</keyword>
72       <keyword>redef</keyword>
73       <keyword>var</keyword>
74       <keyword>package</keyword>
75     </context>
76
77     <context id="module-handlers" style-ref="module-handler">
78       <keyword>import</keyword>
79     </context>
80
81     <context id="keywords" style-ref="keyword">
82       <keyword>do</keyword>
83       <keyword>end</keyword>
84       <keyword>intrude</keyword>
85       <keyword>private</keyword>
86       <keyword>if</keyword>
87       <keyword>then</keyword>
88       <keyword>else</keyword>
89       <keyword>while</keyword>
90       <keyword>for</keyword>
91       <keyword>assert</keyword>
92       <keyword>is</keyword>
93       <keyword>abstract</keyword>
94       <keyword>intern</keyword>
95       <keyword>extern</keyword>
96       <keyword>public</keyword>
97       <keyword>protected</keyword>
98       <keyword>or</keyword>
99       <keyword>as</keyword>
100       <keyword>isa</keyword>
101       <keyword>break</keyword>
102       <keyword>continue</keyword>
103       <keyword>return</keyword>
104       <keyword>label</keyword>
105       <keyword>abort</keyword>
106       <keyword>nullable</keyword>
107       <keyword>new</keyword>
108       <keyword>special</keyword>
109       <keyword>super</keyword>
110       <keyword>init</keyword>
111       <keyword>in</keyword>
112       <keyword>or</keyword>
113       <keyword>and</keyword>
114       <keyword>not</keyword>
115       <keyword>writable</keyword>
116       <keyword>readable</keyword>
117     </context>
118
119     <context id="special-variables" style-ref="special-variable">
120       <keyword>self</keyword>
121     </context>
122
123     <context id="instance-variables" style-ref="variable">
124       <match>(::)?\b_[a-zA-Z_][a-zA-Z0-9_]*</match>
125     </context>
126
127     <context id="class-name" style-ref="class-name">
128       <match>(::)?\b[A-Z][A-Za-z0-9_]*\b</match>
129     </context>
130
131     <context id="null-value" style-ref="null-value">
132       <keyword>null</keyword>
133     </context>
134
135     <context id="boolean" style-ref="boolean">
136       <keyword>false</keyword>
137       <keyword>true</keyword>
138     </context>
139     
140     <define-regex id="underscore_num">\d(_?\d)*</define-regex>
141
142     <define-regex id="float" extended="true">
143       ( (\%{underscore_num})?\.\%{underscore_num} | \%{underscore_num}\. ) |
144       ( (\%{underscore_num}|(\%{underscore_num})?\.\%{underscore_num}|\%{underscore_num}\.)[eE][+-]?\%{underscore_num} )
145     </define-regex>
146
147     <context id="float" style-ref="floating-point">
148       <match>(?&lt;![\w\.])\%{float}(?![\w\.])</match>
149     </context>
150
151     <context id="decimal" style-ref="decimal">
152       <match>(?&lt;![\w\.])([1-9](_?[0-9])*|0)(?![\w\.])</match>
153     </context>
154
155     <!-- in double quotes and backticks -->
156     <!-- FIXME: really would like for the syntax highlight to go back
157          to none here, as any ruby code could go here -->
158     <context id="complex-interpolation" style-ref="escape">
159       <start>{</start>
160       <end>}</end>
161       <include>
162         <context ref="nit:*"/>
163       </include>
164     </context>
165
166     <!-- ruby strings do not end at line end,
167          so we cannot use def:string
168          (parts lifted from perl.lang) -->
169     <context id="double-quoted-string" style-ref="string">
170       <start>"</start>
171       <end>"</end>
172       <include>
173         <context ref="escape"/>
174         <context ref="def:line-continue"/>
175         <context ref="complex-interpolation"/>
176       </include>
177     </context>
178
179     <context id="single-quoted-string" style-ref="string">
180       <start>'</start>
181       <end>'</end>
182       <include>
183         <context style-ref="escape">
184           <match>\\['\\]</match>
185         </context>
186       </include>
187     </context>
188
189     <context id="backtick-quoted-string" style-ref="string">
190       <start>`</start>
191       <end>`</end>
192       <include>
193         <context ref="escape"/>
194         <context ref="def:line-continue"/>
195         <context ref="complex-interpolation"/>
196       </include>
197     </context>
198
199     <context id="nit">
200       <include>
201         <context ref="def:shebang"/>
202         <context ref="def:shell-like-comment"/>
203         <context ref="double-quoted-string"/>
204         <context ref="single-quoted-string"/>
205         <context ref="backtick-quoted-string"/>
206         <context ref="definitions"/>
207         <context ref="module-handlers"/>
208         <context ref="keywords"/>
209         <context ref="special-variables"/>
210         <context ref="instance-variables"/>
211         <context ref="class-name"/>
212         <context ref="null-value"/>
213         <context ref="boolean"/>
214         <context ref="float"/>
215         <context ref="decimal"/>
216       </include>
217     </context>
218
219   </definitions>
220 </language>