aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorChickenkeeper2022-10-14 01:31:32 +0000
committerGitHub2022-10-14 01:31:32 +0000
commitb4e795d70430d28ecd37f8e1564cbd568d17e0b9 (patch)
treea214d732dcb1fcdc2b73dda556f4599384605c57 /runtime
parentcf4a5cca96aa6a35182ce336e066e9aec34b38d2 (diff)
Fix C++ syntax highlighting, and improve C & WGSL highlighting (#4079)
Diffstat (limited to 'runtime')
-rw-r--r--runtime/queries/c/highlights.scm162
-rw-r--r--runtime/queries/cpp/highlights.scm108
-rw-r--r--runtime/queries/wgsl/highlights.scm175
3 files changed, 272 insertions, 173 deletions
diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm
index 647df05d..c0f5763a 100644
--- a/runtime/queries/c/highlights.scm
+++ b/runtime/queries/c/highlights.scm
@@ -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
-"struct" @keyword
-"switch" @keyword
-"typedef" @keyword
-"union" @keyword
-"volatile" @keyword
-"while" @keyword
-"const" @keyword
[
- "#define"
- "#elif"
- "#else"
- "#endif"
- "#if"
- "#ifdef"
- "#ifndef"
- "#include"
- (preproc_directive)
+ "enum"
+ "struct"
+ "typedef"
+ "union"
+] @keyword.storage.type
+
+[
+ "const"
+ "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
-"--" @operator
-"-" @operator
-"-=" @operator
-"->" @operator
-"=" @operator
-"!=" @operator
-"*" @operator
-"&" @operator
-"&&" @operator
-"+" @operator
-"++" @operator
-"+=" @operator
-"<" @operator
-"==" @operator
-">" @operator
-"||" @operator
-">=" @operator
-"<=" @operator
-
-"." @punctuation.delimiter
-";" @punctuation.delimiter
+[
+ "+"
+ "-"
+ "*"
+ "/"
+ "++"
+ "--"
+ "%"
+ "=="
+ "!="
+ ">"
+ "<"
+ ">="
+ "<="
+ "&&"
+ "||"
+ "!"
+ "&"
+ "|"
+ "^"
+ "~"
+ "<<"
+ ">>"
+ "="
+ "+="
+ "-="
+ "*="
+ "/="
+ "%="
+ "<<="
+ ">>="
+ "&="
+ "^="
+ "|="
+ "?"
+] @operator
+
+(conditional_expression ":" @operator)
+
+"..." @punctuation
+
+["," "." ":" ";" "->" "::"] @punctuation.delimiter
+
+["(" ")" "[" "]" "{" "}"] @punctuation.bracket
[(true) (false)] @constant.builtin.boolean
-(enumerator) @type.enum.variant
+(enumerator name: (identifier) @type.enum.variant)
(string_literal) @string
(system_lib_string) @string
@@ -73,19 +112,28 @@
(call_expression
function: (field_expression
field: (field_identifier) @function))
+(call_expression (argument_list (identifier) @variable))
(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
name: (identifier) @function.special)
+(attribute
+ name: (identifier) @attribute)
+
(field_identifier) @variable.other.member
(statement_identifier) @label
(type_identifier) @type
-(primitive_type) @type
+(primitive_type) @type.builtin
(sized_type_specifier) @type
((identifier) @constant
- (#match? @constant "^[A-Z][A-Z\\d_]*$"))
+ (#match? @constant "^[A-Z][A-Z\\d_]*$"))
(identifier) @variable
diff --git a/runtime/queries/cpp/highlights.scm b/runtime/queries/cpp/highlights.scm
index 3348ef3c..11877a76 100644
--- a/runtime/queries/cpp/highlights.scm
+++ b/runtime/queries/cpp/highlights.scm
@@ -1,5 +1,3 @@
-; inherits: c
-
; Functions
(call_expression
@@ -12,56 +10,106 @@
(template_method
name: (field_identifier) @function)
-(template_function
- name: (identifier) @function)
-
(function_declarator
declarator: (qualified_identifier
name: (identifier) @function))
(function_declarator
declarator: (qualified_identifier
- name: (identifier) @function))
+ name: (qualified_identifier
+ name: (identifier) @function)))
(function_declarator
declarator: (field_identifier) @function)
; Types
-((namespace_identifier) @type
- (#match? @type "^[A-Z]"))
+(using_declaration ("using" "namespace" (identifier) @namespace))
+(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
+"decltype" @type
; Constants
(this) @variable.builtin
-(nullptr) @constant
+(nullptr) @constant.builtin
; Keywords
-"catch" @keyword
-"class" @keyword
-"constexpr" @keyword
-"delete" @keyword
-"explicit" @keyword
-"final" @keyword
-"friend" @keyword
-"mutable" @keyword
-"namespace" @keyword
-"noexcept" @keyword
-"new" @keyword
-"override" @keyword
-"private" @keyword
-"protected" @keyword
-"public" @keyword
-"template" @keyword
-"throw" @keyword
-"try" @keyword
-"typename" @keyword
-"using" @keyword
-"virtual" @keyword
+(template_argument_list (["<" ">"] @punctuation.bracket))
+(template_parameter_list (["<" ">"] @punctuation.bracket))
+(default_method_clause "default" @keyword)
+
+"static_assert" @function.special
+
+[
+ "<=>"
+ "[]"
+ "()"
+] @operator
+
+[
+ "co_await"
+ "co_return"
+ "co_yield"
+ "concept"
+ "delete"
+ "final"
+ "new"
+ "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
(raw_string_literal) @string
+
+; inherits: c
diff --git a/runtime/queries/wgsl/highlights.scm b/runtime/queries/wgsl/highlights.scm
index baf9dd8f..2817ea3a 100644
--- a/runtime/queries/wgsl/highlights.scm
+++ b/runtime/queries/wgsl/highlights.scm
@@ -2,57 +2,26 @@
(float_literal) @constant.numeric.float
(bool_literal) @constant.builtin.boolean
-(global_constant_declaration) @variable
-(global_variable_declaration) @variable
-(compound_statement) @variable
-(const_expression) @function
-
-(variable_identifier_declaration
- (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)))
+[
+ "bitcast"
+ "discard"
+ "enable"
+ "fallthrough"
+] @keyword
-(type_constructor_or_function_call_expression
- (type_declaration) @function)
+[
+ "let"
+ "override"
+ "struct"
+ "type"
+ "var"
+ (texel_format)
+] @keyword.storage.type
[
- "struct"
- "bitcast"
- "discard"
- "enable"
- "fallthrough"
- "fn"
- "let"
- "private"
- "read"
- "read_write"
- "storage"
- "type"
- "uniform"
- "var"
- "workgroup"
- "write"
- "override"
- (texel_format)
-] @keyword
+ (access_mode)
+ (address_space)
+] @keyword.storage.modifier
"fn" @keyword.function
@@ -62,53 +31,87 @@
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
+(type_declaration ["<" ">"] @punctuation.bracket)
+
[
- "loop"
- "for"
- "while"
- "break"
- "continue"
- "continuing"
+ "break"
+ "continue"
+ "continuing"
+] @keyword.control
+
+[
+ "loop"
+ "for"
+ "while"
] @keyword.control.repeat
[
- "if"
- "else"
- "switch"
- "case"
- "default"
+ "if"
+ "else"
+ "switch"
+ "case"
+ "default"
] @keyword.control.conditional
[
- "&"
- "&&"
- "/"
- "!"
- "="
- "=="
- "!="
- ">"
- ">="
- ">>"
- "<"
- "<="
- "<<"
- "%"
- "-"
- "+"
- "|"
- "||"
- "*"
- "~"
- "^"
- "@"
- "++"
- "--"
+ "!"
+ "!="
+ "%"
+ "%="
+ "&"
+ "&&"
+ "&="
+ "*"
+ "*="
+ "+"
+ "++"
+ "+="
+ "-"
+ "--"
+ "-="
+ "->"
+ "/"
+ "/="
+ "<"
+ "<<"
+ "<="
+ "="
+ "=="
+ ">"
+ ">="
+ ">>"
+ "@"
+ "^"
+ "^="
+ "|"
+ "|="
+ "||"
+ "~"
] @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
- (identifier) @attribute)
+ (identifier) @attribute)
-(comment) @comment
+(identifier) @variable
-(ERROR) @error
+(comment) @comment