<?xml version="1.0" encoding="UTF-8"?>
<!--

 Author: John Spray <jcspray@icculus.org>
 Copyright (C) 2004, 2005, 2006 John Spray <jcs116@york.ac.uk>
 Copyright (C) 2005 Jerry DeLisle <jvdelisle@verizon.net>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public
 License as published by the Free Software Foundation; either
 version 2 of the License, or (at your option) any later version.

 This library 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
 Library General Public License for more details.

 You should have received a copy of the GNU Library General Public
 License along with this library; if not, write to the
 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.

-->
<language id="fortran" _name="Fortran 95" version="2.0" _section="Sources">
  <metadata>
    <property name="mimetypes">text/x-fortran</property>
    <property name="globs">*.f;*.f9[05];*.for</property>
    <property name="line-comment-start">!</property>
  </metadata>

  <styles>
    <style id="comment" _name="Comment" map-to="def:comment"/>
    <style id="floating-point" _name="Floating Point" map-to="def:floating-point"/>
    <style id="keyword" _name="Keyword" map-to="def:keyword"/>
    <style id="boz-literal" _name="BOZ Literal" map-to="def:base-n-integer"/>
    <style id="decimal" _name="Decimal" map-to="def:decimal"/>
    <style id="type" _name="Data Type" map-to="def:type"/>
  </styles>

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

  <definitions>

    <!-- Note: contains an hack to avoid considering ^COMMON a comment -->
    <context id="line-comment" style-ref="comment" end-at-line-end="true">
      <start>!|(^[Cc](\b|[^Oo]))</start>
      <include>
        <context ref="def:escape"/>
        <context ref="def:in-line-comment"/>
      </include>
    </context>

    <context id="operators" style-ref="keyword">
      <prefix>\.</prefix>
      <suffix>\.</suffix>
      <keyword>TRUE</keyword>
      <keyword>FALSE</keyword>
      <keyword>NOT</keyword>
      <keyword>AND</keyword>
      <keyword>OR</keyword>
      <keyword>XOR</keyword>
      <keyword>EQV</keyword>
      <keyword>NEQV</keyword>
      <keyword>EQ</keyword>
      <keyword>NE</keyword>
      <keyword>GT</keyword>
      <keyword>GE</keyword>
      <keyword>LT</keyword>
      <keyword>LE</keyword>
    </context>

    <context id="keywords" style-ref="keyword">
      <keyword>block data</keyword>
      <keyword>CALL</keyword>
      <keyword>case</keyword>
      <keyword>common</keyword>
      <keyword>contains</keyword>
      <keyword>continue</keyword>
      <keyword>cycle</keyword>
      <keyword>data</keyword>
      <keyword>do</keyword>
      <keyword>elseif</keyword>
      <keyword>else</keyword>
      <keyword>elsewhere</keyword>
      <keyword>enddo</keyword>
      <keyword>endif</keyword>
      <keyword>end</keyword>
      <keyword>external</keyword>
      <keyword>forall</keyword>
      <keyword>function</keyword>
      <keyword>goto</keyword>
      <keyword>if</keyword>
      <keyword>implicit none</keyword>
      <keyword>include</keyword>
      <keyword>intrinsic</keyword>
      <keyword>kind</keyword>
      <keyword>len</keyword>
      <keyword>module</keyword>
      <keyword>program</keyword>
      <keyword>return</keyword>
      <keyword>save</keyword>
      <keyword>SELECT</keyword>
      <keyword>stop</keyword>
      <keyword>subroutine</keyword>
      <keyword>then</keyword>
      <keyword>type</keyword>
      <keyword>use</keyword>
      <keyword>where</keyword>
      <keyword>while</keyword>
    </context>

    <context id="read-write" style-ref="keyword">
      <keyword>backspace</keyword>
      <keyword>close</keyword>
      <keyword>inquire</keyword>
      <keyword>open</keyword>
      <keyword>rewind</keyword>
      <keyword>endfile</keyword>
      <keyword>read</keyword>
      <keyword>write</keyword>
      <keyword>print</keyword>
    </context>

    <context id="input-output" style-ref="keyword">
      <keyword>unit</keyword>
      <keyword>file</keyword>
      <keyword>iostat</keyword>
      <keyword>access</keyword>
      <keyword>blank</keyword>
      <keyword>fmt</keyword>
      <keyword>form</keyword>
      <keyword>recl</keyword>
      <keyword>status</keyword>
      <keyword>exist</keyword>
      <keyword>opened</keyword>
      <keyword>number</keyword>
      <keyword>named</keyword>
      <keyword>name</keyword>
      <keyword>sequential</keyword>
      <keyword>direct</keyword>
      <keyword>rec</keyword>
      <keyword>formatted</keyword>
      <keyword>unformatted</keyword>
      <keyword>nextrec</keyword>
      <keyword>pad</keyword>
      <keyword>position</keyword>
      <keyword>action</keyword>
      <keyword>delim</keyword>
      <keyword>readwrite</keyword>
      <keyword>eor</keyword>
      <keyword>advance</keyword>
      <keyword>nml</keyword>
    </context>

    <context id="intrinsics" style-ref="keyword">
      <keyword>adjustl</keyword>
      <keyword>adjustr</keyword>
      <keyword>all</keyword>
      <keyword>allocated</keyword>
      <keyword>any</keyword>
      <keyword>associated</keyword>
      <keyword>bit_size</keyword>
      <keyword>btest</keyword>
      <keyword>ceiling</keyword>
      <keyword>count</keyword>
      <keyword>cshift</keyword>
      <keyword>date_and_time</keyword>
      <keyword>digits</keyword>
      <keyword>dim</keyword>
      <keyword>dot_product</keyword>
      <keyword>dprod</keyword>
      <keyword>eoshift</keyword>
      <keyword>epsilon</keyword>
      <keyword>exponent</keyword>
      <keyword>floor</keyword>
      <keyword>fraction</keyword>
      <keyword>huge</keyword>
      <keyword>iand</keyword>
      <keyword>ibclr</keyword>
      <keyword>ibits</keyword>
      <keyword>ibset</keyword>
      <keyword>ieor</keyword>
      <keyword>ior</keyword>
      <keyword>ishft</keyword>
      <keyword>ishftc</keyword>
      <keyword>lbound</keyword>
      <keyword>len_trim</keyword>
      <keyword>matmul</keyword>
      <keyword>maxexponent</keyword>
      <keyword>maxloc</keyword>
      <keyword>maxval</keyword>
      <keyword>merge</keyword>
      <keyword>minexponent</keyword>
      <keyword>minloc</keyword>
      <keyword>minval</keyword>
      <keyword>modulo</keyword>
      <keyword>mvbits</keyword>
      <keyword>nearest</keyword>
      <keyword>pack</keyword>
      <keyword>present</keyword>
      <keyword>product</keyword>
      <keyword>radix</keyword>
      <keyword>random_number</keyword>
      <keyword>random_seed</keyword>
      <keyword>range</keyword>
      <keyword>repeat</keyword>
      <keyword>reshape</keyword>
      <keyword>rrspacing</keyword>
      <keyword>scale</keyword>
      <keyword>selected_int_kind</keyword>
      <keyword>selected_real_kind</keyword>
      <keyword>scan</keyword>
      <keyword>shape</keyword>
      <keyword>size</keyword>
      <keyword>spacing</keyword>
      <keyword>spread</keyword>
      <keyword>set_exponent</keyword>
      <keyword>tiny</keyword>
      <keyword>transpose</keyword>
      <keyword>trim</keyword>
      <keyword>ubound</keyword>
      <keyword>unpack</keyword>
      <keyword>verify</keyword>
      <keyword>precision</keyword>
      <keyword>sum</keyword>
      <keyword>system_clock</keyword>
      <keyword>abs</keyword>
      <keyword>acos</keyword>
      <keyword>aimag</keyword>
      <keyword>aint</keyword>
      <keyword>anint</keyword>
      <keyword>asin</keyword>
      <keyword>atan</keyword>
      <keyword>atan2</keyword>
      <keyword>cos</keyword>
      <keyword>sin</keyword>
      <keyword>tan</keyword>
      <keyword>sinh</keyword>
      <keyword>cosh</keyword>
      <keyword>tanh</keyword>
      <keyword>exp</keyword>
      <keyword>log</keyword>
      <keyword>log10</keyword>
      <keyword>sign</keyword>
      <keyword>sqrt</keyword>
      <keyword>int</keyword>
      <keyword>cmplx</keyword>
      <keyword>nint</keyword>
      <keyword>min</keyword>
      <keyword>max</keyword>
      <keyword>conjg</keyword>
      <keyword>char</keyword>
      <keyword>ichar</keyword>
      <keyword>index</keyword>
      <keyword>cabs</keyword>
      <keyword>ccos</keyword>
      <keyword>cexp</keyword>
      <keyword>clog</keyword>
      <keyword>csin</keyword>
      <keyword>csqrt</keyword>
      <keyword>dacos</keyword>
      <keyword>dasin</keyword>
      <keyword>datan</keyword>
      <keyword>datan2</keyword>
      <keyword>dcos</keyword>
      <keyword>dcosh</keyword>
      <keyword>ddim</keyword>
      <keyword>dexp</keyword>
      <keyword>dint</keyword>
      <keyword>dlog</keyword>
      <keyword>dlog10</keyword>
      <keyword>dmod</keyword>
      <keyword>dabs</keyword>
      <keyword>dnint</keyword>
      <keyword>dsign</keyword>
      <keyword>dsin</keyword>
      <keyword>dsinh</keyword>
      <keyword>dsqrt</keyword>
      <keyword>dtan</keyword>
      <keyword>dtanh</keyword>
      <keyword>iabs</keyword>
      <keyword>idim</keyword>
      <keyword>idnint</keyword>
      <keyword>isign</keyword>
      <keyword>idint</keyword>
      <keyword>ifix</keyword>
      <keyword>amax0</keyword>
      <keyword>amax1</keyword>
      <keyword>dmax1</keyword>
      <keyword>max0</keyword>
      <keyword>max1</keyword>
      <keyword>amin0</keyword>
      <keyword>amin1</keyword>
      <keyword>dmin1</keyword>
      <keyword>loc</keyword>
      <keyword>min0</keyword>
      <keyword>min1</keyword>
      <keyword>amod</keyword>
      <keyword>float</keyword>
      <keyword>sngl</keyword>
      <keyword>alog</keyword>
      <keyword>alog10</keyword>
      <keyword>cdabs</keyword>
      <keyword>cdcos</keyword>
      <keyword>cdexp</keyword>
      <keyword>cdlog</keyword>
      <keyword>cdsin</keyword>
      <keyword>cdsqrt</keyword>
      <keyword>cqabs</keyword>
      <keyword>cqcos</keyword>
      <keyword>cqexp</keyword>
      <keyword>cqlog</keyword>
      <keyword>cqsin</keyword>
      <keyword>cqsqrt</keyword>
      <keyword>qacos</keyword>
      <keyword>qasin</keyword>
      <keyword>qatan</keyword>
      <keyword>qatan2</keyword>
      <keyword>qcos</keyword>
      <keyword>qcosh</keyword>
      <keyword>qdim</keyword>
      <keyword>qexp</keyword>
      <keyword>iqint</keyword>
      <keyword>qlog</keyword>
      <keyword>qlog10</keyword>
      <keyword>qmod</keyword>
      <keyword>qabs</keyword>
      <keyword>qnint</keyword>
      <keyword>qsign</keyword>
      <keyword>qsin</keyword>
      <keyword>qsinh</keyword>
      <keyword>qsqrt</keyword>
      <keyword>qtan</keyword>
      <keyword>qtanh</keyword>
      <keyword>qmax1</keyword>
      <keyword>qmin1</keyword>
      <keyword>dimag</keyword>
      <keyword>qimag</keyword>
      <keyword>dcmplx</keyword>
      <keyword>qcmplx</keyword>
      <keyword>dconjg</keyword>
      <keyword>qconjg</keyword>
      <keyword>gamma</keyword>
      <keyword>dgamma</keyword>
      <keyword>qgamma</keyword>
      <keyword>algama</keyword>
      <keyword>dlgama</keyword>
      <keyword>qlgama</keyword>
      <keyword>erf</keyword>
      <keyword>derf</keyword>
      <keyword>qerf</keyword>
      <keyword>erfc</keyword>
      <keyword>derfc</keyword>
      <keyword>qerfc</keyword>
      <keyword>dfloat</keyword>
      <keyword>zabs</keyword>
      <keyword>zcos</keyword>
      <keyword>zexp</keyword>
      <keyword>zlog</keyword>
      <keyword>zsin</keyword>
      <keyword>zsqrt</keyword>
    </context>

    <context id="types" style-ref="type">
      <keyword>REAL</keyword>
      <keyword>INTEGER</keyword>
      <keyword>CHARACTER</keyword>
      <keyword>LOGICAL</keyword>
      <keyword>COMPLEX</keyword>
      <keyword>DOUBLE PRECISION</keyword>
      <keyword>DOUBLE COMPLEX</keyword>
      <keyword>BYTE</keyword>
      <keyword>dimension</keyword>
      <keyword>parameter</keyword>
      <keyword>intent</keyword>
      <keyword>private</keyword>
      <keyword>optional</keyword>
      <keyword>pointer</keyword>
      <keyword>target</keyword>
      <keyword>allocatable</keyword>
    </context>

    <context id="floating-point-number" style-ref="floating-point">
      <match extended="true">
        (?&lt;![\w\.])
        [+-]?
        ((\.[0-9]+ | [0-9]+\.[0-9]*) ([ed][+-]?[0-9]*)? |
         ([0-9]+[ed][+-]?[0-9]*))
        (?![\w\.])
      </match>
    </context>

    <context id="decimal" style-ref="decimal">
      <match extended="true">
        (?&lt;![\w\.])
        [+-]? ([1-9][0-9]*|0)
        (?![\w\.])
      </match>
    </context>

    <context id="boz-literal" style-ref="boz-literal">
      <match extended="true">
        \bb'[01]+'|\bb"[01]+"|
        \bo'[0-7]+'|\bo"[0-7]+"|
        \bz'[0-9a-f]+'|\bz"[0-9a-f]+"
      </match>
    </context>

    <context id="fortran">
      <include>
        <context ref="floating-point-number"/>
        <context ref="decimal"/>
        <context ref="boz-literal"/>
        <context ref="def:string"/>
        <context ref="def:single-quoted-string"/>
        <context ref="line-comment"/>
        <context ref="operators"/>
        <context ref="keywords"/>
        <context ref="read-write"/>
        <context ref="input-output"/>
        <context ref="intrinsics"/>
        <context ref="types"/>
      </include>
    </context>

  </definitions>
</language>
