<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2013-2015 The Rust Project Developers.

Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
option. This file may not be copied, modified, or distributed
except according to those terms.
-->

<!-- Syntax highlighting for the Rust language -->

<language id="rust" _name="Rust" version="2.0" _section="Sources">
  <metadata>
    <property name="mimetypes">text/rust</property>
    <property name="globs">*.rs</property>
    <property name="line-comment-start">//</property>
    <property name="block-comment-start">/*</property>
    <property name="block-comment-end">*/</property>
  </metadata>

  <styles>
    <style id="comment" _name="Comment" map-to="def:comment"/>
    <style id="string" _name="String" map-to="def:string"/>
    <style id="char" _name="Character" map-to="def:character"/>
    <style id="keyword" _name="Keyword" map-to="def:keyword"/>
    <style id="type" _name="Data Type" map-to="def:type"/>
    <style id="constant" _name="Constant" map-to="def:constant"/>
    <style id="identifier" _name="Identifier" map-to="def:identifier"/>
    <style id="number" _name="Number" map-to="def:number"/>
    <style id="scope" _name="Scope" map-to="def:preprocessor"/>
    <style id="attribute" _name="Attribute" map-to="def:preprocessor"/>
    <style id="macro" _name="Macro" map-to="def:preprocessor"/>
  </styles>

  <definitions>

    <context id="function" style-ref="keyword">
		<keyword>fn</keyword>
    </context>

    <context id="type" style-ref="keyword">
		<keyword>type</keyword>
    </context>

    <context id="keywords" style-ref="keyword">
		<keyword>abstract</keyword>
		<keyword>alignof</keyword>
		<keyword>as</keyword>
		<keyword>become</keyword>
		<keyword>box</keyword>
		<keyword>break</keyword>
		<keyword>const</keyword>
		<keyword>continue</keyword>
		<keyword>crate</keyword>
		<keyword>do</keyword>
		<keyword>else</keyword>
		<keyword>enum</keyword>
		<keyword>extern</keyword>
		<keyword>final</keyword>
		<keyword>for</keyword>
		<keyword>if</keyword>
		<keyword>impl</keyword>
		<keyword>in</keyword>
		<keyword>let</keyword>
		<keyword>loop</keyword>
		<keyword>macro</keyword>
		<keyword>match</keyword>
		<keyword>mod</keyword>
		<keyword>move</keyword>
		<keyword>mut</keyword>
		<keyword>offsetof</keyword>
		<keyword>override</keyword>
		<keyword>priv</keyword>
		<keyword>proc</keyword>
		<keyword>pub</keyword>
		<keyword>pure</keyword>
		<keyword>ref</keyword>
		<keyword>return</keyword>
		<keyword>sizeof</keyword>
		<keyword>static</keyword>
		<keyword>struct</keyword>
		<keyword>super</keyword>
		<keyword>trait</keyword>
		<keyword>typeof</keyword>
		<keyword>unsafe</keyword>
		<keyword>unsized</keyword>
		<keyword>use</keyword>
		<keyword>virtual</keyword>
		<keyword>where</keyword>
		<keyword>while</keyword>
		<keyword>yield</keyword>
    </context>

    <context id="types" style-ref="type">
		<keyword>bool</keyword>
		<keyword>isize</keyword>
		<keyword>usize</keyword>
		<keyword>i8</keyword>
		<keyword>i16</keyword>
		<keyword>i32</keyword>
		<keyword>i64</keyword>
		<keyword>u8</keyword>
		<keyword>u16</keyword>
		<keyword>u32</keyword>
		<keyword>u64</keyword>
		<keyword>f32</keyword>
		<keyword>f64</keyword>
		<keyword>char</keyword>
		<keyword>str</keyword>
    </context>

    <context id="self" style-ref="identifier">
		<keyword>Self</keyword>
		<keyword>self</keyword>
    </context>

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

    <context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" class-disabled="no-spell-check">
      <start>//</start>
      <include>
        <context ref="def:in-line-comment"/>
      </include>
    </context>

    <context id="block-comment" style-ref="comment" class="comment" class-disabled="no-spell-check">
      <start>/\*</start>
      <end>\*/</end>
      <include>
        <context ref="def:in-comment"/>
      </include>
    </context>

    <define-regex id="int_suffix" extended="true">
      (i8|i16|i32|i64|i|u8|u16|u32|u64|u)
    </define-regex>

    <define-regex id="exponent" extended="true">
      ([eE][+-]?[0-9_]+)
    </define-regex>

    <define-regex id="float_suffix" extended="true">
      (\%{exponent}?(f32|f64)?)|(\.[0-9][0-9_]*\%{exponent}?)?(f32|f64)?|\.
    </define-regex>

    <define-regex id="num_suffix" extended="true">
      \%{int_suffix}|\%{float_suffix}
    </define-regex>

    <define-regex id="hex_digit" extended="true">
      [0-9a-fA-F]
    </define-regex>

    <define-regex id="oct_digit" extended="true">
      [0-7]
    </define-regex>

    <context id="number" style-ref="number">
      <match extended="true">
        ((?&lt;=\.\.)|(?&lt;![\w\.]))
        (
        [1-9][0-9_]*\%{num_suffix}?|
        0[0-9_]*\%{num_suffix}?|
        0b[01_]+\%{int_suffix}?|
        0o(\%{oct_digit}|_)+\%{int_suffix}?|
        0x(\%{hex_digit}|_)+\%{int_suffix}?
        )
        ((?![\w\.].)|(?=\.\.))
      </match>
    </context>

    <define-regex id="ident" extended="true">
      ([^[:cntrl:][:space:][:punct:][:digit:]]|_)([^[:cntrl:][:punct:][:space:]]|_)*
    </define-regex>

    <context id="scope" style-ref="scope">
      <match extended="true">
        \%{ident}::
      </match>
    </context>

    <context id="macro" style-ref="macro">
      <match extended="true">
        \%{ident}!
      </match>
    </context>

    <context id="lifetime" style-ref="keyword">
      <match extended="true">
        '\%{ident}
      </match>
    </context>

    <define-regex id="common_escape" extended="true">
      '|"|
      \\|n|r|t|0|
      x\%{hex_digit}{2}
    </define-regex>

    <define-regex id="unicode_escape" extended="true">
      u{\%{hex_digit}{1,6}}
    </define-regex>

    <context id="string_escape" style-ref="def:special-char">
      <match>\\\%{common_escape}|\\\%{unicode_escape}</match>
    </context>

    <context id="byte_string_escape" style-ref="def:special-char">
      <match>\\\%{common_escape}</match>
    </context>

    <context id="raw-string" style-ref="string" class="string" class-disabled="no-spell-check">
      <start>b?r(#*)"</start>
      <end>"\%{1@start}</end>
      <include>
        <context ref="def:line-continue"/>
      </include>
    </context>

    <context id="string" style-ref="string" class="string" class-disabled="no-spell-check">
      <start>"</start>
      <end>"</end>
      <include>
        <context ref="string_escape"/>
        <context ref="def:line-continue"/>
      </include>
    </context>

    <context id="byte_string" style-ref="string" class="string" class-disabled="no-spell-check">
      <start>b"</start>
      <end>"</end>
      <include>
        <context ref="byte_string_escape"/>
        <context ref="def:line-continue"/>
      </include>
    </context>

    <context id="char" style-ref="char">
      <match extended="true">'([^\\']|\\\%{common_escape}|\\\%{unicode_escape})'</match>
    </context>

    <context id="byte" style-ref="char">
      <match extended="true">b'([^\\']|\\\%{common_escape})'</match>
    </context>

    <context id="attribute" style-ref="attribute" class="attribute">
      <start extended="true">\#!?\[</start>
      <end>\]</end>
      <include>
        <context ref="def:in-comment"/>
        <context ref="string"/>
        <context ref="raw-string"/>
      </include>
    </context>

    <context id="rust" class="no-spell-check">
      <include>
        <context ref="function"/>
        <context ref="type"/>
        <context ref="keywords"/>
        <context ref="types"/>
        <context ref="self"/>
        <context ref="macro"/>
        <context ref="constants"/>
        <context ref="line-comment"/>
        <context ref="block-comment"/>
        <context ref="number"/>
        <context ref="scope"/>
        <context ref="string"/>
        <context ref="byte_string"/>
        <context ref="raw-string"/>
        <context ref="char"/>
        <context ref="byte"/>
        <context ref="lifetime"/>
        <context ref="attribute"/>
      </include>
    </context>

  </definitions>

</language>
