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

 Author: James Leigh <james@leighnet.ca>
 Copyright (C) 2009 James Leigh <james@leighnet.ca>

 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="sparql" _name="SPARQL" version="2.0" _section="Sources">

  <metadata>
    <property name="mimetypes">text/x-sparql</property>
    <property name="globs">*.sparql</property>
    <property name="line-comment-start">#</property>
  </metadata>

  <styles>
    <style id="class" _name="Class" map-to="def:type"/>
    <style id="datatype" _name="Data Type" map-to="def:type"/>
    <style id="function" _name="Function" map-to="def:function"/>
    <style id="individual" _name="Individual" map-to="def:special-constant"/>
    <style id="keyword" _name="Keyword" map-to="def:keyword"/>
    <style id="boolean" _name="Boolean" map-to="def:boolean"/>
    <style id="literal" _name="Literal" map-to="def:string"/>
    <style id="predicate" _name="Predicate" map-to="def:function"/>
    <style id="qname" _name="QName" />
    <style id="iri" _name="IRI" map-to="def:special-constant"/>
    <style id="var" _name="Variable" map-to="def:preprocessor"/>
  </styles>

  <definitions>
    <context id="sparql">
      <include>

        <context ref="def:shell-like-comment"/>
        <context ref="def:string"/>
        <context ref="def:decimal"/>
        <context ref="def:float"/>
        <context ref="def:hexadecimal"/>

        <context id="iri" style-ref="iri">
          <match>&lt;(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)?/{0,2}[0-9a-zA-Z;/?:@&amp;=+$\\.\\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&amp;=+$\\.\\-_!~*'()%]+)?&gt;</match>
        </context>

        <context id="var" style-ref="var">
          <match>[\?\$][a-zA-Z_0-9]+</match>
        </context>

        <context id="booleans" style-ref="boolean">
          <keyword>true</keyword>
          <keyword>false</keyword>
        </context>

        <context id="a" style-ref="keyword">
          <keyword>a</keyword>
        </context>

        <!-- Use define-regex to override case-sensitivity of keywords -->
        <define-regex id="keywords-regex" extended="true" case-sensitive="false">
          \%[(
          ORDER\s+BY	|
          FROM\s+NAMED	|
          BASE			|
          SELECT		|
          FROM			|
          GRAPH			|
          PREFIX		|
          CONSTRUCT		|
          LIMIT			|
          OPTIONAL		|
          DESCRIBE		|
          OFFSET		|
          WHERE			|
          UNION			|
          ASK			|
          DISTINCT		|
          FILTER		|
          REDUCED
          )\%]
        </define-regex>

        <!-- Use define-regex to override case-sensitivity of keywords -->
        <define-regex id="functions-regex" extended="true" case-sensitive="false">
          \%[(
          STR			|
          isURI			|
          LANG			|
          isIRI			|
          LANGMATCHES	|
          isLITERAL		|
          DATATYPE		|
          REGEX			|
          BOUND			|
          sameTERM		|
          DESC			|
          ASC
          )\%]
        </define-regex>

        <context id="keywords" style-ref="keyword">
          <match>\%{keywords-regex}</match>
        </context>

        <context id="functions" style-ref="function">
          <match>\%{functions-regex}</match>
        </context>

        <context id="datatypes" style-ref="datatype">
          <keyword>xsd:ID</keyword>
          <keyword>xsd:IDREF</keyword>
          <keyword>xsd:NCName</keyword>
          <keyword>xsd:NMTOKEN</keyword>
          <keyword>xsd:Name</keyword>
          <keyword>xsd:anyAtomicType</keyword>
          <keyword>xsd:anyURI</keyword>
          <keyword>xsd:base64Binary</keyword>
          <keyword>xsd:boolean</keyword>
          <keyword>xsd:byte</keyword>
          <keyword>xsd:date</keyword>
          <keyword>xsd:dateTime</keyword>
          <keyword>xsd:dayTimeDuration</keyword>
          <keyword>xsd:decimal</keyword>
          <keyword>xsd:double</keyword>
          <keyword>xsd:duration</keyword>
          <keyword>xsd:float</keyword>
          <keyword>xsd:gDay</keyword>
          <keyword>xsd:gMonth</keyword>
          <keyword>xsd:gMonthDay</keyword>
          <keyword>xsd:gYear</keyword>
          <keyword>xsd:gYearMonth</keyword>
          <keyword>xsd:hexBinary</keyword>
          <keyword>xsd:int</keyword>
          <keyword>xsd:integer</keyword>
          <keyword>xsd:language</keyword>
          <keyword>xsd:long</keyword>
          <keyword>xsd:negativeInteger</keyword>
          <keyword>xsd:nonNegativeInteger</keyword>
          <keyword>xsd:nonPositiveInteger</keyword>
          <keyword>xsd:normalizedString</keyword>
          <keyword>xsd:precisionDecimal</keyword>
          <keyword>xsd:positiveInteger</keyword>
          <keyword>xsd:short</keyword>
          <keyword>xsd:string</keyword>
          <keyword>xsd:time</keyword>
          <keyword>xsd:token</keyword>
          <keyword>xsd:unsignedByte</keyword>
          <keyword>xsd:unsignedInt</keyword>
          <keyword>xsd:unsignedLong</keyword>
          <keyword>xsd:unsignedShort</keyword>
          <keyword>xsd:yearMonthDuration</keyword>
        </context>

        <context id="classes" style-ref="class">
          <keyword>rdf:Property</keyword>
          <keyword>rdf:Statement</keyword>
          <keyword>rdf:Bag</keyword>
          <keyword>rdf:Seq</keyword>
          <keyword>rdf:Alt</keyword>
          <keyword>rdf:List</keyword>
          <keyword>rdf:XMLLiteral</keyword>
          <keyword>rdfs:Resource</keyword>
          <keyword>rdfs:Class</keyword>
          <keyword>rdfs:Literal</keyword>
          <keyword>rdfs:Container</keyword>
          <keyword>rdfs:ContainerMembershipProperty</keyword>
          <keyword>rdfs:Datatype</keyword>
          <keyword>owl:Class</keyword>
          <keyword>owl:Thing</keyword>
          <keyword>owl:Nothing</keyword>
          <keyword>owl:AllDifferent</keyword>
          <keyword>owl:Restriction</keyword>
          <keyword>owl:ObjectProperty</keyword>
          <keyword>owl:DatatypeProperty</keyword>
          <keyword>owl:TransitiveProperty</keyword>
          <keyword>owl:SymmetricProperty</keyword>
          <keyword>owl:FunctionalProperty</keyword>
          <keyword>owl:InverseFunctionalProperty</keyword>
          <keyword>owl:AnnotationProperty</keyword>
          <keyword>owl:Ontology</keyword>
          <keyword>owl:OntologyProperty</keyword>
          <keyword>owl:DeprecatedClass</keyword>
          <keyword>owl:DeprecatedProperty</keyword>
          <keyword>owl:DataRange</keyword>
        </context>

        <context id="predicates" style-ref="predicate">
          <keyword>rdf:type</keyword>
          <keyword>rdf:subject</keyword>
          <keyword>rdf:predicate</keyword>
          <keyword>rdf:object</keyword>
          <keyword>rdf:value</keyword>
          <keyword>rdf:first</keyword>
          <keyword>rdf:rest</keyword>
          <keyword>rdfs:subClassOf</keyword>
          <keyword>rdfs:subPropertyOf</keyword>
          <keyword>rdfs:comment</keyword>
          <keyword>rdfs:label</keyword>
          <keyword>rdfs:domain</keyword>
          <keyword>rdfs:range</keyword>
          <keyword>rdfs:seeAlso</keyword>
          <keyword>rdfs:isDefinedBy</keyword>
          <keyword>rdfs:member</keyword>
          <keyword>owl:equivalentClass</keyword>
          <keyword>owl:disjointWith</keyword>
          <keyword>owl:equivalentProperty</keyword>
          <keyword>owl:sameAs</keyword>
          <keyword>owl:differentFrom</keyword>
          <keyword>owl:distinctMembers</keyword>
          <keyword>owl:unionOf</keyword>
          <keyword>owl:intersectionOf</keyword>
          <keyword>owl:complementOf</keyword>
          <keyword>owl:oneOf</keyword>
          <keyword>owl:onProperty</keyword>
          <keyword>owl:allValuesFrom</keyword>
          <keyword>owl:hasValue</keyword>
          <keyword>owl:someValuesFrom</keyword>
          <keyword>owl:minCardinality</keyword>
          <keyword>owl:maxCardinality</keyword>
          <keyword>owl:cardinality</keyword>
          <keyword>owl:inverseOf</keyword>
          <keyword>owl:imports</keyword>
          <keyword>owl:versionInfo</keyword>
          <keyword>owl:priorVersion</keyword>
          <keyword>owl:backwardCompatibleWith</keyword>
          <keyword>owl:incompatibleWith</keyword>
        </context>

        <context id="individuals" style-ref="individual">
          <keyword>rdf:nil</keyword>
        </context>

        <context id="qnames" style-ref="qname">
          <match>(?&lt;!\w)[a-zA-Z_]*:[a-zA-Z0-9_]+\%]</match>
        </context>

      </include>
    </context>
  </definitions>

</language>
