<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd"
[
  <!ENTITY null "(?:null|Null|NULL|~)">
  <!ENTITY bool "(?:y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)">

  <!ENTITY int         "(?:0|[\-\+]?[1-9][0-9_]*)">
  <!ENTITY intOther    "[\-\+]?0(?:x_*[0-9a-fA-F][0-9a-fA-F_]*|o?_*[0-7][0-7_]*|b_*[01][01_]*)"> <!-- Hex, Octal, Binary -->
  <!ENTITY intBase60   "[\-\+]?[1-9][0-9_]*(?:\:[0-5]?[0-9])+">
  <!ENTITY allInt      "(?:&intBase60;|&intOther;|&int;)">

  <!ENTITY float       "[\-\+]?(?:[0-9][0-9_]*\.[0-9\._]*|\._*[0-9][0-9\._]*)(?:[eE][\-\+]?[0-9]+)?">
  <!ENTITY floatExp    "[\-\+]?[0-9][0-9_]*[eE][\-\+]?[0-9]+">
  <!ENTITY floatBase60 "[\-\+]?[0-9][0-9_]*(?:\:[0-5]?[0-9])+\.[0-9_]*">
  <!ENTITY inf         "[\-\+]?\.(?:inf|Inf|INF)\b">
  <!ENTITY nan         "\.(?:nan|NaN|NAN)\b">
  <!ENTITY allFloat    "(?:&float;|&floatExp;|&floatBase60;|&inf;|&nan;)">

  <!ENTITY endValue       "(?:\s*$|\s+#)">
  <!ENTITY endValueInline "\s*[:,\[\]\{\}]">
  <!ENTITY space          "[ ]">

  <!-- Key quoted -->
  <!ENTITY keyDQ          "&quot;(?:\\.|[^&quot;])+&quot;\s*">
  <!ENTITY keySQ          "'(?:[^']|'')+'\s*">
  <!-- Literal/folded operator -->
  <!ENTITY literalOp      "[\|&gt;][\-\+]?">
  <!-- Key after "?" or "-", used to detect literal/folded operator -->
  <!ENTITY keyAfterOp     "(?:[^&quot;'#\-\?\s][^:#]*|\-(?:[^\s:#][^:#]*)?|&keyDQ;|&keySQ;)">

  <!ENTITY dataTypes      "!!\S+">
  <!ENTITY alias          "&amp;\S+">
  <!ENTITY reference      "\*\S+">

  <!ENTITY dpointsHashAttrPreInline1 "[^\s&quot;'#\-,\}\s][^:#,\}]*(?=\:(?:\s|$))">
  <!ENTITY dpointsHashAttrPreInline2 "\-(?:[^\s:#,\}][^:#,\}]*)?(?=\:(?:\s|$))">
  <!ENTITY dpointsHashAttrPreInline3 "&keyDQ;(?=\:(?:\s|$))">
  <!ENTITY dpointsHashAttrPreInline4 "&keySQ;(?=\:(?:\s|$))">

  <!ENTITY dpointsListAttrPreInline1 "[^&quot;'#\-,\]\s][^:#,\]]*(?=\:(?:\s|$))">
  <!ENTITY dpointsListAttrPreInline2 "\-(?:[^\s:#,\]][^:#,\]]*)?(?=\:(?:\s|$))">
  <!ENTITY dpointsListAttrPreInline3 "&keyDQ;(?=\:(?:\s|$))">
  <!ENTITY dpointsListAttrPreInline4 "&keySQ;(?=\:(?:\s|$))">

  <!ENTITY dpointsAttrPre1 "[^&quot;'#\-\s][^:#]*(?=\:(?:\s|$))">
  <!ENTITY dpointsAttrPre2 "\-(?:[^\s:#][^:#]*)?(?=\:(?:\s|$))">
  <!ENTITY dpointsAttrPre3 "&keyDQ;(?=\:(?:\s|$))">
  <!ENTITY dpointsAttrPre4 "&keySQ;(?=\:(?:\s|$))">

  <!-- Matches Yaml keys whose values are SQL statements in CartoCSS MML files. -->
  <!ENTITY sqlKey "(table|layer_by_sql)">

]>

<!-- Author: Dr Orlovsky MA <maxim@orlovsky.info> //-->
<!-- Modifications (YAML 1.2), values & support for literal/folded style:
       Nibaldo González S. <nibgonz@gmail.com>
       These modifications are under the MIT license. //-->
<!-- Derive the MML syntax highlighting from the yaml syntax highlighting:
       Lukas Sommer <sommerluk@gmail.com>
       These modifications are under the MIT license. //-->

<!-- Syntax highlighting definition for CartoCSS MML, see https://github.com/mapbox/carto
     CartoCSS defines two file formats: MML (Map Markup Language) and MSS (Map Stylesheet).
     This file provides syntax highlighting for MML. As MML is yaml, it is derived from
     the yaml syntax highlighting definition. It adds SQL highlighting for yaml content
     since MML typically contains a lot of SQL code.

     NOTE This file is mostly identical to yaml.xml so changes to yaml.xml can and should
     be backported also to this file.

     HACK There are two keys in MML files that have SQL content: “table” and
     “layer_by_sql”. The good solution would be to recognize these keys and provide
     SQL highlighting for their content (and only their content):
     - folded/literal block:               Yes
     - plain string:                       Possibly. But special treatment for crazy
                                           yaml rules required www.yaml-multiline.info
                                           says: “:” cannot appear before a space or
                                           newline, and “#” cannot appear after a space
                                           or newline
     - single-quoted/double-quoted string: No. Too complicate and too confusing: it would
                                           require special SQL highlighting rules that
                                           deals with the escapes.
     But that could be difficult to implement. However, it seems likely that people
     write SQL in folded/literal blocks, while not using folded/literal blocks for
     anything else. So for simplicity we will here highlight all folded/literal blocks
     as SQL and everything else not, regardless of the key.
-->

<language name="CartoCSS MML" version="2" kateversion="5.44" section="Markup"
          extensions="*.mml"
          author="Dr Orlovsky MA (dr.orlovsky@gmail.com), Nibaldo González (nibgonz@gmail.com), Lukas Sommer (sommerluk@gmail.com)" license="LGPL">
  <highlighting>
    <contexts>
      <context attribute="Attribute" lineEndContext="#stay" name="normal" >
        <StringDetect attribute="Document Header" context="header" String="---" column="0"/>
        <RegExpr attribute="End of Document" context="EOD" String="^\.\.\.$" column="0"/>
        <DetectChar attribute="Directive" context="directive" char="%" column="0"/>

        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />

        <!-- Literal/Folded Style -->
        <IncludeRules context="find-literal-block" />

        <RegExpr attribute="Operator" firstNonSpace="true" context="dash" String="\-(?=\s|$)" />
        <DetectChar attribute="Operator" firstNonSpace="true" context="mapping-key" char="?" />

        <DetectChar attribute="Operator" firstNonSpace="true" context="list" char="[" beginRegion="List" />
        <DetectChar attribute="Operator" firstNonSpace="true" context="hash" char="{" beginRegion="Hash" />

        <RegExpr attribute="Data Types" firstNonSpace="true" context="after-data" String="&dataTypes;" />
        <RegExpr attribute="Alias" firstNonSpace="true" context="after-data" String="&alias;" />
        <RegExpr attribute="Reference" firstNonSpace="true" context="after-data" String="&reference;" />

        <RegExpr attribute="Key" context="dpoints-attribute-pre" String="&dpointsAttrPre1;|&dpointsAttrPre2;|&dpointsAttrPre3;|&dpointsAttrPre4;"/>
        <RegExpr attribute="Key Points Operator" context="attribute-pre" String=":(?=\s|$)"/>

        <DetectChar attribute="String" firstNonSpace="true" context="string" char="'" beginRegion="String" />
        <DetectChar attribute="String" firstNonSpace="true" context="stringx" char="&quot;" beginRegion="String" />
        <IncludeRules context="values-firstnonspace" />
        <DetectSpaces/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="mapping-key" fallthrough="true" fallthroughContext="#pop">
        <RegExpr attribute="Comment" context="#pop!comment" String="(?:^|\s+)#" />
        <DetectSpaces />
        <RegExpr attribute="Operator" context="#pop!dash" String="\-(?=\s|$)" />
        <RegExpr attribute="Data Types" context="#pop!after-data" String="&dataTypes;" />
        <RegExpr attribute="Alias" context="#pop!after-data" String="&alias;" />
        <RegExpr attribute="Reference" context="#pop!after-data" String="&reference;" />

        <DetectChar attribute="Operator" context="#pop!list" char="[" beginRegion="List" />
        <DetectChar attribute="Operator" context="#pop!hash" char="{" beginRegion="Hash" />
        <DetectChar attribute="String" context="#pop!string" char="'" beginRegion="String" />
        <DetectChar attribute="String" context="#pop!stringx" char="&quot;" beginRegion="String" />
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="dash" fallthrough="true" fallthroughContext="#pop">
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
        <DetectSpaces/>
        <RegExpr attribute="Data Types" context="#stay" String="&dataTypes;" />
        <RegExpr attribute="Alias" context="#stay" String="&alias;" />
        <RegExpr attribute="Reference" context="#stay" String="&reference;" />
        <IncludeRules context="values" />
        <DetectChar attribute="Operator" context="#pop!mapping-key" char="?" />
        <RegExpr attribute="Operator" context="#stay" String="\-(?=\s|$)" />

        <DetectChar attribute="Operator" context="#pop!list" char="[" beginRegion="List" />
        <DetectChar attribute="Operator" context="#pop!hash" char="{" beginRegion="Hash" />
        <DetectChar attribute="String" context="#pop!string" char="'" beginRegion="String" />
        <DetectChar attribute="String" context="#pop!stringx" char="&quot;" beginRegion="String" />
      </context>

      <!-- Highlight lists, hashes and strings after a data type, reference or alias -->
      <context attribute="Normal Text" lineEndContext="#pop" name="after-data" fallthrough="true" fallthroughContext="#pop">
        <RegExpr attribute="Comment" context="#pop!comment" String="(?:^|\s+)#" />
        <DetectSpaces />
        <RegExpr attribute="Data Types" context="#stay" String="&dataTypes;" />
        <RegExpr attribute="Alias" context="#stay" String="&alias;" />
        <RegExpr attribute="Reference" context="#stay" String="&reference;" />

        <DetectChar attribute="Operator" context="list" char="[" beginRegion="List" />
        <DetectChar attribute="Operator" context="hash" char="{" beginRegion="Hash" />
        <DetectChar attribute="String" context="string" char="'" beginRegion="String" />
        <DetectChar attribute="String" context="stringx" char="&quot;" beginRegion="String" />
      </context>

      <context attribute="Document Header" lineEndContext="#pop" name="header">
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
        <RegExpr attribute="Literal/Folded Operator" context="header-literal-operator" String="\s&literalOp;(?=&endValue;)" lookAhead="true" />
      </context>
      <context attribute="Document Header" lineEndContext="#pop#pop" name="header-literal-operator" fallthrough="true" fallthroughContext="#pop">
        <DetectSpaces />
        <RegExpr attribute="Literal/Folded Operator" context="#pop#pop!literal-block-simple" String="&literalOp;" beginRegion="Literal" />
      </context>

      <context attribute="End of Document" lineEndContext="#stay" name="EOD">
      </context>

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

      <context attribute="Attribute" lineEndContext="#pop#pop" name="attribute">
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
      </context>

      <context attribute="Attribute" lineEndContext="#stay" name="list-attribute-inline">
        <AnyChar attribute="Operator" context="#pop#pop" lookAhead="true" String=",]" />
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
      </context>
      <context attribute="Attribute" lineEndContext="#stay" name="hash-attribute-inline">
        <AnyChar attribute="Operator" context="#pop#pop" lookAhead="true" String=",}" />
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
      </context>

      <!-- Attribute -->
      <context attribute="Attribute" lineEndContext="#pop" name="dpoints-attribute-pre" fallthrough="true" fallthroughContext="#pop!attribute-pre">
        <DetectChar attribute="Key Points Operator" context="#pop!attribute-pre" char=":" /> <!-- Highlight two points after Key -->
      </context>
      <context attribute="Attribute" lineEndContext="#pop" name="attribute-pre" fallthrough="true" fallthroughContext="attribute">
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
        <DetectSpaces/>
        <DetectChar attribute="Operator" context="#stay" char="?" />
        <RegExpr attribute="Data Types" context="#stay" String="&dataTypes;" />
        <DetectChar attribute="Operator" context="list" char="[" beginRegion="List" />
        <DetectChar attribute="Operator" context="hash" char="{" beginRegion="Hash" />
        <DetectChar attribute="String" context="attribute-string" char="'" beginRegion="String" />
        <DetectChar attribute="String" context="attribute-stringx" char="&quot;" beginRegion="String" />
        <RegExpr attribute="Alias" context="#stay" String="&alias;(?=\s+[\[\{])" />
        <RegExpr attribute="Reference" context="#stay" String="&reference;(?=\s+[\[\{])" />
        <RegExpr attribute="Alias" context="attribute" String="&alias;" />
        <RegExpr attribute="Reference" context="attribute" String="&reference;" />
        <IncludeRules context="values" />
        <RegExpr attribute="Literal/Folded Operator" context="#stay" String="&literalOp;(?=&endValue;)" />
      </context>

      <context attribute="Attribute" lineEndContext="#pop" name="default-attribute-pre-inline">
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
        <DetectSpaces/>

        <DetectChar attribute="Operator" context="#stay" char="?" />
        <RegExpr attribute="Data Types" context="#stay" String="&dataTypes;" />
        <DetectChar attribute="Operator" context="list" char="[" beginRegion="List" />
        <DetectChar attribute="Operator" context="hash" char="{" beginRegion="Hash" />
        <DetectChar attribute="String" context="attribute-string-inline" char="'" beginRegion="String" />
        <DetectChar attribute="String" context="attribute-stringx-inline" char="&quot;" beginRegion="String" />
        <RegExpr attribute="Alias" context="#stay" String="&alias;(?=\s+[\[\{])" />
        <RegExpr attribute="Reference" context="#stay" String="&reference;(?=\s+[\[\{])" />
      </context>

      <!-- Attribute Inline, Within List -->
      <context attribute="Attribute" lineEndContext="#pop" name="dpoints-list-attribute-pre-inline" fallthrough="true" fallthroughContext="#pop!list-attribute-pre-inline">
        <DetectChar attribute="Key Points Operator" context="#pop!list-attribute-pre-inline" char=":" /> <!-- Highlight two points after Key -->
      </context>
      <context attribute="Attribute" lineEndContext="#pop" name="list-attribute-pre-inline" fallthrough="true" fallthroughContext="list-attribute-inline">
        <IncludeRules context="default-attribute-pre-inline" />
        <RegExpr attribute="Alias" context="list-attribute-inline" String="&alias;" />
        <RegExpr attribute="Reference" context="list-attribute-inline" String="&reference;" />

        <AnyChar attribute="Operator" context="#pop" lookAhead="true" String=",]" />
        <IncludeRules context="values-inline" />
      </context>

      <!-- Attribute Inline, Within Hash -->
      <context attribute="Attribute" lineEndContext="#pop" name="dpoints-hash-attribute-pre-inline" fallthrough="true" fallthroughContext="#pop!hash-attribute-pre-inline">
        <DetectChar attribute="Key Points Operator" context="#pop!hash-attribute-pre-inline" char=":" /> <!-- Highlight two points after Key -->
      </context>
      <context attribute="Attribute" lineEndContext="#pop" name="hash-attribute-pre-inline" fallthrough="true" fallthroughContext="hash-attribute-inline">
        <IncludeRules context="default-attribute-pre-inline" />
        <RegExpr attribute="Alias" context="hash-attribute-inline" String="&alias;" />
        <RegExpr attribute="Reference" context="hash-attribute-inline" String="&reference;" />

        <AnyChar attribute="Operator" context="#pop" lookAhead="true" String=",}" />
        <IncludeRules context="values-inline" />
      </context>

      <!-- List -->
      <!-- Context "find-values-list" highlights values and then sends to "list-element" -->
      <context attribute="List" lineEndContext="#stay" name="list" fallthrough="true" fallthroughContext="#pop!find-values-list" noIndentationBasedFolding="true">
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
        <DetectSpaces />
        <DetectChar attribute="Operator" context="#pop!find-values-list" char="?" />
      </context>
      <context attribute="List" lineEndContext="#stay" name="list-element" noIndentationBasedFolding="true">
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />

        <DetectChar attribute="Operator" context="#pop" char="]" endRegion="List" />
        <DetectChar attribute="Operator" context="list" char="[" beginRegion="List" />
        <DetectChar attribute="Operator" context="hash" char="{" beginRegion="Hash" />

        <RegExpr attribute="Key" context="dpoints-list-attribute-pre-inline" String="&dpointsListAttrPreInline1;|&dpointsListAttrPreInline2;|&dpointsListAttrPreInline3;|&dpointsListAttrPreInline4;"/>
        <RegExpr attribute="Key Points Operator" context="list-attribute-pre-inline" String=":(?=\s|$)" firstNonSpace="true" />

        <RegExpr attribute="Data Types" context="#stay" String="&dataTypes;" />
        <RegExpr attribute="Alias" context="#stay" String="&alias;" />
        <RegExpr attribute="Reference" context="#stay" String="&reference;" />
        <DetectChar attribute="String" context="string" char="'" beginRegion="String" />
        <DetectChar attribute="String" context="stringx" char="&quot;" beginRegion="String" />

        <DetectChar attribute="Operator" context="#pop!list" char="," />
        <IncludeRules context="values-list" />
      </context>

      <!-- Hash -->
      <context attribute="Hash" lineEndContext="#stay" name="hash" fallthrough="true" fallthroughContext="#pop!hash-element" noIndentationBasedFolding="true">
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
        <DetectSpaces />
        <DetectChar attribute="Operator" context="#pop!hash-element" char="?" />
      </context>
      <context attribute="Hash" lineEndContext="#stay" name="hash-element" noIndentationBasedFolding="true">
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
        <DetectSpaces/>

        <RegExpr attribute="Key" context="dpoints-hash-attribute-pre-inline" String="&dpointsHashAttrPreInline1;|&dpointsHashAttrPreInline2;|&dpointsHashAttrPreInline3;|&dpointsHashAttrPreInline4;"/>
        <RegExpr attribute="Key Points Operator" context="hash-attribute-pre-inline" String=":(?=\s|$)"/>

        <DetectChar attribute="Operator" context="#pop" char="}" endRegion="Hash" />
        <DetectChar attribute="Operator" context="#pop!hash" char="," />

        <!-- This improves highlighting in keys with multiple lines -->
        <RegExpr attribute="Data Types" context="#stay" String="&dataTypes;" />
        <RegExpr attribute="Alias" context="#stay" String="&alias;" />
        <RegExpr attribute="Reference" context="#stay" String="&reference;" />
        <DetectChar attribute="String" context="string" char="'" beginRegion="String" />
        <DetectChar attribute="String" context="stringx" char="&quot;" beginRegion="String" />
      </context>

      <!-- Strings -->
      <context attribute="String" lineEndContext="#stay" name="attribute-string" noIndentationBasedFolding="true">
        <DetectIdentifier />
        <IncludeRules context="escaped-char-singleq" />
        <DetectChar attribute="String" context="attribute-end" char="'" endRegion="String" />
      </context>

      <context attribute="String" lineEndContext="#stay" name="attribute-stringx" noIndentationBasedFolding="true">
        <DetectIdentifier />
        <IncludeRules context="escaped-char-doubleq" />
        <DetectChar attribute="String" context="attribute-end" char="&quot;" endRegion="String" />
      </context>

      <context attribute="String" lineEndContext="#stay" name="attribute-string-inline" noIndentationBasedFolding="true">
          <DetectIdentifier />
          <IncludeRules context="escaped-char-singleq" />
          <DetectChar attribute="String" context="attribute-end-inline" char="'" endRegion="String" />
      </context>

      <context attribute="String" lineEndContext="#stay" name="attribute-stringx-inline" noIndentationBasedFolding="true">
          <DetectIdentifier />
          <IncludeRules context="escaped-char-doubleq" />
          <DetectChar attribute="String" context="attribute-end-inline" char="&quot;" endRegion="String" />
      </context>

      <context attribute="Error" lineEndContext="#pop#pop#pop" name="attribute-end">
          <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
          <DetectSpaces attribute="Normal Text" context="#stay"/>
      </context>

      <context attribute="Error" lineEndContext="#pop#pop#pop" name="attribute-end-inline">
          <RegExpr attribute="Comment" context="comment" String="(?:^|\s+)#" />
          <DetectSpaces attribute="Normal Text" context="#stay"/>
          <AnyChar context="#pop#pop#pop" lookAhead="true" String="}],"/>
      </context>

      <context attribute="String" lineEndContext="#stay" name="string" noIndentationBasedFolding="true">
        <DetectIdentifier />
        <IncludeRules context="escaped-char-singleq" />
        <DetectChar attribute="String" context="#pop" char="'" endRegion="String" />
      </context>

      <context attribute="String" lineEndContext="#stay" name="stringx" noIndentationBasedFolding="true">
        <DetectIdentifier />
        <IncludeRules context="escaped-char-doubleq" />
        <DetectChar attribute="String" context="#pop" char="&quot;" endRegion="String" />
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="escaped-char-doubleq">
        <RegExpr attribute="Escaped Character" context="#stay" String="\\(?:[\s0abtnvfre&quot;/\\N_Lp]|x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8})"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="escaped-char-singleq">
        <Detect2Chars attribute="Escaped Character" context="#stay" char="'" char1="'" />
      </context>

      <context attribute="Comment" lineEndContext="#pop" name="comment">
        <DetectSpaces />
        <IncludeRules context="##Comments" />
      </context>

      <!-- Values -->
      <context attribute="Normal Text" lineEndContext="#stay" name="values">
        <RegExpr attribute="Null" context="#stay" String="&null;(?=&endValue;)"/>
        <RegExpr attribute="Boolean" context="#stay" String="&bool;(?=&endValue;)"/>
        <RegExpr attribute="Float" context="#stay" String="&allFloat;(?=&endValue;)"/>
        <RegExpr attribute="Integer" context="#stay" String="&allInt;(?=&endValue;)"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="values-firstnonspace">
        <RegExpr attribute="Null" firstNonSpace="true" context="#stay" String="&null;(?=&endValue;)"/>
        <RegExpr attribute="Boolean" firstNonSpace="true" context="#stay" String="&bool;(?=&endValue;)"/>
        <RegExpr attribute="Float" firstNonSpace="true" context="#stay" String="&allFloat;(?=&endValue;)"/>
        <RegExpr attribute="Integer" firstNonSpace="true" context="#stay" String="&allInt;(?=&endValue;)"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="values-inline">
        <RegExpr attribute="Null" context="#stay" String="&null;(?=&endValueInline;|&endValue;)"/>
        <RegExpr attribute="Boolean" context="#stay" String="&bool;(?=&endValueInline;|&endValue;)"/>
        <RegExpr attribute="Float" context="#stay" String="&allFloat;(?=&endValueInline;|&endValue;)"/>
        <RegExpr attribute="Integer" context="#stay" String="&allInt;(?=&endValueInline;|&endValue;)"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="values-list">
        <RegExpr attribute="Null" context="#stay" String="(?:\s|^)&null;(?=&endValueInline;|&endValue;)"/>
        <RegExpr attribute="Boolean" context="#stay" String="(?:\s|^)&bool;(?=&endValueInline;|&endValue;)"/>
        <RegExpr attribute="Float" context="#stay" String="(?:\s|^)&allFloat;(?=&endValueInline;|&endValue;)"/>
        <RegExpr attribute="Integer" context="#stay" String="(?:\s|^)&allInt;(?=&endValueInline;|&endValue;)"/>
      </context>
      <!-- If the value is found immediately at the beginning of the list item -->
      <context attribute="Normal Text" lineEndContext="#pop!list-element" name="find-values-list" fallthrough="true" fallthroughContext="#pop!list-element">
        <RegExpr attribute="Null" context="#pop!list-element" String="&null;(?=&endValueInline;|&endValue;)"/>
        <RegExpr attribute="Boolean" context="#pop!list-element" String="&bool;(?=&endValueInline;|&endValue;)"/>
        <RegExpr attribute="Float" context="#pop!list-element" String="&allFloat;(?=&endValueInline;|&endValue;)"/>
        <RegExpr attribute="Integer" context="#pop!list-element" String="&allInt;(?=&endValueInline;|&endValue;)"/>
      </context>

      <!-- Literal/Folded Style: http://yaml.org/spec/1.2/spec.html#id2795688 -->

      <context attribute="Normal Text" lineEndContext="#stay" name="find-literal-block">
        <!-- Do not allow indentation with tabs: -->
        <RegExpr attribute="Alert" context="#stay" column="0"
                 String="^&space;*\t+\s*(?=(?:(?:&keyDQ;|&keySQ;|[^#])*[^#\w\|&lt;&gt;&quot;'])?&literalOp;&endValue;)" />

        <!-- CASE 1: The literal/folded operator is the first character of a line.
             The text after a space is considered literal.
             Ex:
             > |
             >  ^Start the literal text
        -->
        <RegExpr attribute="Literal/Folded Operator" context="literal-block-simple" column="0"
                 String="^&literalOp;(?=&endValue;)" beginRegion="Literal" />

        <!-- CASE 2: Only the literal/folded operator is present in a line, after a space (the indentation
             is captured). The text with the same indentation of the operator will be highlighted as literal.
             Ex:
             >  key:
             >    |
             >    ^Start the literal text

             However, in this case, the correct way is to use the indentation of the block, not the
             indentation of the the operator. The problem is that it is difficult to capture.
             >  key1:
             >   key2:
             >    key3:
             >          |
             >     ^Block indentation (correct literal text)
        -->
        <RegExpr attribute="Literal/Folded Operator" context="literal-block-only-operator" column="0"
                 String="^(&space;+)&literalOp;(?=&endValue;)" beginRegion="Literal" />

        <!-- CASE 3: There is a Key before the literal/folded operator (Key indentation is captured).
             The text with the Key's indentation plus a space is considered literal.
             Ex:
             >    key: |
             >     ^Start the literal text
             >  key: !!type >-
             >   ^Start the folded text
        -->
        <RegExpr attribute="Key Points Operator" context="literal-block-key" column="0"
                 String="^(&space;*)\:(?=\s+(?:(?:&keyDQ;|&keySQ;|[^#])*[^#\w\|&lt;&gt;&quot;'])?&literalOp;&endValue;)" />
        <RegExpr attribute="Key" context="literal-block-key" column="0"
                 String="^(&space;*)(?:[^&quot;'#\-\?\s][^:#]*|\-(?:[^\s:#][^:#]*)?|&keyDQ;|&keySQ;)(?=\:\s+(?:(?:&keyDQ;|&keySQ;|[^#])*[^#\w\|&lt;&gt;&quot;'])?&literalOp;&endValue;)" />

        <!-- CASE 4: Is there an operator "?" or "-" at the beginning of the line.
             NOTE: Nested characters "-" and "?" are considered as part of the indentation.
             Therefore, the indentation of the Key or the last operator "?" or "-" is captured.
             Ex:
             >  ? |
             >   ^Start the literal Text
             >  ? - - |
             >       ^Start the literal text
             >  - Key: |
             >     ^Start the literal text
             >  ? - - - - Key: |
             >             ^Start the literal text
        -->
        <RegExpr context="start-literal-block-withdash" lookAhead="true" column="0"
                 String="^&space;*(?:\?&space;*|\-&space;+){1,6}(?:(?:&keyDQ;|&keySQ;|[^#\-\?\s]|\-[^\s#])(?:(?:&keyDQ;|&keySQ;|[^#])*[^#\w\|&lt;&gt;&quot;'])?)?&literalOp;&endValue;" />

        <!-- CASE 5: Literal/folded operator after a data type or other content.
             Ex:
             >  !!type |
             >   ^Start the literal text
             >  key1:
             >   key2:
             >    !!type |
             >    ^Start the literal text
        -->
        <RegExpr context="start-literal-block-other" lookAhead="true" column="0"
                 String="^&space;*(?:(?:[&amp;\*]|!!)\S+\s+)+&literalOp;&endValue;" />
      </context>

      <!-- If the line with the literal operator starts with the "-" or "?" operator.
           NOTE: The indentation capture is limited to 6 nested operators. -->
      <context attribute="Normal Text" lineEndContext="#pop" name="start-literal-block-withdash" noIndentationBasedFolding="true">
        <!-- With Key: Capture the Key indentation -->
        <RegExpr attribute="Operator" context="#pop!literal-block-key-withdash-s2" String="^(&space;*)[\?\-](&space;*)(?=&keyAfterOp;:\s)" column="0"/>
        <RegExpr attribute="Operator" context="#pop!literal-block-key-withdash-s3" String="^(&space;*)[\?\-](&space;*)[\?\-](&space;*)(?=&keyAfterOp;:\s)" column="0"/>
        <RegExpr attribute="Operator" context="#pop!literal-block-key-withdash-s4" String="^(&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)(?=&keyAfterOp;:\s)" column="0"/>
        <RegExpr attribute="Operator" context="#pop!literal-block-key-withdash-s5" String="^(&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)(?=&keyAfterOp;:\s)" column="0"/>
        <RegExpr attribute="Operator" context="#pop!literal-block-key-withdash-s6" String="^(&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)(?=&keyAfterOp;:\s)" column="0"/>
        <RegExpr attribute="Operator" context="#pop!literal-block-key-withdash-s7" String="^(&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)(?=&keyAfterOp;:\s)" column="0"/>
        <!-- Without Key: Capture the indentation of the last operator "?" or "-" -->
        <RegExpr attribute="Operator" context="#pop!literal-block-withdash-s1" String="^(&space;*)[\?\-]\s*(?=[^#\-\?\s]|\-[^\s#])" column="0"/>
        <RegExpr attribute="Operator" context="#pop!literal-block-withdash-s2" String="^(&space;*)[\?\-](&space;*)[\?\-]\s*(?=[^#\-\?\s]|\-[^\s#])" column="0"/>
        <RegExpr attribute="Operator" context="#pop!literal-block-withdash-s3" String="^(&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-]\s*(?=[^#\-\?\s]|\-[^\s#])" column="0"/>
        <RegExpr attribute="Operator" context="#pop!literal-block-withdash-s4" String="^(&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-]\s*(?=[^#\-\?\s]|\-[^\s#])" column="0"/>
        <RegExpr attribute="Operator" context="#pop!literal-block-withdash-s5" String="^(&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-]\s*(?=[^#\-\?\s]|\-[^\s#])" column="0"/>
        <RegExpr attribute="Operator" context="#pop!literal-block-withdash-s6" String="^(&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-](&space;*)[\?\-]\s*(?=[^#\-\?\s]|\-[^\s#])" column="0"/>
      </context>
      <!-- Capture the indentation of data type, reference or alias  -->
      <context attribute="Normal Text" lineEndContext="#pop" name="start-literal-block-other" noIndentationBasedFolding="true">
        <!-- The text with the same indentation will be considered literal -->
        <RegExpr attribute="Data Types" context="#pop!literal-block-after-data" String="^(&space;+)&dataTypes;" column="0" />
        <RegExpr attribute="Alias" context="#pop!literal-block-after-data" String="^(&space;+)&alias;" column="0" />
        <RegExpr attribute="Reference" context="#pop!literal-block-after-data" String="^(&space;+)&reference;" column="0" />
        <!-- The text after a space will be considered literal (empty text is captured) -->
        <RegExpr attribute="Data Types" context="#pop!literal-block-withdash-s1" String="^()&dataTypes;" column="0" />
        <RegExpr attribute="Alias" context="#pop!literal-block-withdash-s1" String="^()&alias;" column="0" />
        <RegExpr attribute="Reference" context="#pop!literal-block-withdash-s1" String="^()&reference;" column="0" />
      </context>

      <!-- Highlight data/attribute before the literal operator (Note that if there is a line
           break within a string or bracket, the literal line will not be highlighted). -->
      <context attribute="Attribute" lineEndContext="#pop#pop" name="before-literal-operator" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Operator" context="#pop!end-literal-operator" String="&literalOp;(?=&endValue;)" beginRegion="Literal" />

        <RegExpr attribute="Error" context="#pop#pop" String="(?:[&amp;\*]|!!)\S*&literalOp;(?=&endValue;)" />
        <RegExpr attribute="Data Types" context="#stay" String="&dataTypes;" />
        <RegExpr attribute="Alias" context="#stay" String="&alias;" />
        <RegExpr attribute="Reference" context="#stay" String="&reference;" />

        <DetectChar attribute="Operator" context="list" char="[" beginRegion="List" />
        <DetectChar attribute="Operator" context="hash" char="{" beginRegion="Hash" />
        <DetectChar attribute="String" context="string" char="'" beginRegion="String" />
        <DetectChar attribute="String" context="stringx" char="&quot;" beginRegion="String" />
      </context>

      <context attribute="Normal Text" lineEndContext="#pop#pop" name="dpoints-key-before-literal-operator" fallthrough="true" fallthroughContext="#pop#pop" noIndentationBasedFolding="true">
        <DetectChar attribute="Key Points Operator" context="#pop!key-before-literal-operator" char=":" />
      </context>
      <context attribute="Attribute" lineEndContext="#pop#pop" name="key-before-literal-operator" noIndentationBasedFolding="true">
        <IncludeRules context="before-literal-operator" />
        <DetectChar attribute="Operator" context="#stay" char="?" />
      </context>
      <context attribute="Attribute" lineEndContext="#pop" name="end-literal-operator" noIndentationBasedFolding="true">
        <RegExpr attribute="Comment" context="#pop!comment" String="(?:^|\s+)#" />
      </context>

      <!-- Common rules for the content of the literal blocks -->
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-default" noIndentationBasedFolding="true">
        <!-- End literal/folded block -->
        <RegExpr attribute="Normal Text" context="#pop" String="^\s*\S" lookAhead="true" column="0" endRegion="Literal" />
        <!-- Find literal/folded operator -->
        <RegExpr context="before-literal-operator" String="\S" lookAhead="true" />
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="literal-block-key-default" noIndentationBasedFolding="true">
        <!-- End literal/folded block -->
        <RegExpr attribute="Normal Text" context="#pop" String="^\s*\S" lookAhead="true" column="0" endRegion="Literal" />
        <!-- Detect Key before the literal/folded operator -->
        <RegExpr attribute="Key" context="dpoints-key-before-literal-operator" String="&keyAfterOp;(?=:\s)" />
        <RegExpr attribute="Normal Text" context="#pop" String="\S" lookAhead="true" endRegion="Literal" />
      </context>

      <!-- Content of the literal block: -->

      <!-- If the literal operator is starting the line (after a space, use block indentation) -->
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-only-operator" dynamic="true" noIndentationBasedFolding="true">
        <StringDetect attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="%1" dynamic="true" column="0" />

        <RegExpr attribute="Normal Text" context="#pop" String="^\s*\S" lookAhead="true" column="0" endRegion="Literal" />
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s)#" />
        <RegExpr context="#pop" String="\S" lookAhead="true" endRegion="Literal" />
      </context>
      <!-- If the literal operator is the first character of a line (or after header) -->
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-simple" noIndentationBasedFolding="true">
        <DetectSpaces attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" column="0" />

        <RegExpr attribute="Normal Text" context="#pop" String="^\s*\S" lookAhead="true" column="0" endRegion="Literal" />
        <RegExpr attribute="Comment" context="comment" String="(?:^|\s)#" />
      </context>
      <!-- If there is a data type or other content before the liretal operator (use block indentation) -->
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-after-data" dynamic="true" noIndentationBasedFolding="true">
        <StringDetect attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="%1" dynamic="true" column="0" />

        <RegExpr attribute="Normal Text" context="#pop" String="^\s*\S" lookAhead="true" column="0" endRegion="Literal" />
        <RegExpr context="before-literal-operator" String="\S" lookAhead="true" />
      </context>
      <!-- If there is a key before the literal operator -->
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-key" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1\s" dynamic="true" column="0" />

        <RegExpr attribute="Normal Text" context="#pop" String="^\s*\S" lookAhead="true" column="0" endRegion="Literal" />
        <!-- Attribute of the Key (the Key was previously highlighted) -->
        <RegExpr attribute="Key Points Operator" context="key-before-literal-operator" String=":\s" />
        <RegExpr context="key-before-literal-operator" String="\S" lookAhead="true" />
      </context>
      <context attribute="Literal/Folded Block" lineEndContext="#pop" name="injected-sql" noIndentationBasedFolding="true">
        <!-- CartoCSS is a preprocessor for Mapnik, which supports exclusivly
             PostgreSQL (with the PostGIS extension) as database, therefore we
             choose the Postgre flavor of SQL syntax hightlighting here.
             The includeAttrib="true" in <IncludeRules> will override
             the attribute="Literal/Folded Block" of the current <context>
             with attribute="WHATEVER" of the default <context> of
             "##SQL (PostgreSQL)". This ensures that we get the identical
             highlighting as in SQL even for default text that has no special
             rule in the “SQL (PostgreSQL)” syntax highlighting. -->
        <IncludeRules context="##SQL (PostgreSQL)" includeAttrib="true"/>
      </context>

      <!-- If there are dashes/"?" before the literal operator -->
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-withdash-s1" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-default" />
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-withdash-s2" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1%2&space;\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-default" />
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-withdash-s3" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1%2%3&space;{2}\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-default" />
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-withdash-s4" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1%2%3%4&space;{3}\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-default" />
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-withdash-s5" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1%2%3%4%5&space;{4}\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-default" />
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-withdash-s6" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1%2%3%4%5%6&space;{5}\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-default" />
      </context>
      <!-- If there are dashes/"?" and a Key before the literal operator -->
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-key-withdash-s2" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1%2&space;\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-key-default" />
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-key-withdash-s3" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1%2%3&space;{2}\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-key-default" />
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-key-withdash-s4" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1%2%3%4&space;{3}\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-key-default" />
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-key-withdash-s5" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1%2%3%4%5&space;{4}\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-key-default" />
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-key-withdash-s6" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1%2%3%4%5%6&space;{5}\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-key-default" />
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="literal-block-key-withdash-s7" dynamic="true" noIndentationBasedFolding="true">
        <RegExpr attribute="Literal/Folded Block" context="injected-sql" lookAhead="true" String="^%1%2%3%4%5%6%7&space;{6}\s" dynamic="true" column="0" />
        <IncludeRules context="literal-block-key-default" />
      </context>
    </contexts>

    <itemDatas>
      <itemData name="Normal Text" defStyleNum="dsAttribute" spellChecking="false" />
      <itemData name="Attribute" defStyleNum="dsAttribute" spellChecking="false" />
      <itemData name="List" defStyleNum="dsAttribute" spellChecking="false" />
      <itemData name="Hash" defStyleNum="dsAttribute" spellChecking="false" />
      <itemData name="Comment" defStyleNum="dsComment" />
      <itemData name="End of Document" defStyleNum="dsComment" />
      <itemData name="Document Header" defStyleNum="dsPreprocessor" spellChecking="false" />
      <itemData name="Data Types" defStyleNum="dsOthers" spellChecking="false" />
      <itemData name="Alias" defStyleNum="dsOthers" spellChecking="false" />
      <itemData name="Reference" defStyleNum="dsOthers" spellChecking="false" />
      <itemData name="Key" defStyleNum="dsFunction" bold="1" spellChecking="false" />
      <itemData name="Directive" defStyleNum="dsPreprocessor" spellChecking="false" />
      <itemData name="Key Points Operator" defStyleNum="dsKeyword" spellChecking="false" />
      <itemData name="Operator" defStyleNum="dsKeyword" spellChecking="false" />
      <itemData name="String" defStyleNum="dsString" spellChecking="false" />
      <itemData name="Escaped Character" defStyleNum="dsSpecialChar" spellChecking="false" />
      <itemData name="Literal/Folded Operator" defStyleNum="dsChar" spellChecking="false" bold="1" />
      <itemData name="Literal/Folded Block" defStyleNum="dsNormal" spellChecking="false" />
      <itemData name="Null" defStyleNum="dsChar" spellChecking="false" />
      <itemData name="Boolean" defStyleNum="dsChar" spellChecking="false" />
      <itemData name="Integer" defStyleNum="dsDecVal" spellChecking="false" />
      <itemData name="Float" defStyleNum="dsFloat" spellChecking="false" />
      <itemData name="Error" defStyleNum="dsError" spellChecking="false" />
      <itemData name="Alert" defStyleNum="dsAlert" backgroundColor="#EF9A9A" spellChecking="false" />
    </itemDatas>
  </highlighting>

  <general>
    <folding indentationsensitive="1" />
    <emptyLines>
      <emptyLine regexpr="(?:\s+|\s*#.*)"/>
    </emptyLines>
    <comments>
      <comment name="singleLine" start="#" position="afterwhitespace" />
    </comments>
    <keywords casesensitive="1"/>
  </general>
</language>
<!-- kate: replace-tabs on; tab-width 2; indent-width 2; -->
