<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<!--
   This should be part of the KDE project
   Copyright (C) 2005 Helmut Wollmersdorfer <helmut@wollmersdorfer.at>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   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; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   *** NOTICE ***
   This file is based on perl.xml by Anders Lund <anders@alweb.dk> from the kate project.

   *** TODO ***
   - remove remaining 'perlishms'
   - check against the growing list of keywords, functions and operators of qore
   - check/add objects support
   - submit to the KDE project
   - new-syntax support, var detection without leading $
   - check tab&space mix detection
   - regex highlight
-->

<language name="Qore" version="0.5" kateversion="3.5" section="Scripts" extensions="*.q;*qc;*.ql;*qsd;*qclass;*qconst;*qwf;*qfd" mimetype="application/x-qore;text/x-qore" author="Helmut Wollmersdorfer (helmut@wollmersdorfer.at)" license="LGPL">
  <highlighting>
    <list name="keywords">
      <item> switch </item>
      <item> case </item>
      <item> default </item>
      <item> inherits </item>
      <item> class </item>
      <item> private </item>
      <item> public </item>
      <item> synchronized </item>
      <item> where </item>
      <item> do </item>
      <item> while </item>
      <item> if </item>
      <item> else </item>
      <item> for </item>
      <item> foreach </item>
      <item> const </item>
      <item> namespace </item>
      <item> return </item>
      <item> my </item>
      <item> our </item>
      <item> try </item>
      <item> throw </item>
      <item> catch </item>
      <item> find </item>
      <item> thread_exit </item>
      <item> in </item>
      <item> sub </item>
      <item> context </item>
      <item> sortBy </item>
      <item> sortDescendingBy </item>
      <item> NULL </item>
      <item> NOTHING </item>
      <item> summarize </item>
      <item> by </item>
      <item> subcontext </item>
      <item> break </item>
      <item> continue </item>
      <item> module </item>
      <item> final </item>
      <item> static </item>
      <item> deprecated </item>
      <item> rethrow </item>
      <item> abstract </item>
      <item> on_error </item>
      <item> on_exit </item>
      <item> on_success </item>
      <item> thread_exit </item>
    </list>
    <list name="types">
      <item> int </item>
      <item> float </item>
      <item> number </item>
      <item> bool </item>
      <item> string </item>
      <item> date </item>
      <item> timeout </item>
      <item> binary </item>
      <item> hash </item>
      <item> list </item>
      <item> object </item>
      <item> null </item>
      <item> nothing </item>
      <item> timeout </item>
      <item> softint </item>
      <item> softfloat </item>
      <item> softnumber </item>
      <item> softbool </item>
      <item> softstring </item>
      <item> softdate </item>
      <item> softlist </item>
      <item> data </item>
      <item> callref </item>
      <item> closure </item>
      <item> code </item>
      <item> reference </item> 
      <item> any </item>
    </list>
    <!-- just words have meaning -->
    <list name="operators">
      <item> . </item>
      <item> ++ </item>
      <item> -- </item>
      <item> new </item>
      <item> background </item>
      <item> delete </item>
      <item> remove </item>
      <item> cast </item>
      <item> ! </item>
      <item> ~ </item>
      <item> - </item>
      <item> shift </item>
      <item> pop </item>
      <item> chomp </item>
      <item> trim </item>
      <item> elements </item>
      <item> keys </item>
      <item> * </item>
      <item> / </item>
      <item> % </item>
      <item> + </item>
      <item> &gt;&gt; </item>
      <item> &lt;&lt; </item>
      <item> exists </item>
      <item> instanceof </item>
      <item> &lt; </item>
      <item> &gt; </item>
      <item> == </item>
      <item> != </item>
      <item> &lt;= </item>
      <item> &gt;= </item>
      <item> &lt;=&gt; </item>
      <item> === </item>
      <item> !== </item>
      <item> =~ </item>
      <item> !~ </item>
      <item> &amp; </item>
      <item> ^ </item>
      <item> | </item>
      <item> &amp;&amp; </item>
      <item> || </item>
      <item> ? </item>
      <item> : </item>
      <item> ?? </item>
      <item> ?* </item>
      <item> , </item>
      <item> unshift </item>
      <item> push </item>
      <item> splice </item>
      <item> extract </item>
      <item> map </item>
      <item> foldl </item>
      <item> foldr </item>
      <item> select </item>
      <item> = </item>
      <item> += </item>
      <item> -= </item>
      <item> &amp;= </item>
      <item> |= </item>
      <item> %= </item>
      <item> *= </item>
      <item> /= </item>
      <item> ^= </item>
      <item> &lt;&lt;= </item>
      <item> &gt;&gt;= </item>      
    </list>
    <!-- not used -->
    <list name="functions">
      <item>abort</item>
      <item>abs</item>
      <item>acos</item>
      <item>asin</item>
      <item>atan</item>
      <item>backquote</item>
      <item>binary</item>
      <item>boolean</item>
      <item>callObjectMethod</item>
      <item>callObjectMethodArgs</item>
      <item>call_function</item>
      <item>cbrt</item>
      <item>ceil</item>
      <item>chmod</item>
      <item>chr</item>
      <item>className</item>
      <item>clock_getmicros</item>
      <item>clock_getmillis</item>
      <item>clock_getnanos</item>
      <item>close</item>
      <item>close_file</item>
      <item>convert_encoding</item>
      <item>cos</item>
      <item>cosh</item>
      <item>create_file</item>
      <item>date</item>
      <item>eof</item>
      <item>errno</item>
      <item>existsFunction</item>
      <item>exit</item>
      <item>exp</item>
      <item>exp2</item>
      <item>expm1</item>
      <item>f_printf</item>
      <item>f_sprintf</item>
      <item>fflush</item>
      <item>float</item>
      <item>floor</item>
      <item>fork</item>
      <item>format_date</item>
      <item>format_number</item>
      <item>functionType</item>
      <item>getClass</item>
      <item>getFeatureList</item>
      <item>getMethodList</item>
      <item>getModuleList</item>
      <item>get_default_encoding</item>
      <item>get_encoding</item>
      <item>get_thread_data</item>
      <item>getegid</item>
      <item>geteuid</item>
      <item>getenv</item>
      <item>getgid</item>
      <item>gethostname</item>
      <item>getpid</item>
      <item>getppid</item>
      <item>getpwuid</item>
      <item>gettid</item>
      <item>getuid</item>
      <item>glob</item>
      <item>gmtime</item>
      <item>hash</item>
      <item>html_decode</item>
      <item>html_encode</item>
      <item>hypot</item>
      <item>index</item>
      <item>int</item>
      <item>kill</item>
      <item>length</item>
      <item>list</item>
      <item>localtime</item>
      <item>log10</item>
      <item>log1p</item>
      <item>logb</item>
      <item>lstat</item>
      <item>makeBase64String</item>
      <item>makeXMLFragment</item>
      <item>makeXMLRPCCallString</item>
      <item>makeXMLRPCFaultResponseString</item>
      <item>makeXMLRPCResponseString</item>
      <item>makeXMLRPCValueString</item>
      <item>makeXMLString</item>
      <item>mkdir</item>
      <item>mkfifo</item>
      <item>mktime</item>
      <item>nlog</item>
      <item>now</item>
      <item>num_threads</item>
      <item>open</item>
      <item>ord</item>
      <item>parse</item>
      <item>parseBase64String</item>
      <item>parseURL</item>
      <item>parseXML</item>
      <item>pow</item>
      <item>print</item>
      <item>printf</item>
      <item>rand</item>
      <item>regex</item>
      <item>replace</item>
      <item>rindex</item>
      <item>rmdir</item>
      <item>save_thread_data</item>
      <item>setenv</item>
      <item>sin</item>
      <item>sinh</item>
      <item>sleep</item>
      <item>socket_accept</item>
      <item>socket_bind</item>
      <item>socket_close</item>
      <item>socket_connect</item>
      <item>socket_getrecvtimeout</item>
      <item>socket_getsendtimeout</item>
      <item>socket_listen</item>
      <item>socket_recv</item>
      <item>socket_send</item>
      <item>socket_setrecvtimeout</item>
      <item>socket_setsendtimeout</item>
      <item>sort</item>
      <item>sortDescending</item>
      <item>split</item>
      <item>sprintf</item>
      <item>sqrt</item>
      <item>srand</item>
      <item>stat</item>
      <item>strerror</item>
      <item>string</item>
      <item>strlen</item>
      <item>substr</item>
      <item>system</item>
      <item>tan</item>
      <item>tanh</item>
      <item>thread_list</item>
      <item>timegm</item>
      <item>tolower</item>
      <item>toupper</item>
      <item>type</item>
      <item>typename</item>
      <item>umask</item>
      <item>unlink</item>
      <item>unsetenv</item>
      <item>usleep</item>
      <item>vprintf</item>
      <item>vsprintf</item>
    </list>
    <contexts>
      <context name="normal" attribute="Normal Text" lineEndContext="#stay"> 
        <RegExpr attribute="Directive" context="directive_params" String="^%ifdef" beginRegion="Region" />
        <RegExpr attribute="Directive" context="directive_params" String="^%ifndef" beginRegion="Region" />
        <RegExpr attribute="Directive" context="directive_params" String="^%else" beginRegion="Region" endRegion="Region" />
        <RegExpr attribute="Directive" context="directive_params" String="^%endif" endRegion="Region" />

        <RegExpr attribute="Directive" context="directive_params" String="^%[a-z]+[a-z0-9\-]*" />
	<!-- mixed space and tab -->
        <RegExpr attribute="Invisible" context="#stay" String=" +\t" />
	<RegExpr attribute="Invisible" context="#stay" String="\t+ " />

        <keyword attribute="Keyword" context="#stay" String="keywords" />
        <keyword attribute="Operator word" context="#stay" String="operators" />
        <keyword attribute="Type" context="#stay" String="types" />
        <DetectChar attribute="Operator" context="string" char="&quot;" />
        <DetectChar attribute="Operator" context="simple_string" char="'" />

        <DetectChar attribute="String (interpolated)" context="backtick" char="`" />

        <RegExpr attribute="Keyword" context="sub_name_def" String="\bsub\s+" />

        <RegExpr attribute="Object Member" context="var_detect" String="\$\.[a-zA-Z][a-zA-Z0-9_]*" />
        <Detect2Chars attribute="Variable" context="#stay" char="$" char1="#" />
        <StringDetect attribute="Bool" context="#stay" String="False" />
        <StringDetect attribute="Bool" context="#stay" String="True" />

        <AnyChar attribute="Variable" context="var_detect" String="$" />
        
	<!-- YYYY-MM-DD[THH:mm:SS[.n*]][Z|[+-]HH[:mm[:SS]]] -->
	<!-- YYYY-MM-DD[-HH:mm:SS[.n*]][Z|[+-]HH[:mm[:SS]]] -->
        <RegExpr attribute="Date" context="#stay" String="\d{4}\-\d{2}\-\d{2}([T-]\d{2}:\d{2}:\d{2}(\.\d{1,6})?)?(Z|[+-]\d{2}(:\d{2}(:\d{2})?)?)?" />
	<!-- relative time -->
        <RegExpr attribute="Date" context="#stay" String="\d+(ms|us|[YMDhms])" />
	<!-- TODO: sometimes may be detected as variable, e.g. PT122S is legal var name -->
	<!-- PYYYY-MM-DDTHH:mm:SS -->
        <RegExpr attribute="Date" context="#stay" String="P\d{4}-\d{2}-d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,6})?" />
        <RegExpr attribute="Date" context="#stay" String="P(?=\w*\d)(?:\d+Y|Y)?(?:\d+M|M)?(?:\d+W|W)?(?:\d+D|D)?(?:T(?:\d+H|H)?(?:\d+M|M)?(?:\d+S|S)?(?:\d+u|u)?)?" />
 
        <HlCOct attribute="Octal" context="slash_safe_escape" />
        <HlCHex attribute="Hex" context="slash_safe_escape" />
        <Float attribute="Float" context="slash_safe_escape">
	  <AnyChar attribute="Float" context="slash_safe_escape" String="n" /> 
	</Float>
        <Int attribute="Decimal" context="slash_safe_escape" />
	<RegExpr attribute="Binary" context="#stay" String="&lt;[a-zA-Z0-9]+&gt;" />


        <DetectChar attribute="Comment" context="comment" char="#" />
        <Detect2Chars attribute="Comment" context="block_comment" char="/" char1="*" beginRegion="Comment"/>

        <DetectChar attribute="Normal Text" context="#stay" char="{" beginRegion="Block" />
        <DetectChar attribute="Normal Text" context="#stay" char="}" endRegion="Block" />

        <RegExpr attribute="Invisible" context="#stay" String="\s+$" />
      </context>

      <context name="directive_params" attribute="Directive params" lineEndContext="#pop">
      </context>

      <context name="slash_safe_escape" attribute="Normal Text" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop">
        <RegExpr attribute="Normal Text" context="#pop" String="\s*\]?\s*/" />
        <RegExpr attribute="Normal Text" context="#pop" String="\s*\}?\s*/" endRegion="Block" />
        <RegExpr attribute="Normal Text" context="#pop" String="\s*\)?\s*/" />
        <keyword attribute="Keyword" context="#pop" String="keywords" />
        <keyword attribute="Operator word" context="#pop" String="operators" />
        <keyword attribute="Type" context="#pop" String="types" />
      </context>

      <context name="string" attribute="String" lineEndContext="#stay">
        <Detect2Chars attribute="String" context="#stay" char="\" char1="\" />
        <Detect2Chars attribute="String" context="#stay" char="\" char1="'" />
        <Detect2Chars attribute="String" context="#stay" char="\" char1="&quot;" />
        <DetectChar attribute="Operator" context="#pop" char="&quot;" endRegion="String" />
      </context>

      <context name="simple_string" attribute="String" lineEndContext="#stay">
        <DetectChar attribute="Operator" context="#pop" char="'" endRegion="String" />
      </context>

      <!-- ====== Variables ====== -->
      <context name="find_variable" attribute="Variable" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop" >
        <RegExpr attribute="Object Member" context="var_detect" String="\$\.[a-zA-Z][a-zA-Z0-9_]*" />
        <AnyChar attribute="Variable" context="var_detect" String="$" />
      </context>

      <context name="var_detect" attribute="Variable" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop#pop">
        <RegExpr attribute="Variable" context="#stay" String="[\w_]+" />
        <Detect2Chars attribute="Normal Text" context="#stay" char=":" char1=":" />
        <Detect2Chars attribute="Normal Text" context="#stay" char="+" char1="+" />
        <Detect2Chars attribute="Normal Text" context="#stay" char="-" char1="-" />
      </context>

      <context name="backtick" attribute="String (interpolated)" lineEndContext="#stay">
        <DetectChar attribute="Operator" context="#pop" char="`"/>
      </context>

      <context name="sub_name_def" attribute="Normal Text" lineEndContext="#pop" fallthrough="true" fallthroughContext="#pop">
        <RegExpr attribute="Function" context="#stay" String="\w+" />
        <RegExpr attribute="Normal Text" context="find_variable" String="\$\S" lookAhead="true" />
        <RegExpr attribute="Normal Text" context="sub_arg_definition" String="\s*\(" />
        <Detect2Chars attribute="Normal Text" context="#stay" char=":" char1=":" />
      </context>

      <context name="sub_arg_definition" attribute="Normal Text" lineEndContext="#stay" fallthrough="true" fallthroughContext="#pop#pop">
        <AnyChar attribute="Variable" context="var_detect" String="$" />
        <DetectChar attribute="Normal Text" context="slash_safe_escape" char=")" />
      </context>

      <context name="comment" attribute="Comment" lineEndContext="#pop">
        <RegExpr attribute="Note" context="#stay" String="(?:FIXME|TODO|NOTE):?" />
      </context>

      <context name="block_comment" attribute="Comment" lineEndContext="#stay">
        <DetectSpaces />
        <Detect2Chars attribute="Comment" context="#pop" char="*" char1="/" endRegion="Comment"/>
        <IncludeRules context="##Alerts" />
        <DetectIdentifier />
      </context>

    </contexts>
    <itemDatas>
      <!-- dsChar -->
      <itemData name="Normal Text"               defStyleNum="dsNormal" />
      <itemData name="Keyword"                   defStyleNum="dsKeyword" />
      <itemData name="Operator word"             defStyleNum="dsKeyword" italic="true" />
      <itemData name="Directive"                 defStyleNum="dsOthers" bold="true" italic="true" color="teal" />
      <itemData name="Directive params"          defStyleNum="dsOthers"  italic="true" color="teal" />
      <itemData name="Type"                      defStyleNum="dsDataType" />
      <itemData name="Function"                  defStyleNum="dsFunction" />
      <itemData name="Operator"                  defStyleNum="dsKeyword" color="#008000"/>
      <itemData name="Variable"                  defStyleNum="dsDataType" />
      <itemData name="Object Member"             defStyleNum="dsDataType" />
      <itemData name="Decimal"                   defStyleNum="dsDecVal" />
      <itemData name="Bool"                      defStyleNum="dsDecVal" />
      <itemData name="Date"                      defStyleNum="dsDecVal" />
      <itemData name="Octal"                     defStyleNum="dsBaseN" />
      <itemData name="Hex"                       defStyleNum="dsBaseN" />
      <itemData name="Float"                     defStyleNum="dsFloat" />
      <itemData name="String"                    defStyleNum="dsString" color="#FF6C6C" selColor="#FF6C6C" bold="0" italic="0" />
      <itemData name="String (interpolated)"     defStyleNum="dsString" />
      <itemData name="Binary"                    defStyleNum="dsBaseN" />
      <itemData name="Comment"                   defStyleNum="dsComment" />
      <itemData name="Pod"                       defStyleNum="dsComment" />
      <itemData name="Nothing"                   defStyleNum="dsComment" />
      <itemData name="Note"                      defStyleNum="dsAlert" />
      <itemData name="Region"                    defStyleNum="dsRegionMarker" />
      <itemData name="Invisible"                 defStyleNum="dsError" underline="true" selColor="#FF0000" />
    </itemDatas>
  </highlighting>
  <general>
    <comments>
      <comment name="singleLine" start="#" />
      <comment name="multiLine" start="/*" end="*/" region="Comment" />
    </comments>
    <keywords casesensitive="1" />
  </general>
</language>
<!-- kate: space-indent on; indent-width 4; replace-tabs on; -->
