Fix C++ syntax highlighting, and improve C & WGSL highlighting (#4079)

This commit is contained in:
Chickenkeeper 2022-10-14 02:31:32 +01:00 committed by GitHub
parent cf4a5cca96
commit b4e795d704
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 274 additions and 175 deletions

View file

@ -184,7 +184,7 @@ args = { console = "internalConsole", attachCommands = [ "platform select remote
[[grammar]] [[grammar]]
name = "c" name = "c"
source = { git = "https://github.com/tree-sitter/tree-sitter-c", rev = "f05e279aedde06a25801c3f2b2cc8ac17fac52ae" } source = { git = "https://github.com/tree-sitter/tree-sitter-c", rev = "7175a6dd5fc1cee660dce6fe23f6043d75af424a" }
[[language]] [[language]]
name = "cpp" name = "cpp"
@ -221,7 +221,7 @@ args = { console = "internalConsole", attachCommands = [ "platform select remote
[[grammar]] [[grammar]]
name = "cpp" name = "cpp"
source = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "e8dcc9d2b404c542fd236ea5f7208f90be8a6e89" } source = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "d5e90fba898f320db48d81ddedd78d52c67c1fed" }
[[language]] [[language]]
name = "c-sharp" name = "c-sharp"

View file

@ -1,65 +1,104 @@
(storage_class_specifier) @keyword.storage
"goto" @keyword
"register" @keyword
"break" @keyword
"case" @keyword
"continue" @keyword
"default" @keyword
"do" @keyword
"else" @keyword
"enum" @keyword
"extern" @keyword
"for" @keyword
"if" @keyword
"inline" @keyword
"return" @keyword
"sizeof" @keyword "sizeof" @keyword
"struct" @keyword
"switch" @keyword
"typedef" @keyword
"union" @keyword
"volatile" @keyword
"while" @keyword
"const" @keyword
[ [
"#define" "enum"
"#elif" "struct"
"#else" "typedef"
"#endif" "union"
"#if" ] @keyword.storage.type
"#ifdef"
"#ifndef" [
"#include" "const"
(preproc_directive) "extern"
"inline"
"register"
"volatile"
(storage_class_specifier)
] @keyword.storage.modifier
[
"goto"
"break"
"continue"
] @keyword.control
[
"do"
"for"
"while"
] @keyword.control.repeat
[
"if"
"else"
"switch"
"case"
"default"
] @keyword.control.conditional
"return" @keyword.control.return
[
"defined"
"#define"
"#elif"
"#else"
"#endif"
"#if"
"#ifdef"
"#ifndef"
"#include"
(preproc_directive)
] @keyword.directive ] @keyword.directive
"--" @operator [
"-" @operator "+"
"-=" @operator "-"
"->" @operator "*"
"=" @operator "/"
"!=" @operator "++"
"*" @operator "--"
"&" @operator "%"
"&&" @operator "=="
"+" @operator "!="
"++" @operator ">"
"+=" @operator "<"
"<" @operator ">="
"==" @operator "<="
">" @operator "&&"
"||" @operator "||"
">=" @operator "!"
"<=" @operator "&"
"|"
"^"
"~"
"<<"
">>"
"="
"+="
"-="
"*="
"/="
"%="
"<<="
">>="
"&="
"^="
"|="
"?"
] @operator
"." @punctuation.delimiter (conditional_expression ":" @operator)
";" @punctuation.delimiter
"..." @punctuation
["," "." ":" ";" "->" "::"] @punctuation.delimiter
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
[(true) (false)] @constant.builtin.boolean [(true) (false)] @constant.builtin.boolean
(enumerator) @type.enum.variant (enumerator name: (identifier) @type.enum.variant)
(string_literal) @string (string_literal) @string
(system_lib_string) @string (system_lib_string) @string
@ -73,19 +112,28 @@
(call_expression (call_expression
function: (field_expression function: (field_expression
field: (field_identifier) @function)) field: (field_identifier) @function))
(call_expression (argument_list (identifier) @variable))
(function_declarator (function_declarator
declarator: (identifier) @function) declarator: [(identifier) (field_identifier)] @function)
(parameter_declaration
declarator: (identifier) @variable.parameter)
(parameter_declaration
(pointer_declarator
declarator: (identifier) @variable.parameter))
(preproc_function_def (preproc_function_def
name: (identifier) @function.special) name: (identifier) @function.special)
(attribute
name: (identifier) @attribute)
(field_identifier) @variable.other.member (field_identifier) @variable.other.member
(statement_identifier) @label (statement_identifier) @label
(type_identifier) @type (type_identifier) @type
(primitive_type) @type (primitive_type) @type.builtin
(sized_type_specifier) @type (sized_type_specifier) @type
((identifier) @constant ((identifier) @constant
(#match? @constant "^[A-Z][A-Z\\d_]*$")) (#match? @constant "^[A-Z][A-Z\\d_]*$"))
(identifier) @variable (identifier) @variable

View file

@ -1,5 +1,3 @@
; inherits: c
; Functions ; Functions
(call_expression (call_expression
@ -12,56 +10,106 @@
(template_method (template_method
name: (field_identifier) @function) name: (field_identifier) @function)
(template_function
name: (identifier) @function)
(function_declarator (function_declarator
declarator: (qualified_identifier declarator: (qualified_identifier
name: (identifier) @function)) name: (identifier) @function))
(function_declarator (function_declarator
declarator: (qualified_identifier declarator: (qualified_identifier
name: (identifier) @function)) name: (qualified_identifier
name: (identifier) @function)))
(function_declarator (function_declarator
declarator: (field_identifier) @function) declarator: (field_identifier) @function)
; Types ; Types
((namespace_identifier) @type (using_declaration ("using" "namespace" (identifier) @namespace))
(#match? @type "^[A-Z]")) (using_declaration ("using" "namespace" (qualified_identifier name: (identifier) @namespace)))
(namespace_definition name: (identifier) @namespace)
(namespace_identifier) @namespace
(qualified_identifier name: (identifier) @type.enum.variant)
(auto) @type (auto) @type
"decltype" @type
; Constants ; Constants
(this) @variable.builtin (this) @variable.builtin
(nullptr) @constant (nullptr) @constant.builtin
; Keywords ; Keywords
"catch" @keyword (template_argument_list (["<" ">"] @punctuation.bracket))
"class" @keyword (template_parameter_list (["<" ">"] @punctuation.bracket))
"constexpr" @keyword (default_method_clause "default" @keyword)
"delete" @keyword
"explicit" @keyword "static_assert" @function.special
"final" @keyword
"friend" @keyword [
"mutable" @keyword "<=>"
"namespace" @keyword "[]"
"noexcept" @keyword "()"
"new" @keyword ] @operator
"override" @keyword
"private" @keyword [
"protected" @keyword "co_await"
"public" @keyword "co_return"
"template" @keyword "co_yield"
"throw" @keyword "concept"
"try" @keyword "delete"
"typename" @keyword "final"
"using" @keyword "new"
"virtual" @keyword "operator"
"requires"
"using"
] @keyword
[
"catch"
"noexcept"
"throw"
"try"
] @keyword.control.exception
[
"and"
"and_eq"
"bitor"
"bitand"
"not"
"not_eq"
"or"
"or_eq"
"xor"
"xor_eq"
] @keyword.operator
[
"class"
"namespace"
"typename"
] @keyword.storage.type
[
"constexpr"
"constinit"
"consteval"
"explicit"
"friend"
"mutable"
"private"
"protected"
"public"
"override"
"template"
"virtual"
] @keyword.storage.modifier
; Strings ; Strings
(raw_string_literal) @string (raw_string_literal) @string
; inherits: c

View file

@ -2,57 +2,26 @@
(float_literal) @constant.numeric.float (float_literal) @constant.numeric.float
(bool_literal) @constant.builtin.boolean (bool_literal) @constant.builtin.boolean
(global_constant_declaration) @variable [
(global_variable_declaration) @variable "bitcast"
(compound_statement) @variable "discard"
(const_expression) @function "enable"
"fallthrough"
(variable_identifier_declaration ] @keyword
(identifier) @variable
(type_declaration) @type)
(function_declaration
(identifier) @function
(function_return_type_declaration
(type_declaration) @type))
(parameter
(variable_identifier_declaration
(identifier) @variable.parameter
(type_declaration) @type))
(struct_declaration
(identifier) @type)
(struct_declaration
(struct_member
(variable_identifier_declaration
(identifier) @variable.other.member
(type_declaration) @type)))
(type_constructor_or_function_call_expression
(type_declaration) @function)
[ [
"struct" "let"
"bitcast" "override"
"discard" "struct"
"enable" "type"
"fallthrough" "var"
"fn" (texel_format)
"let" ] @keyword.storage.type
"private"
"read" [
"read_write" (access_mode)
"storage" (address_space)
"type" ] @keyword.storage.modifier
"uniform"
"var"
"workgroup"
"write"
"override"
(texel_format)
] @keyword
"fn" @keyword.function "fn" @keyword.function
@ -62,53 +31,87 @@
["(" ")" "[" "]" "{" "}"] @punctuation.bracket ["(" ")" "[" "]" "{" "}"] @punctuation.bracket
(type_declaration ["<" ">"] @punctuation.bracket)
[ [
"loop" "break"
"for" "continue"
"while" "continuing"
"break" ] @keyword.control
"continue"
"continuing" [
"loop"
"for"
"while"
] @keyword.control.repeat ] @keyword.control.repeat
[ [
"if" "if"
"else" "else"
"switch" "switch"
"case" "case"
"default" "default"
] @keyword.control.conditional ] @keyword.control.conditional
[ [
"&" "!"
"&&" "!="
"/" "%"
"!" "%="
"=" "&"
"==" "&&"
"!=" "&="
">" "*"
">=" "*="
">>" "+"
"<" "++"
"<=" "+="
"<<" "-"
"%" "--"
"-" "-="
"+" "->"
"|" "/"
"||" "/="
"*" "<"
"~" "<<"
"^" "<="
"@" "="
"++" "=="
"--" ">"
">="
">>"
"@"
"^"
"^="
"|"
"|="
"||"
"~"
] @operator ] @operator
(function_declaration
(identifier) @function)
(parameter
(variable_identifier_declaration
(identifier) @variable.parameter))
(struct_declaration
(identifier) @type)
(struct_declaration
(struct_member
(variable_identifier_declaration
(identifier) @variable.other.member)))
(type_constructor_or_function_call_expression
(type_declaration (identifier) @function))
(type_declaration _ @type)
(attribute (attribute
(identifier) @attribute) (identifier) @attribute)
(identifier) @variable
(comment) @comment (comment) @comment
(ERROR) @error