mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:20:11 +01:00
Setting "type" to bright red to make comparison obvious: (screenshots taken from VSCode) Before <img width="446" height="150" alt="Screenshot 2026-07-20 135558" src="https://github.com/user-attachments/assets/81249005-99f1-47bb-af4f-ad6e8f2404fb" /> After <img width="429" height="149" alt="Screenshot 2026-07-20 135738" src="https://github.com/user-attachments/assets/acc83086-fe19-4a18-a833-968daed56229" /> I'm not super familiar with textmate/highlightjs, but I think what was happening on line 5 is that the "type" scope is being extended to the `=` after `.y`. Adding `,` as an "end" token fixes this, and I think this is what highlightjs already does. I've also added "unused" as a keyword.
539 lines
15 KiB
JSON
539 lines
15 KiB
JSON
{
|
|
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
|
"uuid": "4568a54d-9a79-41ac-a36b-05916252763b",
|
|
"name": "carbon",
|
|
"scopeName": "source.carbon",
|
|
"foldingStartMarker": "\\{\\s*$",
|
|
"foldingStopMarker": "^\\s*\\}",
|
|
"fileTypes": ["carbon"],
|
|
"patterns": [
|
|
{
|
|
"include": "#comments"
|
|
},
|
|
{
|
|
"include": "#cpp-inline"
|
|
},
|
|
{
|
|
"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": {
|
|
"cpp-inline": {
|
|
"patterns": [
|
|
{
|
|
"comment": "C++ inline import (triple-quoted)",
|
|
"begin": "\\b(import)\\b\\s+\\b(Cpp)\\b\\s+\\b(inline)\\b\\s*(''')([^\\s'#]*\\n)?",
|
|
"beginCaptures": {
|
|
"1": { "name": "storage.type.carbon" },
|
|
"2": { "name": "support.type.property-name.carbon" },
|
|
"3": { "name": "storage.type.carbon" },
|
|
"4": { "name": "string.quoted.triple.carbon" },
|
|
"5": { "name": "constant.character.escape.carbon" }
|
|
},
|
|
"end": "(''')\\s*(;)",
|
|
"endCaptures": {
|
|
"1": { "name": "string.quoted.triple.carbon" },
|
|
"2": { "name": "punctuation.terminator.carbon" }
|
|
},
|
|
"contentName": "meta.embedded.block.cpp",
|
|
"patterns": [
|
|
{
|
|
"include": "source.cpp"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"comment": "C++ inline import (double-quoted)",
|
|
"begin": "\\b(import)\\b\\s+\\b(Cpp)\\b\\s+\\b(inline)\\b\\s*(\")",
|
|
"beginCaptures": {
|
|
"1": { "name": "storage.type.carbon" },
|
|
"2": { "name": "support.type.property-name.carbon" },
|
|
"3": { "name": "storage.type.carbon" },
|
|
"4": { "name": "string.quoted.double.carbon" }
|
|
},
|
|
"end": "(\")\\s*(;)",
|
|
"endCaptures": {
|
|
"1": { "name": "string.quoted.double.carbon" },
|
|
"2": { "name": "punctuation.terminator.carbon" }
|
|
},
|
|
"contentName": "meta.embedded.inline.cpp",
|
|
"patterns": [
|
|
{
|
|
"include": "source.cpp"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"comment": "C++ inline block (triple-quoted)",
|
|
"begin": "\\b(inline)\\b\\s+\\b(Cpp)\\b\\s*(''')([^\\s'#]*\\n)?",
|
|
"beginCaptures": {
|
|
"1": { "name": "storage.type.carbon" },
|
|
"2": { "name": "support.type.property-name.carbon" },
|
|
"3": { "name": "string.quoted.triple.carbon" },
|
|
"4": { "name": "constant.character.escape.carbon" }
|
|
},
|
|
"end": "(''')\\s*(;)",
|
|
"endCaptures": {
|
|
"1": { "name": "string.quoted.triple.carbon" },
|
|
"2": { "name": "punctuation.terminator.carbon" }
|
|
},
|
|
"contentName": "meta.embedded.block.cpp",
|
|
"patterns": [
|
|
{
|
|
"include": "source.cpp"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"comment": "C++ inline block (double-quoted)",
|
|
"begin": "\\b(inline)\\b\\s+\\b(Cpp)\\b\\s*(\")",
|
|
"beginCaptures": {
|
|
"1": { "name": "storage.type.carbon" },
|
|
"2": { "name": "support.type.property-name.carbon" },
|
|
"3": { "name": "string.quoted.double.carbon" }
|
|
},
|
|
"end": "(\")\\s*(;)",
|
|
"endCaptures": {
|
|
"1": { "name": "string.quoted.double.carbon" },
|
|
"2": { "name": "punctuation.terminator.carbon" }
|
|
},
|
|
"contentName": "meta.embedded.inline.cpp",
|
|
"patterns": [
|
|
{
|
|
"include": "source.cpp"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
"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|generic|impls|in|like|not|or|partial|ref|runtime|template|unused|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|inline|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": "(?<=\\bpackage\\s)\\w+"
|
|
},
|
|
{
|
|
"name": "support.class.carbon",
|
|
"match": "(?<=\\bCore\\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" }
|
|
]
|
|
}
|
|
}
|
|
}
|