<lexer>
  <config>
    <name>ArangoDB AQL</name>
    <alias>aql</alias>
    <filename>*.aql</filename>
    <mime_type>text/x-aql</mime_type>
    <case_insensitive>true</case_insensitive>
    <dot_all>true</dot_all>
    <ensure_nl>true</ensure_nl>
  </config>
  <rules>
    <state name="comments-and-whitespace">
      <rule pattern="\s+">
        <token type="Text"/>
      </rule>
      <rule pattern="//.*?\n">
        <token type="CommentSingle"/>
      </rule>
      <rule pattern="/\*">
        <token type="CommentMultiline"/>
        <push state="multiline-comment"/>
      </rule>
    </state>
    <state name="multiline-comment">
      <rule pattern="[^*]+">
        <token type="CommentMultiline"/>
      </rule>
      <rule pattern="\*/">
        <token type="CommentMultiline"/>
        <pop depth="1"/>
      </rule>
      <rule pattern="\*">
        <token type="CommentMultiline"/>
      </rule>
    </state>
    <state name="double-quote">
      <rule pattern="\\.">
        <token type="LiteralStringDouble"/>
      </rule>
      <rule pattern="[^&#34;\\]+">
        <token type="LiteralStringDouble"/>
      </rule>
      <rule pattern="&#34;">
        <token type="LiteralStringDouble"/>
        <pop depth="1"/>
      </rule>
    </state>
    <state name="single-quote">
      <rule pattern="\\.">
        <token type="LiteralStringSingle"/>
      </rule>
      <rule pattern="[^&#39;\\]+">
        <token type="LiteralStringSingle"/>
      </rule>
      <rule pattern="&#39;">
        <token type="LiteralStringSingle"/>
        <pop depth="1"/>
      </rule>
    </state>
    <state name="backtick">
      <rule pattern="\\.">
        <token type="Name"/>
      </rule>
      <rule pattern="[^`\\]+">
        <token type="Name"/>
      </rule>
      <rule pattern="`">
        <token type="Name"/>
        <pop depth="1"/>
      </rule>
    </state>
    <state name="forwardtick">
      <rule pattern="\\.">
        <token type="Name"/>
      </rule>
      <rule pattern="[^´\\]+">
        <token type="Name"/>
      </rule>
      <rule pattern="´">
        <token type="Name"/>
        <pop depth="1"/>
      </rule>
    </state>
    <state name="identifier">
      <rule pattern="(?:\$?|_+)[a-z]+[_a-z0-9]*">
        <token type="Name"/>
      </rule>
      <rule pattern="`">
        <token type="Name"/>
        <push state="backtick"/>
      </rule>
      <rule pattern="´">
        <token type="Name"/>
        <push state="forwardtick"/>
      </rule>
    </state>
    <state name="root">
      <rule>
        <include state="comments-and-whitespace"/>
      </rule>
      <rule pattern="0b[01]+">
        <token type="LiteralNumberBin"/>
      </rule>
      <rule pattern="0x[0-9a-f]+">
        <token type="LiteralNumberHex"/>
      </rule>
      <rule pattern="(?:0|[1-9][0-9]*)(?![\.e])">
        <token type="LiteralNumberInteger"/>
      </rule>
      <rule pattern="(?:(?:0|[1-9][0-9]*)(?:\.[0-9]+)?|\.[0-9]+)(?:e[\-\+]?[0-9]+)?">
        <token type="LiteralNumberFloat"/>
      </rule>
      <rule pattern="@@(?:_+[a-z0-9]+[a-z0-9_]*|[a-z0-9][a-z0-9_]*)">
        <token type="NameVariableGlobal"/>
      </rule>
      <rule pattern="@(?:_+[a-z0-9]+[a-z0-9_]*|[a-z0-9][a-z0-9_]*)">
        <token type="NameVariable"/>
      </rule>
      <rule pattern="=~|!~|[=!&lt;&gt;]=?|[%?:/*+-]|\.\.|&amp;&amp;|\|\|">
        <token type="Operator"/>
      </rule>
      <rule pattern="[.,(){}\[\]]">
        <token type="Punctuation"/>
      </rule>
      <rule pattern="[a-zA-Z0-9][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)+(?=\s*\()">
        <token type="NameFunction"/>
      </rule>
      <rule pattern="(WITH)(\s+)(COUNT)(\s+)(INTO)\b">
        <bygroups>
          <token type="KeywordReserved"/>
          <token type="Text"/>
          <token type="KeywordPseudo"/>
          <token type="Text"/>
          <token type="KeywordReserved"/>
        </bygroups>
      </rule>
      <rule pattern="(?:KEEP|PRUNE|SEARCH|TO)\b">
        <token type="KeywordPseudo"/>
      </rule>
      <rule pattern="OPTIONS(?=\s*\{)">
        <token type="KeywordPseudo"/>
      </rule>
      <rule pattern="(?:AGGREGATE|ALL|ALL_SHORTEST_PATHS|AND|ANY|ASC|AT LEAST|COLLECT|DESC|DISTINCT|FILTER|FOR|GRAPH|IN|INBOUND|INSERT|INTO|K_PATHS|K_SHORTEST_PATHS|LIKE|LIMIT|NONE|NOT|OR|OUTBOUND|REMOVE|REPLACE|RETURN|SHORTEST_PATH|SORT|UPDATE|UPSERT|WITH|WINDOW)\b">
        <token type="KeywordReserved"/>
      </rule>
      <rule pattern="LET\b">
        <token type="KeywordDeclaration"/>
      </rule>
      <rule pattern="(?:true|false|null)\b">
        <token type="KeywordConstant"/>
      </rule>
      <rule pattern="(?-i)(?:CURRENT|NEW|OLD)\b">
        <token type="NameBuiltinPseudo"/>
      </rule>
      <rule pattern="(?:to_bool|to_number|to_char|to_string|to_array|to_list|is_null|is_bool|is_number|is_string|is_array|is_list|is_object|is_document|is_datestring|typename|json_stringify|json_parse|concat|concat_separator|char_length|lower|upper|substring|substring_bytes|left|right|trim|reverse|repeat|contains|log|log2|log10|exp|exp2|sin|cos|tan|asin|acos|atan|atan2|radians|degrees|pi|regex_test|regex_replace|like|floor|ceil|round|abs|rand|random|sqrt|pow|length|count|min|max|average|avg|sum|product|median|variance_population|variance_sample|variance|percentile|bit_and|bit_or|bit_xor|bit_negate|bit_test|bit_popcount|bit_shift_left|bit_shift_right|bit_construct|bit_deconstruct|bit_to_string|bit_from_string|first|last|unique|outersection|interleave|in_range|jaccard|matches|merge|merge_recursive|has|attributes|keys|values|entries|unset|unset_recursive|keep|keep_recursive|near|within|within_rectangle|is_in_polygon|distance|fulltext|stddev_sample|stddev_population|stddev|slice|nth|position|contains_array|translate|zip|call|apply|push|append|pop|shift|unshift|remove_value|remove_values|remove_nth|replace_nth|date_now|date_timestamp|date_iso8601|date_dayofweek|date_year|date_month|date_day|date_hour|date_minute|date_second|date_millisecond|date_dayofyear|date_isoweek|date_isoweekyear|date_leapyear|date_quarter|date_days_in_month|date_trunc|date_round|date_add|date_subtract|date_diff|date_compare|date_format|date_utctolocal|date_localtoutc|date_timezone|date_timezones|fail|passthru|v8|sleep|schema_get|schema_validate|shard_id|version|noopt|noeval|not_null|first_list|first_document|parse_identifier|parse_collection|parse_key|current_user|current_database|collection_count|pregel_result|collections|document|decode_rev|range|union|union_distinct|minus|intersection|flatten|is_same_collection|check_document|ltrim|rtrim|find_first|find_last|split|substitute|ipv4_to_number|ipv4_from_number|is_ipv4|md5|sha1|sha256|sha512|crc32|fnv64|hash|random_token|to_base64|to_hex|encode_uri_component|soundex|assert|warn|is_key|sorted|sorted_unique|count_distinct|count_unique|levenshtein_distance|levenshtein_match|regex_matches|regex_split|ngram_match|ngram_similarity|ngram_positional_similarity|uuid|tokens|exists|starts_with|phrase|min_match|bm25|tfidf|boost|analyzer|offset_info|value|cosine_similarity|decay_exp|decay_gauss|decay_linear|l1_distance|l2_distance|minhash|minhash_count|minhash_error|minhash_match|geo_point|geo_multipoint|geo_polygon|geo_multipolygon|geo_linestring|geo_multilinestring|geo_contains|geo_intersects|geo_equals|geo_distance|geo_area|geo_in_range)(?=\s*\()">
        <token type="NameFunction"/>
      </rule>
      <rule pattern="&#34;">
        <token type="LiteralStringDouble"/>
        <push state="double-quote"/>
      </rule>
      <rule pattern="&#39;">
        <token type="LiteralStringSingle"/>
        <push state="single-quote"/>
      </rule>
      <rule pattern="#\d+\b">
        <token type="NameLabel"/>
      </rule>
      <rule>
        <include state="identifier"/>
      </rule>
    </state>
  </rules>
</lexer>