8edd22e650439aeaafa41608d2132d7ecd07c7a7
[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     <style id="extern-code"          _name="Extern code"           map-to="def:comment"/>
53   </styles>
54
55   <definitions>
56
57     <context id="escape" style-ref="escape">
58       <match>\\((0-7){3}|(x[a-fA-F0-9]{2})|(c\S)|([CM]-\S)|(M-C-\S)|.)</match>
59     </context>
60
61     <context id="extern-code" style-ref="extern-code">
62         <start>`\{</start>
63         <end>`\}</end>
64         <include>
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>module</keyword>
75       <keyword>type</keyword>
76       <keyword>universal</keyword>
77       <keyword>enum</keyword>
78     </context>
79
80     <context id="module-handlers" style-ref="module-handler">
81       <keyword>import</keyword>
82     </context>
83
84     <context id="keywords" style-ref="keyword">
85       <keyword>do</keyword>
86       <keyword>end</keyword>
87       <keyword>intrude</keyword>
88       <keyword>private</keyword>
89       <keyword>if</keyword>
90       <keyword>then</keyword>
91       <keyword>else</keyword>
92       <keyword>while</keyword>
93       <keyword>for</keyword>
94       <keyword>assert</keyword>
95       <keyword>is</keyword>
96       <keyword>abstract</keyword>
97       <keyword>intern</keyword>
98       <keyword>extern</keyword>
99       <keyword>public</keyword>
100       <keyword>protected</keyword>
101       <keyword>or</keyword>
102       <keyword>as</keyword>
103       <keyword>isa</keyword>
104       <keyword>break</keyword>
105       <keyword>continue</keyword>
106       <keyword>return</keyword>
107       <keyword>label</keyword>
108       <keyword>abort</keyword>
109       <keyword>nullable</keyword>
110       <keyword>new</keyword>
111       <keyword>special</keyword>
112       <keyword>super</keyword>
113       <keyword>init</keyword>
114       <keyword>in</keyword>
115       <keyword>or</keyword>
116       <keyword>and</keyword>
117       <keyword>not</keyword>
118       <keyword>writable</keyword>
119       <keyword>readable</keyword>
120     </context>
121
122     <context id="special-variables" style-ref="special-variable">
123       <keyword>self</keyword>
124     </context>
125
126     <context id="instance-variables" style-ref="variable">
127       <match>(::)?\b_[a-zA-Z_][a-zA-Z0-9_]*</match>
128     </context>
129
130     <context id="class-name" style-ref="class-name">
131       <match>(::)?\b[A-Z][A-Za-z0-9_]*\b</match>
132     </context>
133
134     <context id="null-value" style-ref="null-value">
135       <keyword>null</keyword>
136     </context>
137
138     <context id="boolean" style-ref="boolean">
139       <keyword>false</keyword>
140       <keyword>true</keyword>
141     </context>
142     
143     <define-regex id="underscore_num">\d(_?\d)*</define-regex>
144
145     <define-regex id="float" extended="true">
146       ( (\%{underscore_num})?\.\%{underscore_num} | \%{underscore_num}\. ) |
147       ( (\%{underscore_num}|(\%{underscore_num})?\.\%{underscore_num}|\%{underscore_num}\.)[eE][+-]?\%{underscore_num} )
148     </define-regex>
149
150     <context id="float" style-ref="floating-point">
151       <match>(?&lt;![\w\.])\%{float}(?![\w\.])</match>
152     </context>
153
154     <context id="decimal" style-ref="decimal">
155       <match>(?&lt;![\w\.])([1-9](_?[0-9])*|0)(?![\w\.])</match>
156     </context>
157
158     <!-- in double quotes and backticks -->
159     <!-- FIXME: really would like for the syntax highlight to go back
160          to none here, as any ruby code could go here -->
161     <context id="complex-interpolation" style-ref="escape">
162       <start>{</start>
163       <end>}</end>
164       <include>
165         <context ref="nit:*"/>
166       </include>
167     </context>
168
169     <!-- ruby strings do not end at line end,
170          so we cannot use def:string
171          (parts lifted from perl.lang) -->
172     <context id="double-quoted-string" style-ref="string">
173       <start>"</start>
174       <end>"</end>
175       <include>
176         <context ref="escape"/>
177         <context ref="def:line-continue"/>
178         <context ref="complex-interpolation"/>
179       </include>
180     </context>
181
182     <context id="single-quoted-string" style-ref="string">
183       <start>'</start>
184       <end>'</end>
185       <include>
186         <context style-ref="escape">
187           <match>\\['\\]</match>
188         </context>
189       </include>
190     </context>
191
192     <context id="nit">
193       <include>
194         <context ref="def:shebang"/>
195         <context ref="def:shell-like-comment"/>
196         <context ref="double-quoted-string"/>
197         <context ref="single-quoted-string"/>
198         <context ref="definitions"/>
199         <context ref="module-handlers"/>
200         <context ref="keywords"/>
201         <context ref="special-variables"/>
202         <context ref="instance-variables"/>
203         <context ref="class-name"/>
204         <context ref="null-value"/>
205         <context ref="boolean"/>
206         <context ref="float"/>
207         <context ref="decimal"/>
208         <context ref="extern-code"/>
209       </include>
210     </context>
211
212   </definitions>
213 </language>