| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- {
- "$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": "#types"
- },
- {
- "include": "#functions"
- },
- {
- "include": "#variables"
- },
- {
- "include": "#operators"
- },
- {
- "include": "#special-keywords"
- },
- {
- "include": "#introducer-keywords"
- },
- {
- "include": "#modifier-keywords"
- },
- {
- "include": "#misc-keywords"
- },
- {
- "include": "#self-keywords"
- },
- {
- "include": "#underscore"
- },
- {
- "include": "#true-false"
- },
- {
- "include": "#type-literals"
- },
- {
- "include": "#numbers"
- },
- {
- "include": "#parameter-bindings"
- },
- {
- "include": "#customs"
- }
- ],
- "repository": {
- "comments": {
- "patterns": [
- {
- "name": "comment.line.carbon",
- "match": "^\\s*(?=//\\s).*$"
- },
- {
- "name": "comment.line.carbon",
- "match": "^\\s*//@dump-sem-ir-(begin|end)\\s*$"
- },
- {
- "name": "comment.line.carbon",
- "match": "^\\s*//@include-in-dumps\\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"
- }
- ]
- }
- ]
- },
- "types": {
- "name": "meta.type.carbon",
- "patterns": [
- {
- "comment": "Matches type, constraint, and implementation declarations, and explicit casts.",
- "begin": "\\b((adapt|alias|class|constraint|interface|impl)|(as|impls))\\b",
- "beginCaptures": {
- "2": { "name": "storage.type.carbon" },
- "3": { "name": "keyword.control.carbon" }
- },
- "end": "(?=[;{])",
- "patterns": [
- { "include": "#common" },
- { "include": "#parameter-bindings" },
- {
- "name": "support.type.carbon",
- "match": "\\w+"
- }
- ]
- },
- {
- "comment": "Matches types in bindings.",
- "begin": ":!?",
- "end": "(?=([;{=]|->|in|where))",
- "patterns": [
- { "include": "#common" },
- { "include": "#variables" },
- { "include": "#parameter-bindings" },
- {
- "name": "support.type.carbon",
- "match": "\\w+"
- }
- ]
- },
- {
- "comment": "Matches function return types.",
- "begin": "->",
- "end": "(?=([;{]|=>))",
- "patterns": [
- { "include": "#common" },
- {
- "name": "support.type.carbon",
- "match": "\\w+"
- }
- ]
- },
- {
- "comment": "Matches types in where clause.",
- "begin": "\\bwhere\\b",
- "beginCaptures": {
- "0": { "name": "keyword.control.carbon" }
- },
- "end": "(?=[;{])",
- "patterns": [
- { "include": "#common" },
- { "include": "#variables" },
- { "include": "#parameter-bindings" },
- {
- "name": "support.type.carbon",
- "match": "\\w+"
- }
- ]
- },
- {
- "comment": "Matches choices.",
- "begin": "\\bchoice\\b",
- "beginCaptures": {
- "0": { "name": "storage.type.carbon" }
- },
- "end": "(?=[;}])",
- "patterns": [
- { "include": "#common" },
- { "include": "#variables" },
- { "include": "#parameter-bindings" },
- {
- "name": "support.type.carbon",
- "match": "\\w+"
- },
- {
- "comment": "Matches the choice values.",
- "begin": "\\{",
- "end": "(?=})",
- "patterns": [
- { "include": "#common" },
- {
- "name": "variable.other.enummember.carbon",
- "match": "\\w+"
- }
- ]
- }
- ]
- }
- ]
- },
- "functions": {
- "name": "meta.function.carbon",
- "patterns": [
- {
- "comment": "Matches function declarations.",
- "begin": "\\bfn\\b",
- "beginCaptures": {
- "0": { "name": "storage.type.carbon" }
- },
- "end": "(?=[\\[\\(])",
- "patterns": [
- { "include": "#common" },
- {
- "name": "support.function.carbon",
- "match": "\\w+"
- }
- ]
- }
- ]
- },
- "variables": {
- "name": "meta.variable.carbon",
- "patterns": [
- {
- "comment": "Matches variable declarations.",
- "begin": "\\b(var|let)\\b",
- "beginCaptures": {
- "0": { "name": "storage.type.carbon" }
- },
- "end": "(?=:)",
- "patterns": [
- { "include": "#common" },
- {
- "name": "support.variable.carbon",
- "match": "\\w+"
- }
- ]
- }
- ]
- },
- "operators": {
- "patterns": [
- {
- "name": "keyword.operator.carbon",
- "match": "\\b(>>=|<=>|<<=|\\&=|==|!=|>=|>>|<=|<<|-=|->|--|%=|\\|=|\\+=|\\+\\+|/=|\\*=|\\&|\\^|=|>|<|-|%|\\.|\\||\\+|/|\\*)\\b"
- },
- {
- "name": "keyword.control.carbon",
- "match": "\\b(and|as|impls|in|like|not|or|partial|ref|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|const|extend|extern|final|private|protected|static|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(array|bool|char|str|type)\\b"
- },
- {
- "name": "constant.language.carbon",
- "comment": "Match common numeric type literals. Language server should highlight other valid literals.",
- "match": "\\b[iuf](8|16|32|64|128)\\b"
- }
- ]
- },
- "numbers": {
- "comment": "Invalid formats are also highlighted. Language server handles error highlighting",
- "patterns": [
- {
- "name": "constant.numeric.carbon",
- "match": "0x[_0-9a-fA-F]*(\\.[_0-9a-fA-F]+(p[-+]?[0-9]+)?)?"
- },
- {
- "name": "constant.numeric.carbon",
- "match": "0b[_01]*"
- },
- {
- "name": "constant.numeric.carbon",
- "match": "[0-9][_0-9]*(\\.[_0-9]+(e[-+]?[0-9]+)?)?"
- }
- ]
- },
- "parameter-bindings": {
- "patterns": [
- {
- "comment": "Matches parameter bindings.",
- "match": "\\b(\\w+)\\s*(?=:)",
- "captures": {
- "1": { "name": "support.variable.carbon" }
- }
- }
- ]
- },
- "customs": {
- "comment": "For rules that should be checked last.",
- "patterns": [
- {
- "name": "support.class.carbon",
- "match": "(?<=\\b(package|Core)\\s)\\w+"
- },
- {
- "name": "support.type.property-name.carbon",
- "match": "(?<=\\bimport\\s)\\w+"
- },
- {
- "comment": "Matches function calls.",
- "name": "support.function.carbon",
- "match": "\\b\\w+\\s*\\("
- },
- {
- "comment": "Matches unidentified words as variables.",
- "name": "support.variable.carbon",
- "match": "\\b\\w+\\b"
- }
- ]
- },
- "common": {
- "comments": [
- "For including comments, operators, keywords, literals, and language constants ",
- "in other rules that use begin/end. This way we do not accidentally override their ",
- "highlighting in complex rules."
- ],
- "patterns": [
- { "include": "#comments" },
- { "include": "#strings" },
- { "include": "#operators" },
- { "include": "#special-keywords" },
- { "include": "#introducer-keywords" },
- { "include": "#modifier-keywords" },
- { "include": "#misc-keywords" },
- { "include": "#self-keywords" },
- { "include": "#true-false" },
- { "include": "#type-literals" },
- { "include": "#numbers" }
- ]
- }
- }
- }
|