<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is created based on "ruby.lang" which is part of GtkSourceView.
-->

<language id="ngraph-math" _name="ngraph mathematics transformation" version="2.0" _section="Script">
  <metadata>
    <property name="mimetypes">text/x-ngraph-math</property>
    <property name="line-comment-start">#</property>
  </metadata>

  <styles>
    <style id="keyword"              _name="Keyword"               map-to="def:keyword"/>
    <style id="comment"              _name="Comment"               map-to="def:comment"/>
    <style id="floating-point"       _name="Floating point number" map-to="def:floating-point"/>
    <style id="decimal"              _name="Decimal number"        map-to="def:floating-point"/>
    <style id="base-n-integer"       _name="Base-N number"         map-to="def:base-n-integer"/>
    <style id="builtin"              _name="Builtin"               map-to="def:function"/>
    <style id="constant"             _name="Constant"              map-to="def:constant"/>
    <style id="operator"             _name="Operator"              map-to="def:operator"/>
    <style id="parameter"            _name="Parameter"             map-to="def:identifier"/>
    <style id="string-variable"      _name="String Variable"       map-to="def:preprocessor"/>
    <style id="special-variable"     _name="Special Variable"      map-to="def:type"/>
    <style id="special-constants"    _name="Special Constant"      map-to="def:constant"/>
    <style id="string"               _name="String"                map-to="def:string"/>
    <style id="escape"               _name="Escaped Character"     map-to="def:special-char"/>
  </styles>

  <default-regex-options case-sensitive="false"/>

  <definitions>

    <context id="keywords" style-ref="keyword">
      <keyword>def</keyword>
      <keyword>const</keyword>
    </context>

    <context id="parameters" style-ref="parameter">
      <match>(%f[0-9]{3,5})|(%[0-9]{1,3})</match>
    </context>

    <context id="special-constants" style-ref="constant">
      <match>%[ND]</match>
    </context>

    <context id="string-variables" style-ref="string-variable">
      <match>\$[_a-zA-Z]\w*</match>
    </context>

    <context id="special-variables" style-ref="special-variable">
      <keyword>x</keyword>
      <keyword>y</keyword>
      <keyword>col</keyword>
    </context>

    <context id="escape" style-ref="escape">
      <match>\\([0-7]{1,3}|(x[a-fA-F0-9]{1,2})|.)</match>
    </context>

    <context id="complex-interpolation">
      <start>#{</start>
      <end>}</end>
      <include>
        <context ref="ngraph-math:*"/>
      </include>
    </context>

    <context id="inside-interpolated-string">
      <include>
	<context ref="escape"/>
        <context ref="complex-interpolation"/>
      </include>
    </context>

    <context id="double-quoted-string" style-ref="string" class="string" class-disabled="no-spell-check">
      <start>"</start>
      <end>"</end>
      <include>
        <context ref="inside-interpolated-string"/>
      </include>
    </context>

    <context id="single-quoted-string" style-ref="string" class="string" class-disabled="no-spell-check">
      <start>'</start>
      <end>'</end>
      <include>
        <context style-ref="escape">
          <match>\\['\\]</match>
        </context>
      </include>
    </context>

    <define-regex id="underscore_num">\d( ?\d)*</define-regex>

    <define-regex id="float" extended="true">
      ( \%{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>

    <context id="hex" style-ref="base-n-integer">
      <match>(?&lt;![\w\.])0[xX][0-9A-Fa-f]( ?[0-9A-Fa-f])*(?![\w\.])</match>
    </context>

    <context id="octal" style-ref="base-n-integer">
      <match>(?&lt;![\w\.])0[oO][0-7]( ?[0-7])*(?![\w\.])</match>
    </context>

    <context id="binary" style-ref="base-n-integer">
      <match>(?&lt;![\w\.])0[bB][01]( ?[01])*(?![\w\.])</match>
    </context>

    <context id="operators" style-ref="operator" extend-parent="false">
      <match>(([-^/\+\*\!\=:\\&lt;&gt;|&amp;]|(&gt;&gt;)|(&lt;&lt;))\=)|([-^/\+\*\!\=\\&lt;&gt;|&amp;~])|(&lt;&lt;)|(&gt;&gt;)|(&amp;&amp;)|(\|\|)</match>
    </context>
