misc: gtksourceview nit syntax highlighting
[nit.git] / misc / gtksourceview / nit.lang
diff --git a/misc/gtksourceview/nit.lang b/misc/gtksourceview/nit.lang
new file mode 100644 (file)
index 0000000..d38655b
--- /dev/null
@@ -0,0 +1,220 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Author: Alexis Laferrière <alexis.laf@xymus.net>
+ Copyright (C) 2009 Alexis Laferrière <alexis.laf@xymus.net>
+
+ Based on ruby.lang
+ Copyright (C) 2004 Archit Baweja <bighead@users.sourceforge.net>
+ Copyright (C) 2005 Michael Witrant <mike@lepton.fr>
+ Copyright (C) 2006 Gabriel Bauman <gbauman@gmail.com>
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+-->
+<language id="nit" _name="Nit" version="2.0" _section="Sources">
+  <metadata>
+    <property name="mimetypes">text/x-nit</property>
+    <property name="globs">*.nit</property>
+    <property name="line-comment-start">#</property>
+  </metadata>
+
+  <styles>
+    <style id="escape"               _name="Escaped Character"     map-to="def:special-char"/>
+    <style id="comment"              _name="Comment"               map-to="def:comment"/>
+    <style id="attribute-definition" _name="Attribute Definition"  map-to="def:statement"/>
+    <style id="module-handler"       _name="Module handler"        map-to="def:preprocessor"/>
+    <style id="keyword"              _name="Keyword"               map-to="def:keyword"/>
+    <style id="null-value"           _name="Nil Constant"          map-to="def:special-constant"/>
+    <style id="boolean"              _name="Boolean value"         map-to="def:boolean"/>
+    <style id="floating-point"       _name="Floating point number" map-to="def:floating-point"/>
+    <style id="decimal"              _name="Decimal number"        map-to="def:decimal"/>
+    <style id="base-n-integer"       _name="Base-N number"         map-to="def:base-n-integer"/>
+    <style id="string"               _name="String"                map-to="def:string"/>
+    <style id="builtin"              _name="Builtin"               map-to="def:type"/>
+    <style id="class-name"           _name="Constant"              map-to="def:type"/>
+    <style id="symbol"               _name="Symbol"                map-to="def:string"/>
+    <style id="special-variable"     _name="Special Variable"      map-to="def:identifier"/>
+    <style id="predefined-variable"  _name="Predefined Variable"   map-to="def:identifier"/>
+    <style id="variable"             _name="Variable"              map-to="def:identifier"/>
+  </styles>
+
+  <definitions>
+
+    <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="multiline-comment" style-ref="comment">
+      <start>^=begin</start>
+      <end>^=end</end>
+      <include>
+        <context ref="escape"/>
+        <context ref="def:in-comment"/>
+      </include>
+    </context>
+
+    <context id="definitions" style-ref="keyword">
+      <keyword>class</keyword>
+      <keyword>fun</keyword>
+      <keyword>redef</keyword>
+      <keyword>var</keyword>
+      <keyword>package</keyword>
+    </context>
+
+    <context id="module-handlers" style-ref="module-handler">
+      <keyword>import</keyword>
+    </context>
+
+    <context id="keywords" style-ref="keyword">
+      <keyword>do</keyword>
+      <keyword>end</keyword>
+      <keyword>intrude</keyword>
+      <keyword>private</keyword>
+      <keyword>if</keyword>
+      <keyword>then</keyword>
+      <keyword>else</keyword>
+      <keyword>while</keyword>
+      <keyword>for</keyword>
+      <keyword>assert</keyword>
+      <keyword>is</keyword>
+      <keyword>abstract</keyword>
+      <keyword>intern</keyword>
+      <keyword>extern</keyword>
+      <keyword>public</keyword>
+      <keyword>protected</keyword>
+      <keyword>or</keyword>
+      <keyword>as</keyword>
+      <keyword>isa</keyword>
+      <keyword>break</keyword>
+      <keyword>continue</keyword>
+      <keyword>return</keyword>
+      <keyword>label</keyword>
+      <keyword>abort</keyword>
+      <keyword>nullable</keyword>
+      <keyword>new</keyword>
+      <keyword>special</keyword>
+      <keyword>super</keyword>
+      <keyword>init</keyword>
+      <keyword>in</keyword>
+      <keyword>or</keyword>
+      <keyword>and</keyword>
+      <keyword>not</keyword>
+      <keyword>writable</keyword>
+      <keyword>readable</keyword>
+    </context>
+
+    <context id="special-variables" style-ref="special-variable">
+      <keyword>self</keyword>
+    </context>
+
+    <context id="instance-variables" style-ref="variable">
+      <match>(::)?\b_[a-zA-Z_][a-zA-Z0-9_]*</match>
+    </context>
+
+    <context id="class-name" style-ref="class-name">
+      <match>(::)?\b[A-Z][A-Za-z0-9_]*\b</match>
+    </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>
+    
+    <define-regex id="underscore_num">\d(_?\d)*</define-regex>
+
+    <define-regex id="float" extended="true">
+      ( (\%{underscore_num})?\.\%{underscore_num} | \%{underscore_num}\. ) |
+      ( (\%{underscore_num}|(\%{underscore_num})?\.\%{underscore_num}|\%{underscore_num}\.)[eE][+-]?\%{underscore_num} )
+    </define-regex>
+
+    <context id="float" style-ref="floating-point">
+      <match>(?&lt;![\w\.])\%{float}(?![\w\.])</match>
+    </context>
+
+    <context id="decimal" style-ref="decimal">
+      <match>(?&lt;![\w\.])([1-9](_?[0-9])*|0)(?![\w\.])</match>
+    </context>
+
+    <!-- in double quotes and backticks -->
+    <!-- FIXME: really would like for the syntax highlight to go back
+         to none here, as any ruby code could go here -->
+    <context id="complex-interpolation" style-ref="escape">
+      <start>{</start>
+      <end>}</end>
+      <include>
+        <context ref="nit:*"/>
+      </include>
+    </context>
+
+    <!-- ruby strings do not end at line end,
+         so we cannot use def:string
+         (parts lifted from perl.lang) -->
+    <context id="double-quoted-string" style-ref="string">
+      <start>"</start>
+      <end>"</end>
+      <include>
+        <context ref="escape"/>
+        <context ref="def:line-continue"/>
+        <context ref="complex-interpolation"/>
+      </include>
+    </context>
+
+    <context id="single-quoted-string" style-ref="string">
+      <start>'</start>
+      <end>'</end>
+      <include>
+        <context style-ref="escape">
+          <match>\\['\\]</match>
+        </context>
+      </include>
+    </context>
+
+    <context id="backtick-quoted-string" style-ref="string">
+      <start>`</start>
+      <end>`</end>
+      <include>
+        <context ref="escape"/>
+        <context ref="def:line-continue"/>
+        <context ref="complex-interpolation"/>
+      </include>
+    </context>
+
+    <context id="nit">
+      <include>
+        <context ref="def:shebang"/>
+        <context ref="def:shell-like-comment"/>
+        <context ref="double-quoted-string"/>
+        <context ref="single-quoted-string"/>
+        <context ref="backtick-quoted-string"/>
+        <context ref="definitions"/>
+        <context ref="module-handlers"/>
+        <context ref="keywords"/>
+        <context ref="special-variables"/>
+        <context ref="instance-variables"/>
+        <context ref="class-name"/>
+        <context ref="null-value"/>
+        <context ref="boolean"/>
+        <context ref="float"/>
+        <context ref="decimal"/>
+      </include>
+    </context>
+
+  </definitions>
+</language>