{
  "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
  "name": "carbon",
  "scopeName": "source.carbon",
  "foldingStartMarker": "\\{\\s*$",
  "foldingStopMarker": "^\\s*\\}",
  "fileTypes": ["carbon"],
  "patterns": [
    {
      "include": "#comments"
    },
    {
      "include": "#strings"
    },
    {
      "include": "#operators"
    },
    {
      "include": "#special-keywords"
    },
    {
      "include": "#numbers"
    },
    {
      "include": "#introducer-keywords"
    },
    {
      "include": "#modifier-keywords"
    },
    {
      "include": "#misc-keywords"
    },
    {
      "include": "#self-keywords"
    },
    {
      "include": "#underscore"
    },
    {
      "include": "#true-false"
    },
    {
      "include": "#type-literals"
    },
    {
      "include": "#functions"
    },
    {
      "include": "#customs"
    }
  ],
  "repository": {
    "comments": {
      "patterns": [
        {
          "name": "comment.line.carbon",
          "match": "^\\s*(?=//\\s).*$"
        },
        {
          "name": "comment.line.carbon",
          "match": "^\\s*//@dump-sem-ir-(begin|end)\\s*$"
        }
      ]
    },
    "string_escapes": {
      "patterns": [
        {
          "name": "constant.character.escape.carbon",
          "match": "\\\\([tnr'\"0\\0]|x[0-9A-F]{2}|u\\{[0-9A-F]{4,}\\})"
        }
      ]
    },
    "strings": {
      "patterns": [
        {
          "name": "string.quoted.triple.carbon",
          "begin": "'''([^\\s'#]*\\n)?",
          "end": "'''",
          "beginCaptures": {
            "1": {
              "name": "constant.character.escape.carbon"
            }
          },
          "patterns": [
            {
              "include": "#string_escapes"
            }
          ]
        },
        {
          "name": "string.quoted.double.carbon",
          "begin": "\"",
          "end": "\"",
          "patterns": [
            {
              "include": "#string_escapes"
            }
          ]
        }
      ]
    },
    "operators": {
      "patterns": [
        {
          "name": "keyword.operator.carbon",
          "match": "\\b(>>=|<=>|<<=|\\&=|==|!=|>=|>>|<=|<<|-=|->|--|%=|\\|=|\\+=|\\+\\+|/=|\\*=|\\&|\\^|=|>|<|-|%|.|\\||\\+|/|\\*)\\b"
        },
        {
          "name": "keyword.operator.carbon",
          "match": "\\b(addr|and|as|impls|in|like|not|or|partial|template|where)\\b"
        }
      ]
    },
    "special-keywords": {
      "patterns": [
        {
          "name": "keyword.control.carbon",
          "match": "\\b(break|case|continue|else|if|for|match|return|returned|then|while)\\b"
        },
        {
          "name": "keyword.control.carbon",
          "match": "\\b(default)\\b(?=\\s*=>)"
        }
      ]
    },
    "introducer-keywords": {
      "patterns": [
        {
          "name": "storage.type.carbon",
          "match": "\\b(adapt|alias|choice|class|constraint|fn|import|interface|let|library|namespace|var)\\b"
        },
        {
          "name": "storage.type.carbon",
          "match": "\\b(base)\\b(?!\\s*class\\b)"
        },
        {
          "name": "storage.type.carbon",
          "match": "\\b(export)\\b(?!\\s*import\\b)"
        },
        {
          "name": "storage.type.carbon",
          "match": "\\b(impl)\\b(?!\\s*(fn|library|package)\\b)"
        },
        {
          "name": "storage.type.carbon",
          "match": "\\b(package)\\b(?!\\.)"
        }
      ]
    },
    "modifier-keywords": {
      "patterns": [
        {
          "name": "storage.modifier.carbon",
          "match": "\\b(abstract|extend|extern|final|private|protected|virtual)\\b"
        },
        {
          "name": "storage.modifier.carbon",
          "match": "\\b(base)\\b(?=\\s*class\\b)"
        },
        {
          "name": "storage.modifier.carbon",
          "match": "\\b(default)\\b(?!\\s*=>)"
        },
        {
          "name": "storage.modifier.carbon",
          "match": "\\b(export)\\b(?=\\s*import\\b)"
        },
        {
          "name": "storage.modifier.carbon",
          "match": "\\b(impl)\\b(?=\\s*(fn|library|package)\\b)"
        }
      ]
    },
    "misc-keywords": {
      "patterns": [
        {
          "name": "keyword.other.carbon",
          "match": "\\b(auto|destructor|forall|friend|observe|override|require)\\b"
        },
        {
          "name": "keyword.other.carbon",
          "match": "(?<=\\.)\\b(base)\\b"
        }
      ]
    },
    "self-keywords": {
      "patterns": [
        {
          "name": "variable.language.carbon",
          "match": "\\b(self|Self)\\b"
        }
      ]
    },
    "underscore": {
      "patterns": [
        {
          "name": "variable.language.carbon",
          "match": "\\b(_)\\b"
        }
      ]
    },
    "true-false": {
      "patterns": [
        {
          "name": "constant.language.carbon",
          "match": "\\b(true|false)\\b"
        }
      ]
    },
    "type-literals": {
      "patterns": [
        {
          "name": "constant.language.carbon",
          "match": "\\b(bool|[iuf][1-9][0-9]*|type)\\b"
        }
      ]
    },
    "functions": {
      "patterns": [
        {
          "name": "support.function.carbon",
          "match": "\\b[a-zA-Z]+\\s*\\("
        }
      ]
    },
    "customs": {
      "patterns": [
        {
          "name": "support.class.carbon",
          "match": "(?<=\\b(package|Core)\\s)\\w+"
        },
        {
          "name": "support.variable.carbon",
          "match": "(?<=\\s*\\.)\\w+"
        },
        {
          "name": "support.variable.carbon",
          "match": "(?<=\\bas\\s)\\w+"
        },
        {
          "name": "support.variable.carbon",
          "match": "\\w+(?=\\s*:)"
        },
        {
          "name": "support.variable.carbon",
          "match": "(?<=\\blet\\s)\\w+"
        },
        {
          "name": "support.variable.carbon",
          "match": "(?<=\\bvar\\s)\\w+"
        },
        {
          "name": "support.function.carbon",
          "match": "(?<=\\bfn\\s)\\w+"
        },
        {
          "name": "support.other.carbon",
          "match": "(?<=\\bimpl\\s)\\w+"
        },
        {
          "name": "support.type.property-name.carbon",
          "match": "(?<=\\bimport\\s)\\w+"
        },
        {
          "name": "support.class.carbon",
          "match": "(?<=\\bclass\\s)\\w+"
        }
      ]
    },
    "numbers": {
      "patterns": [
        {
          "name": "constant.numeric.carbon",
          "match": "0x[_0-9A-F]+(\\.[_0-9A-F]+(p[-+]?[1-9][0-9]*)?)?"
        },
        {
          "name": "constant.numeric.carbon",
          "match": "0b[_01]+"
        },
        {
          "name": "constant.numeric.carbon",
          "match": "[1-9][_0-9]*(\\.[_0-9]+(e[-+]?[1-9][0-9]*)?)?"
        }
      ]
    }
  }
}
