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

 This file is part of GtkSourceView

 Authors: Ignacio Casal Quinteiro
 Copyright (C) 2009 Ignacio Casal Quinteiro <icq@gnome.org>

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

 GtkSourceView 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
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

-->
<language id="prolog" _name="Prolog" version="2.0" _section="Sources">
  <metadata>
    <property name="mimetypes">text/x-prolog</property>
    <property name="globs">*.prolog</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="variable"          _name="Variable"          map-to="def:type"/>
    <style id="keyword"           _name="Keyword"           map-to="def:keyword"/>
    <style id="string"            _name="String"            map-to="def:string"/>
    <style id="number"            _name="Number"            map-to="def:decimal"/>
    <style id="operator"          _name="Operator"          map-to="def:operator"/>
    <style id="error"             _name="Error"             map-to="def:error"/>
    <style id="escaped-character" _name="Escaped Character" map-to="def:special-char"/>
  </styles>

  <definitions>
    
    <define-regex id="symbolchar">[-!+\\|=:&amp;&gt;&lt;]</define-regex>

    <define-regex id="escaped-character" extended="true">
            \\(                   # leading backslash
            [\\\"\'nrbtfav\?] |   # escaped character
            [0-7]{1,3} |          # one, two, or three octal digits
            x[0-9A-Fa-f]+         # 'x' followed by hex digits
            )
    </define-regex>

    <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-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>
    
    <context id="close-comment-outside-comment" style-ref="error">
      <match>\*/(?!\*)</match>
    </context>

    <context id="variable" style-ref="variable">
      <match>\b(_|[A-Z][A-Za-z0-9_]*)\b</match>
    </context>
    
    <context id="operators" style-ref="operator">
      <prefix>(?&lt;!\%{symbolchar})</prefix>
      <suffix>(?!\%{symbolchar})</suffix>
      <keyword>=</keyword>
      <keyword>==</keyword>
      <keyword>=\\=</keyword>
      <keyword>=:=</keyword>
      <keyword>\|</keyword>
      <keyword>&lt;</keyword>
      <keyword>&gt;</keyword>
      <keyword>=&lt;</keyword>
      <keyword>&gt;=</keyword>
      <keyword>\\=</keyword>
      <keyword>\\==</keyword>
      <keyword>\\\+</keyword>
    </context>
    
    <context id="special-operators" style-ref="operator">
      <match>([!;]|:\-)</match>
    </context>

    <context id="escaped-character" style-ref="escaped-character">
          <match>\%{escaped-character}</match>
    </context>

    <context id="string" style-ref="string" end-at-line-end="true" class="string" class-disabled="no-spell-check">
      <start>"</start>
      <end>"</end>
      <include>
        <context ref="escaped-character"/>
      </include>
    </context>

    <context id="string2" style-ref="string" end-at-line-end="true" class="string" class-disabled="no-spell-check">
      <start>'</start>
      <end>'</end>
      <include>
        <context ref="escaped-character"/>
      </include>
    </context>

    <context id="number" style-ref="number">
      <match extended="true">
        \b[0-9]+(\.[0-9]+)?\b
      </match>
    </context>

    <context id="arith" style-ref="keyword">
      <keyword>mod</keyword>
      <keyword>div</keyword>
      <keyword>abs</keyword>
      <keyword>exp</keyword>
      <keyword>ln</keyword>
      <keyword>log</keyword>
      <keyword>sqrt</keyword>
      <keyword>round</keyword>
      <keyword>trunc</keyword>
      <keyword>val</keyword>
      <keyword>cos</keyword>
      <keyword>sin</keyword>
      <keyword>tan</keyword>
      <keyword>arctan</keyword>
      <keyword>random</keyword>
      <keyword>randominit</keyword>
    </context>

    <context id="keyword" style-ref="keyword">
      <keyword>module</keyword>
      <keyword>meta_predicate</keyword>
      <keyword>multifile</keyword>
      <keyword>dynamic</keyword>
      <keyword>abolish</keyword>
      <keyword>current_output</keyword>
      <keyword>peek_code</keyword>
      <keyword>append</keyword>
      <keyword>current_predicate</keyword>
      <keyword>put_byte</keyword>
      <keyword>arg</keyword>
      <keyword>current_prolog_flag</keyword>
      <keyword>put_char</keyword>
      <keyword>asserta</keyword>
      <keyword>assert</keyword>
      <keyword>fail</keyword>
      <keyword>put_code</keyword>
      <keyword>assertz</keyword>
      <keyword>findall</keyword>
      <keyword>read</keyword>
      <keyword>at_end_of_stream</keyword>
      <keyword>float</keyword>
      <keyword>read_term</keyword>
      <keyword>atom</keyword>
      <keyword>flush_output</keyword>
      <keyword>repeat</keyword>
      <keyword>atom_chars</keyword>
      <keyword>functor</keyword>
      <keyword>retract</keyword>
      <keyword>atom_codes</keyword>
      <keyword>get_byte</keyword>
      <keyword>set_input</keyword>
      <keyword>atom_concat</keyword>
      <keyword>get_char</keyword>
      <keyword>set_output</keyword>
      <keyword>atom_length</keyword>
      <keyword>get_code</keyword>
      <keyword>set_prolog_flag</keyword>
      <keyword>atomic</keyword>
      <keyword>halt</keyword>
      <keyword>set_stream_position</keyword>
      <keyword>bagof</keyword>
      <keyword>integer</keyword>
      <keyword>setof</keyword>
      <keyword>call</keyword>
      <keyword>is</keyword>
      <keyword>stream_property</keyword>
      <keyword>catch</keyword>
      <keyword>nl</keyword>
      <keyword>sub_atom</keyword>
      <keyword>char_code</keyword>
      <keyword>nonvar</keyword>
      <keyword>throw</keyword>
      <keyword>char_conversion</keyword>
      <keyword>number</keyword>
      <keyword>clause</keyword>
      <keyword>number_chars</keyword>
      <keyword>unify_with_occurs_check</keyword>
      <keyword>close</keyword>
      <keyword>number_codes</keyword>
      <keyword>var</keyword>
      <keyword>compound</keyword>
      <keyword>once</keyword>
      <keyword>copy_term</keyword>
      <keyword>op</keyword>
      <keyword>write</keyword>
      <keyword>writeln</keyword>
      <keyword>write_canonical</keyword>
      <keyword>write_term</keyword>
      <keyword>writeq</keyword>
      <keyword>current_char_conversion</keyword>
      <keyword>open</keyword>
      <keyword>current_input</keyword>
      <keyword>peek_byte</keyword>
      <keyword>current_op</keyword>
      <keyword>peek_char</keyword>
      <keyword>false</keyword>
      <keyword>true</keyword>
      <keyword>consult</keyword>
      <keyword>member</keyword>
      <keyword>memberchk</keyword>
      <keyword>reverse</keyword>
      <keyword>permutation</keyword>
      <keyword>delete</keyword>
    </context>

    <context id="prolog" class="no-spell-check">
      <include>
        <context ref="keyword"/>
        <context ref="arith"/>
        <context ref="number"/>
        <context ref="string"/>
        <context ref="string2"/>
        <context ref="special-operators"/>
        <context ref="operators"/>
        <context ref="variable"/>
        <context ref="block-comment"/>
        <context ref="line-comment"/>
        <context ref="close-comment-outside-comment"/>
      </include>
    </context>

  </definitions>
</language>
