{
  "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
  "name": "U",
  "scopeName": "source.u",
  "fileTypes": ["u", "gen.u"],
  "patterns": [
    { "include": "#comments" },
    { "include": "#strings" },
    { "include": "#template-strings" },
    { "include": "#numbers" },
    { "include": "#keywords" },
    { "include": "#modifiers" },
    { "include": "#types" },
    { "include": "#constants" },
    { "include": "#function-declaration" },
    { "include": "#data-declaration" },
    { "include": "#operators" },
    { "include": "#identifiers" }
  ],
  "repository": {
    "comments": {
      "patterns": [
        {
          "name": "comment.line.documentation.u",
          "match": "///.*$",
          "patterns": [
            {
              "name": "storage.type.annotation.u",
              "match": "@(intent|constraint|perf|example|security|generated|meta|regen|footer)\\b"
            }
          ]
        },
        {
          "name": "comment.line.double-slash.u",
          "match": "//.*$"
        }
      ]
    },
    "strings": {
      "patterns": [
        {
          "name": "string.quoted.double.u",
          "begin": "\"",
          "end": "\"",
          "patterns": [
            {
              "name": "constant.character.escape.u",
              "match": "\\\\."
            },
            {
              "name": "meta.embedded.expression.u",
              "begin": "\\$\\{",
              "end": "\\}",
              "beginCaptures": { "0": { "name": "punctuation.definition.interpolation.begin.u" } },
              "endCaptures": { "0": { "name": "punctuation.definition.interpolation.end.u" } },
              "patterns": [{ "include": "source.u" }]
            }
          ]
        }
      ]
    },
    "template-strings": {
      "patterns": [
        {
          "name": "string.template.u",
          "begin": "`",
          "end": "`",
          "patterns": [
            {
              "name": "meta.embedded.expression.u",
              "begin": "\\$\\{",
              "end": "\\}",
              "beginCaptures": { "0": { "name": "punctuation.definition.interpolation.begin.u" } },
              "endCaptures": { "0": { "name": "punctuation.definition.interpolation.end.u" } },
              "patterns": [{ "include": "source.u" }]
            }
          ]
        }
      ]
    },
    "numbers": {
      "patterns": [
        {
          "name": "constant.numeric.hex.u",
          "match": "\\b0[xX][0-9a-fA-F]+\\b"
        },
        {
          "name": "constant.numeric.binary.u",
          "match": "\\b0[bB][01]+\\b"
        },
        {
          "name": "constant.numeric.float.u",
          "match": "\\b[0-9]+\\.[0-9]+\\b"
        },
        {
          "name": "constant.numeric.integer.u",
          "match": "\\b[0-9]+\\b"
        }
      ]
    },
    "keywords": {
      "patterns": [
        {
          "name": "keyword.control.return.u",
          "match": "\\br\\s*=>"
        },
        {
          "name": "keyword.control.throw.u",
          "match": "\\bx\\s+(?=[A-Z])"
        },
        {
          "name": "keyword.control.u",
          "match": "(?<=^|\\t|\\s)(?:a|e|o|r|w|x)(?=\\s|$|\\(|\\.)"
        },
        {
          "name": "keyword.declaration.function.u",
          "match": "(?<=^|\\t|\\s)(?:u\\s+)?(?:a\\s+)?(?:z\\s+)?f(?=\\s*[+A-Za-z_])"
        },
        {
          "name": "keyword.declaration.data.u",
          "match": "(?<=^|\\t|\\s)d(?=\\s+[A-Z])"
        },
        {
          "name": "keyword.other.copy.u",
          "match": "(?<=^|\\t|\\s)c(?=\\s|\\+)"
        },
        {
          "name": "variable.language.this.u",
          "match": "\\bt\\."
        }
      ]
    },
    "modifiers": {
      "patterns": [
        {
          "name": "storage.modifier.u",
          "match": "[+-][MEDRNAGV]\\b"
        }
      ]
    },
    "types": {
      "patterns": [
        {
          "name": "support.type.primitive.u",
          "match": "\\b(?:I|N|S|L|B|D|Q|I8|I16|I32|I64|U8|U16|U32|U64|N32|N64)\\b"
        },
        {
          "name": "entity.name.type.u",
          "match": "\\b[A-Z][a-zA-Z0-9]+\\b"
        }
      ]
    },
    "constants": {
      "patterns": [
        {
          "name": "constant.language.u",
          "match": "\\b(?:none|true|false)\\b"
        },
        {
          "name": "constant.language.infinity.u",
          "match": "(?<=\\s|\\[)w(?=\\s|\\]|$)"
        }
      ]
    },
    "function-declaration": {
      "patterns": [
        {
          "match": "(?<=f\\s)([a-z_][a-zA-Z0-9_]*)\\s*(?=\\(|\\[)",
          "captures": {
            "1": { "name": "entity.name.function.u" }
          }
        }
      ]
    },
    "data-declaration": {
      "patterns": [
        {
          "match": "(?<=d\\s)([A-Z][a-zA-Z0-9]*)\\s*(?::\\s*([A-Z][a-zA-Z0-9]*))?",
          "captures": {
            "1": { "name": "entity.name.type.class.u" },
            "2": { "name": "entity.other.inherited-class.u" }
          }
        }
      ]
    },
    "operators": {
      "patterns": [
        {
          "name": "keyword.operator.arrow.u",
          "match": "=>|->|<<"
        },
        {
          "name": "keyword.operator.comparison.u",
          "match": "==|!=|<=|>=|<|>"
        },
        {
          "name": "keyword.operator.logical.u",
          "match": "&|\\||!"
        },
        {
          "name": "keyword.operator.arithmetic.u",
          "match": "[+\\-*/%]"
        },
        {
          "name": "keyword.operator.guard.u",
          "match": "\\?"
        },
        {
          "name": "keyword.operator.range.u",
          "match": "\\.\\."
        },
        {
          "name": "keyword.operator.type-narrow.u",
          "match": "::"
        },
        {
          "name": "keyword.operator.assignment.u",
          "match": "(?<![=!<>])=(?!=)"
        }
      ]
    },
    "identifiers": {
      "patterns": [
        {
          "name": "variable.other.u",
          "match": "\\b[a-z_][a-zA-Z0-9_]*\\b"
        }
      ]
    }
  }
}
