Skip to content

Commit

Permalink
Syntax highlighter in VScode for carbon programming language (carbon-…
Browse files Browse the repository at this point in the history
…language#3953)

I have made the necessary changes to
https://github.com/carbon-language/carbon-lang/tree/trunk/utils/vscode
for the VScode syntax highlighter to work:

- [x] Changes have been tested and found to be working.

---------

Co-authored-by: Richard Smith <[email protected]>
Co-authored-by: Carbon Infra Bot <[email protected]>
  • Loading branch information
3 people authored and CJ-Johnson committed May 23, 2024
1 parent a7c3f90 commit 7464831
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 167 deletions.
157 changes: 0 additions & 157 deletions utils/textmate/Syntaxes/Carbon.plist

This file was deleted.

201 changes: 201 additions & 0 deletions utils/textmate/Syntaxes/carbon.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "carbon",
"foldingStartMarker": "\\{\\s*$",
"foldingStopMarker": "^\\s*\\}",
"fileTypes": ["carbon"],
"patterns": [
{
"include": "#comments"
},
{
"include": "#operators"
},
{
"include": "#special-keywords"
},
{
"include": "#numbers"
},
{
"include": "#reserved-words"
},
{
"include": "#operator-dedicated-keywords-statements"
},
{
"include": "#ctrl-statements"
},
{
"include": "#true-false"
},
{
"include": "#functions"
},
{
"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"
}
]
},
{
"include": "#customs"
}
],
"repository": {
"operators": {
"patterns": [
{
"name": "keyword.operator.carbon",
"match": "\\b(\\+|-|\\*|/|!)\\b"
}
]
},
"comments": {
"patterns": [
{
"begin": "(^[ \\t]+)?(?=//)",
"end": "(?!\\G)",
"patterns": [
{
"name": "comment.line.carbon",
"begin": "//",
"end": "$"
}
]
}
]
},
"string_escapes": {
"patterns": [
{
"name": "constant.character.escape.carbon",
"match": "\\\\([tnr'\"0\\0]|x[0-9A-F]{2}|u\\{[0-9A-F]{4,}\\})"
}
]
},
"special-keywords": {
"patterns": [
{
"name": "keyword.control.carbon",
"match": "\\b(break|case|continue|default|else|if|for|match|return|returned|then|while)\\b"
}
]
},
"operator-dedicated-keywords-statements": {
"patterns": [
{
"name": "keyword.other.carbon",
"match": "\\b(abstract|adapt|addr|alias|and|api|as|auto|base|choice|class|constraint|destructor|extend|final|fn|forall|friend|impl|impls|import|in|interface|let|library|like|namespace|not|observe|or|override|package|partial|private|protected|require|Self|template|type|var|virtual|where|_)\\b"
}
]
},
"reserved-words": {
"patterns": [
{
"name": "support.type.carbon",
"match": "\\b(As|bool|Carbon\\.Int|Carbon\\.UInt|f16|f32|f64|f128|i8|i16|i32|i64|i128|i256|Slice|String|StringView|type|u8|u16|u32|u64|u128|u256)\\b"
}
]
},
"true-false": {
"patterns": [
{
"name": "constant.language.carbon",
"match": "\\b(true|false)\\b"
}
]
},
"functions": {
"patterns": [
{
"name": "support.function.carbon",
"match": "\\b[a-zA-Z]+\\s*\\("
}
]
},
"customs": {
"patterns": [
{
"name": "support.class.carbon",
"match": "(?<=\\bpackage\\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]*)?)?"
}
]
}
},
"scopeName": "source.carbon"
}
1 change: 0 additions & 1 deletion utils/vscode/Carbon.plist

This file was deleted.

1 change: 1 addition & 0 deletions utils/vscode/carbon.tmLanguage.json
20 changes: 14 additions & 6 deletions utils/vscode/language-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@
"comments": {
"lineComment": "//"
},
// Symbols used as brackets.
"brackets": [
["(", ")"],
["{", "}"],
["[", "]"],
["{", "}"]
["(", ")"]
],
// Symbols that are auto closed when typing.
"autoClosingPairs": [
["(", ")"],
["{", "}"],
["[", "]"],
["{", "}"]
["(", ")"],
["\"", "\""],
["'", "'"]
],
// Symbols that can be used to surround a selection.
"surroundingPairs": [
["(", ")"],
["{", "}"],
["[", "]"],
["{", "}"]
["(", ")"],
["\"", "\""],
["'", "'"],
["'''", "'''"]
]
}
Loading

0 comments on commit 7464831

Please sign in to comment.