<?xml version="1.0" encoding="UTF-8"?>
<!--
 Author: Christian Troost
 Copyright (C) 2015 Christian Troost

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

<language id="mpmasql_dat" _name="mpmasql (.dat)" version="2.0" _section="mpmasql">
  <metadata>
    <property name="mimetypes">text/mpmasql-dat</property>
    <property name="globs">*.dat</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="error" _name="Error" map-to="def:error"/>
    <style id="keyword" _name="Keyword" map-to="def:identifier"/>
    <style id="headline" _name="Headline" map-to="def:keyword"/>
    <style id="statement" _name="Statement" map-to="def:type"/>
    <style id="operator" _name="Statement" map-to="def:type"/>
    <style id="function" _name="Function" map-to="def:type"/>
    <style id="localvar" _name="Function" map-to="def:function"/>
     <style id="class_def" _name="Class Definition" />
     <style id="rtext" _name="Class Definition" map-to="def:underlined"/>
     <style id="infotext" _name="Info text" />
      <style id="userwarn" _name="Warningtext" map-to="def:note"/>

     <style id="string" _name="Class Definition" map-to="def:string"/>
     <style id="special-char" _name="Class Definition" map-to="def:special-char"/>
     <style id="floating-point" _name="Class Definition" map-to="def:string"/>
     <style id="vartab" _name="Tab" />
     <style id="varparam" _name="Parameter"  />
 </styles>

 <definitions>

  <context id="comment" style-ref="comment" class="comment" class-disabled="no-spell-check">
      <start>/\*</start>
      <end>\*/</end>
      <include>
        <context style-ref="error" extend-parent="false">
          <match>/\*</match>
        </context>
        <context ref="def:in-comment"/>
      </include>
    </context>
    
     <context id="any-text" style-ref="infotext"  extend-parent="false">
	    <match>.*</match>
    </context>

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

    
      <context id="escape" style-ref="special-char">
            <match>\\.</match>
        </context>

        <!-- usual quoted string, ends at line end, \ is an escape char -->
      
       
    <context id="empty" >
      <match>^\s*$</match>
    </context>
    
    <context id="anything-else" style-ref="error"  extend-parent="false" >
	    <match>.*</match>
    </context> 
    
    
        
    <context id="mpmasql_marpa_expression">
	<include>
	 <define-regex id="operator" extended="true">
	    \-|\+|\*|\^|\/|~|==|!=|&gt;|&lt;|&gt;=|&lt;=|&amp;&amp;|\|\|
	</define-regex>
	  <context ref="def:decimal"/>
	  <context ref="def:float"/>
	  
	    <context id="string" style-ref="string" end-at-line-end="false" class="string" class-disabled="no-spell-check">
            <start>"</start>
            <end>"</end>
            <include>
                <context ref="escape"/>
               <!-- <context ref="line-continue"/>-->
               
            </include>
        </context>
	  <context id="operator" style-ref="operator"><!-- see `man perlop` -->
		<match>\%{operator}</match>
	  </context>
	  <context id="written_operator" style-ref="keyword">
		<keyword>except</keyword>
		<keyword>fits_the_pattern</keyword>
		<keyword>is_element_of</keyword>
		<keyword>equals</keyword>
		<keyword>does_not_equal</keyword>
		<keyword>all</keyword>
		<keyword>where</keyword>
		<keyword>in</keyword>

	  </context>
	  

	  
	  <context id="mpmasql_key" style-ref="keyword">
	    <prefix>\#</prefix>
	    <keyword>annuityFactor</keyword>
	    <keyword>cartesian_concat</keyword>
	    <keyword>cartesian_power_concat</keyword>
	    <keyword>classifyToMultiple</keyword>
	    <keyword>classify_to_multiple</keyword>
	    <keyword>count</keyword>
	    <keyword>distinct_values_in_column</keyword>
	    <keyword>e</keyword>
	    <keyword>financeFrmDepreciationAtAge</keyword>
	    <keyword>financeFrmPrincipalPaidAtAge</keyword>
	    <keyword>financeFrmRate</keyword>
	    <keyword>financeFrmTimeValueFactor</keyword>
	    
	    <keyword>floor</keyword>
	    <keyword>foreach</keyword>
		<keyword>fromMaxXYtoZ</keyword>
		<keyword>fromXtoMinYZ</keyword>


	    <keyword>fvalue</keyword>
	    <keyword>ifalone</keyword>
	    <keyword>if_elsif</keyword>
	    <keyword>ifthenelse</keyword>
	    <keyword>if</keyword>

	    <keyword>intersection</keyword>

	    <keyword>is_equal</keyword>
	    <keyword>is_part_of</keyword>
	    <keyword>lengthOfText</keyword>
	    <keyword>list_concat</keyword>
	    <keyword>list</keyword>
	    <keyword>ln</keyword>
	    <keyword>mapcell</keyword>
	    <keyword>max</keyword>
	    <keyword>min</keyword>
   	    <keyword>mperiodsThrough</keyword>
   	    <keyword>mperiodsAfter</keyword>
   	    <keyword>mod</keyword>


	    <keyword>normlike</keyword>
	    <keyword>partOfText</keyword>
	    <keyword>product</keyword>
	    <keyword>protected_divide</keyword>
	    <keyword>qlist</keyword>
	    <keyword>random_number</keyword>
	    <keyword>regexp</keyword>
	    <keyword>ifnull</keyword>
	    <keyword>report</keyword>
	    <keyword>round_to</keyword>
	    <keyword>sequence</keyword>
    	    <keyword>set_mapping</keyword>
	    <keyword>steps</keyword>
	    <keyword>union</keyword>

	    <keyword>var</keyword>

	  </context>
	  
	  
	  <context id="userwarn" style-ref="userwarn" end-at-line-end="false">
	  <start>(#warn|#error)\(</start>
	  <end>\)</end>
	  <include> 
		  		  <context id="wwarn" sub-pattern="1" where="start" style-ref="function"/>

		  <context ref="any-text" style-ref="userwarn" />

		  </include>
		  
	  </context>
	  
	</include>
    </context>
    
    
    
    
    
    
    
     <context id="section-heading" style-ref="class_def" end-at-line-end="false">
	    <start>^\s*(#section|#subsection|#subsubsection)\s*</start>
	    <end>(?=^#section|^#subsection|^#subsubsection|^#info|^#table|^#global|^#simulationRun_parameter)</end>
	    
	    <include>
		  <context id="wsection" sub-pattern="1" where="start" style-ref="statement"/>
     	  <context ref="empty"/>
	      <context ref="any-text" style-ref="headline"/>
	     <context ref="anything-else"/>

	    </include>
    </context>
    
         <context id="info-section" style-ref="class_def" end-at-line-end="false">
	    <start>^\s*(#info)</start>
	    <end>(?=^#section|^#subsection|^#subsubsection|^#info|^#table|^#global|^#simulationRun_parameter)</end>
	    
	    <include>
		  <context id="winfo" sub-pattern="1" where="start" style-ref="statement"/>	     
	      <context ref="comment"/>
	     <context ref="any-text"/>


	    </include>
    </context>
    
     <context id="global-def" style-ref="class_def" end-at-line-end="false">
	    <start>^\s*(#global)\s*(\w+)\s*=</start>
	    	    <end>(?=^#section|^#subsection|^#subsubsection|^#info|^#table|^#global|^#simulationRun_parameter)</end>

	    <include>
		 <context id="parameter_w0" sub-pattern="1" where="start" style-ref="statement"/>
	     <context id="parameter_w1" sub-pattern="2" where="start" style-ref="varparam"/>
		  <context ref="mpmasql_marpa_expression:*" />

		 </include>
    </context>
     <context id="simrunp-def" style-ref="class_def" end-at-line-end="false">
	    <start>^\s*(#simulationRun_parameter)\s*(\w+)\s*</start>
	    	    <end>(?=^#section|^#subsection|^#subsubsection|^#info|^#table|^#global|^#simulationRun_parameter)</end>

	    <include>
		 <context id="parameter_w0" sub-pattern="1" where="start" style-ref="statement"/>
	     <context id="parameter_w1" sub-pattern="2" where="start" style-ref="varparam"/>
		  <context ref="mpmasql_marpa_expression:*" />

		 </include>
    </context>
         <context id="global-set-def" style-ref="class_def" end-at-line-end="false">
	    <start>^\s*(#global_set)\s*(\w+)\s*=</start>
	    	    <end>(?=^#section|^#subsection|^#subsubsection|^#info|^#table|^#global|^#simulationRun_parameter)</end>

	    <include>
		 <context id="parameter_w0" sub-pattern="1" where="start" style-ref="statement"/>
	     <context id="parameter_w1" sub-pattern="2" where="start" style-ref="varparam"/>
		  <context ref="mpmasql_marpa_expression:*" />

	    </include>
    </context>
    

	     <context id="bracketed-tabdef" end-parent="true"> 
		  <start>\s*\{\s*</start>
		  <end>\s*\}\s*</end>
		  <include>
			      <context ref="comment"/>
			      <context ref="close-comment-outside-comment" />
			      <!--<context ref="empty" end-parent="true"/>-->
			      <context ref="mpmasql_marpa_expression:*" />
		  </include>
	     </context> 




    <context id="user-table-def" style-ref="class_def">
	    <start>^(#table)\s*(\w+)\s+=?\s*\(\s*(ascii|sql|here|sparql|spreadsheet|swapped_keys|recombine|merge)\s*,\s*\d+\s*\)</start>
	    	    <end>(?=^#section|^#subsection|^#subsubsection|^#info|^#table|^#global|^#simulationRun_parameter)</end>

	    <include>
		<context id="parameter_w0" sub-pattern="1" where="start" style-ref="statement"/>
	     <context id="parameter_w1" sub-pattern="2" where="start" style-ref="rtext"/>
	     <context id="parameter_w2" sub-pattern="3" where="start" style-ref="keyword"/>
	     <context ref="bracketed-tabdef"/>
			      <context ref="mpmasql_marpa_expression:*" />
     			      <context ref="comment"/>

	   </include>
    </context>
  
    
   
 
   
    
   <context id="mpmasql_dat">
      <include>
	<context ref="section-heading"/>
	
	 <context ref="info-section"/>
	 <context ref="user-table-def"/>
	 <context ref="global-def"/>
     <context ref="global-set-def"/>
     <context ref="simrunp-def"/>
	 <context ref="comment"/>
	 <context ref="empty" />
	 <context ref="anything-else"/>

	 <context ref="close-comment-outside-comment" />

      </include>
    </context>


</definitions>
</language>
