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

The Why3 Verification Platform   /   The Why3 Development Team
Copyright 2010-2013   -    INRIA - CNRS - Paris-Sud University

This software is distributed under the terms of the GNU Lesser
General Public License version 2.1, with the special exception
on linking described in file LICENSE.

-->
<!--
 This file was based on ocaml.lang by
 Copyright (C) 2007 Eric Cooper <ecc@cmu.edu>
 Copyright (C) 2007 Eric Norige <thelema314@gmail.com>
-->
<language id="why3c" _name="Why3microC" version="2.0" _section="Sources">
  <metadata>
    <property name="mimetypes">text/x-why3c</property>
    <property name="globs">*.c</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="base-n-integer" _name="Base-N Integer" map-to="def:base-n-integer"/>
    <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="string" _name="String" map-to="def:string"/>
    <style id="keyword" _name="Keyword" map-to="def:keyword"/>
    <style id="meta-keyword" _name="Type, module or object keyword" map-to="def:keyword"/>
    <style id="fun-keyword" _name="Builtin-function keyword" map-to="def:keyword"/>
    <style id="type" _name="Data Type" map-to="def:type"/>
    <style id="label" _name="Labeled argument" map-to="def:type"/>
<!--
    <style id="poly-variant" _name="Polymorphic Variant" map-to="def:type"/>
-->
    <style id="variant" _name="Variant Constructor" map-to="def:type"/>
    <style id="type-var" _name="Type Variable" map-to="def:type"/>
    <style id="module" _name="Module Path" map-to="def:type"/>
    <style id="escape" _name="Escaped Character" map-to="def:special-char"/>
    <style id="boolean" _name="Boolean value" map-to="def:boolean"/>
    <style id="spec-keyword" _name="Specification keyword" map-to="def:shebang"/>
    <style id="error" _name="Error" map-to="def:error"/>
  </styles>

  <definitions>
    <define-regex id="cap-ident">\b[A-Z][A-Za-z0-9_']*</define-regex>
    <define-regex id="low-ident">\b[a-z][A-Za-z0-9_']*</define-regex>
    <define-regex id="char-esc">\\((\\|"|'|n|t|b|r)|[0-9]{3}|x[0-9a-fA-F]{2})</define-regex>
    <!-- " -->
    <context id="escape-seq" style-ref="escape">
      <match>\%{char-esc}</match>
    </context>
    <!-- here's the main context -->
    <context id="why3c">
      <include>
	<context id="symbol-star">
	  <match>\(\*\)</match>
	</context>
	<context id="comment" style-ref="comment">
	  <start>\(\*</start>
	  <end>\*\)</end>
	  <include>
	    <context ref="symbol-star"/>
	    <context id="comment-in-comment" style-ref="comment">
	      <start>\(\*</start>
	      <end>\*\)</end>
	      <include>
		<context ref="string"/>
		<context ref="symbol-star"/>
		<context ref="comment-in-comment"/>
		<context ref="def:in-comment:*"/>
	      </include>
	    </context>
	    <context ref="string"/>
	    <context ref="def:in-comment:*"/>
	  </include>
	</context>
        <context id="comment2" style-ref="comment">
	  <start>//[^@]</start>
	  <end>$</end>
	  <include>
	    <context ref="symbol-star"/>
	    <context ref="string"/>
	    <context ref="def:in-comment:*"/>
	  </include>
	</context>
        <context id="prepro" style-ref="string">
	  <start>#</start>
	  <end>$</end>
	  <include>
	    <context ref="symbol-star"/>
	    <context ref="string"/>
	    <context ref="def:in-comment:*"/>
	  </include>
	</context>
	<context id="decimal" style-ref="decimal">
	  <match>[-]?[0-9][0-9_]*[lLn]?</match>
	</context>
	<context id="hex-number" style-ref="base-n-integer">
	  <match>[-]?0[xX][0-9A-Fa-f][0-9A-Fa-f_]*[lL]?</match>
	</context>
	<context id="octal-number" style-ref="base-n-integer">
	  <match>[-]?0[oO][0-7][0-7_]*[lL]?</match>
	</context>
	<context id="binary-number" style-ref="base-n-integer">
	  <match>[-]?0[bB][01][01_]*[lL]?</match>
	</context>
	<context id="floating-point-number" style-ref="floating-point">
	  <match>[-]?[0-9][0-9_]*(\.[0-9_]*)?([Ee][+-]?[0-9][0-9_]*)?</match>
	</context>
        <context id="attributes" style-ref="string">
          <start>\[\@</start>
          <end>\]</end>
        </context>
<!--
	<context id="label" style-ref="label">
	  <match>[~?]\%{low-ident}</match>
	</context>
	<context id="poly-variant" style-ref="poly-variant">
	  <match>`\%{cap-ident}</match>
	</context>
-->
	<context id="modpath" style-ref="module">
	  <!-- include final '.'?  At the moment, no.  -->
	  <match>\%{cap-ident}(\.\%{cap-ident})*(?=\.)</match>
	</context>
	<context id="variant" style-ref="variant">
	  <match>\%{cap-ident}</match>
	</context>
	<context id="string" style-ref="string">
	  <start>"</start>
	  <end>"</end>
	  <include>
	    <context ref="escape-seq"/>
	  </include>
	</context>
<!--
	<context id="character-constant" style-ref="string">
	  <match>('\%{char-esc}')|('[^\\']')</match>
	</context>
-->
	<context id="type-var" style-ref="type-var">
	  <match>'\%{low-ident}</match>
	</context>
	<context id="recordlit">
	  <start>\{</start>
	  <end>\}</end>
	  <include>
	    <context ref="why3c"/>
	  </include>
	</context>
	<context id="badrecord" style-ref="error" extend-parent="false">
	  <match>}</match>
	</context>
<!--
	<context id="arraylit">
	  <start>\[\|</start>
	  <end>\|\]</end>
	  <include>
	    <context ref="why3c"/>
	  </include>
	</context>
	<context id="badarray" style-ref="error" extend-parent="false">
	  <match>\|\]</match>
	</context>
	<context id="listlit">
	  <start>\[</start>
	  <end>(?&lt;!\|)\]</end>
	  <include>
	    <context ref="why3c"/>
	  </include>
	</context>
	<context id="badlist" style-ref="error" extend-parent="false">
	  <match>\]</match>
	</context>
-->
	<context id="keywords" style-ref="meta-keyword">
          <keyword>abstract</keyword>
          <keyword>as</keyword>
          <keyword>axiom</keyword>
          <keyword>clone</keyword>
          <keyword>coinductive</keyword>
          <keyword>constant</keyword>
          <keyword>end</keyword>
          <keyword>exception</keyword>
          <keyword>export</keyword>
          <keyword>function</keyword>
          <keyword>goal</keyword>
          <keyword>ghost</keyword>
          <keyword>import</keyword>
          <keyword>inductive</keyword>
          <keyword>lemma</keyword>
          <keyword>meta</keyword>
          <keyword>mutable</keyword>
          <keyword>module</keyword>
          <keyword>predicate</keyword>
          <keyword>private</keyword>
          <keyword>scope</keyword>
          <keyword>theory</keyword>
          <keyword>type</keyword>
          <keyword>use</keyword>
          <keyword>val</keyword>
          <keyword>with</keyword>
	</context>
	<context id="meta-words" style-ref="keyword">
          <keyword>any</keyword>
          <keyword>begin</keyword>
          <keyword>break</keyword>
          <keyword>by</keyword>
          <keyword>continue</keyword>
          <keyword>do</keyword>
          <keyword>done</keyword>
          <keyword>downto</keyword>
          <keyword>else</keyword>
          <keyword>exists</keyword>
          <keyword>for</keyword>
          <keyword>forall</keyword>
          <keyword>fun</keyword>
          <keyword>if</keyword>
          <keyword>in</keyword>
          <keyword>label</keyword>
          <keyword>let</keyword>
          <keyword>loop</keyword>
          <keyword>match</keyword>
          <keyword>not</keyword>
          <keyword>raise</keyword>
          <keyword>rec</keyword>
          <keyword>return</keyword>
          <keyword>so</keyword>
          <keyword>then</keyword>
          <keyword>to</keyword>
          <keyword>try</keyword>
          <keyword>while</keyword>
	  <keyword>-&gt;</keyword>
	</context>
	<context id="spec" style-ref="spec-keyword">
          <keyword>absurd</keyword>
          <keyword>alias</keyword>
          <keyword>assert</keyword>
          <keyword>assume</keyword>
          <keyword>at</keyword>
	  <keyword>diverges</keyword>
	  <keyword>ensures</keyword>
	  <keyword>check</keyword>
	  <keyword>invariant</keyword>
	  <keyword>old</keyword>
	  <keyword>pure</keyword>
	  <keyword>raises</keyword>
	  <keyword>reads</keyword>
	  <keyword>requires</keyword>
	  <keyword>returns</keyword>
	  <keyword>variant</keyword>
	  <keyword>writes</keyword>
	</context>
	<context id="bool-const" style-ref="boolean">
	  <keyword>true</keyword>
	  <keyword>false</keyword>
	</context>
	<context id="types" style-ref="type">
	  <keyword>array</keyword>
	  <keyword>bool</keyword>
	  <keyword>int</keyword>
	  <keyword>list</keyword>
	  <keyword>map</keyword>
	  <keyword>option</keyword>
 	  <keyword>real</keyword>
	  <keyword>ref</keyword>
	  <keyword>unit</keyword>
	  <keyword>void</keyword>
	</context>
	<context id="var">
	  <match>\%{low-ident}</match>
	</context>
      </include>
    </context>
  </definitions>
</language>
