on master help sign in
Fix C++ syntax highlighting, and improve C & WGSL highlighting (#4079)
commitb4e795d70430d28ecd37f8e1564cbd568d17e0b9 authorChickenkeeper <chrism.chickenkeeper24@gmail.com> dateFri 14 Oct 2022, 02:31 (4 years ago) parentcf4a5cc
4 files changed+274−175
languages.toml+2−2 runtime/queries/c/highlights.scm+105−57 runtime/queries/cpp/highlights.scm+78−30 runtime/queries/wgsl/highlights.scm+89−86
languages.toml+2−2
@@ -184,7 +184,7 @@ args = { console = "internalConsole", attachCommands = [ "platform select remote
184184
185185[[grammar]]
186186name = "c"
187−source = { git = "https://github.com/tree-sitter/tree-sitter-c", rev = "f05e279aedde06a25801c3f2b2cc8ac17fac52ae" }
187+source = { git = "https://github.com/tree-sitter/tree-sitter-c", rev = "7175a6dd5fc1cee660dce6fe23f6043d75af424a" }
188188
189189[[language]]
190190name = "cpp"
@@ -221,7 +221,7 @@ args = { console = "internalConsole", attachCommands = [ "platform select remote
221221
222222[[grammar]]
223223name = "cpp"
224−source = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "e8dcc9d2b404c542fd236ea5f7208f90be8a6e89" }
224+source = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "d5e90fba898f320db48d81ddedd78d52c67c1fed" }
225225
226226[[language]]
227227name = "c-sharp"
runtime/queries/c/highlights.scm+105−57
@@ -1,65 +1,104 @@
1−(storage_class_specifier) @keyword.storage
2−
3−"goto" @keyword
4−"register" @keyword
5−"break" @keyword
6−"case" @keyword
7−"continue" @keyword
8−"default" @keyword
9−"do" @keyword
10−"else" @keyword
11−"enum" @keyword
12−"extern" @keyword
13−"for" @keyword
14−"if" @keyword
15−"inline" @keyword
16−"return" @keyword
171"sizeof" @keyword
18−"struct" @keyword
19−"switch" @keyword
20−"typedef" @keyword
21−"union" @keyword
22−"volatile" @keyword
23−"while" @keyword
24−"const" @keyword
252
263[
27− "#define"
28− "#elif"
29− "#else"
30− "#endif"
31− "#if"
32− "#ifdef"
33− "#ifndef"
34− "#include"
35− (preproc_directive)
4+ "enum"
5+ "struct"
6+ "typedef"
7+ "union"
8+] @keyword.storage.type
9+
10+[
11+ "const"
12+ "extern"
13+ "inline"
14+ "register"
15+ "volatile"
16+ (storage_class_specifier)
17+] @keyword.storage.modifier
18+
19+[
20+ "goto"
21+ "break"
22+ "continue"
23+] @keyword.control
24+
25+[
26+ "do"
27+ "for"
28+ "while"
29+] @keyword.control.repeat
30+
31+[
32+ "if"
33+ "else"
34+ "switch"
35+ "case"
36+ "default"
37+] @keyword.control.conditional
38+
39+"return" @keyword.control.return
40+
41+[
42+ "defined"
43+ "#define"
44+ "#elif"
45+ "#else"
46+ "#endif"
47+ "#if"
48+ "#ifdef"
49+ "#ifndef"
50+ "#include"
51+ (preproc_directive)
3652] @keyword.directive
3753
38−"--" @operator
39−"-" @operator
40−"-=" @operator
41−"->" @operator
42−"=" @operator
43−"!=" @operator
44−"*" @operator
45−"&" @operator
46−"&&" @operator
47−"+" @operator
48−"++" @operator
49−"+=" @operator
50−"<" @operator
51−"==" @operator
52−">" @operator
53−"||" @operator
54−">=" @operator
55−"<=" @operator
56−
57−"." @punctuation.delimiter
58−";" @punctuation.delimiter
54+[
55+ "+"
56+ "-"
57+ "*"
58+ "/"
59+ "++"
60+ "--"
61+ "%"
62+ "=="
63+ "!="
64+ ">"
65+ "<"
66+ ">="
67+ "<="
68+ "&&"
69+ "||"
70+ "!"
71+ "&"
72+ "|"
73+ "^"
74+ "~"
75+ "<<"
76+ ">>"
77+ "="
78+ "+="
79+ "-="
80+ "*="
81+ "/="
82+ "%="
83+ "<<="
84+ ">>="
85+ "&="
86+ "^="
87+ "|="
88+ "?"
89+] @operator
90+
91+(conditional_expression ":" @operator)
92+
93+"..." @punctuation
94+
95+["," "." ":" ";" "->" "::"] @punctuation.delimiter
96+
97+["(" ")" "[" "]" "{" "}"] @punctuation.bracket
5998
6099[(true) (false)] @constant.builtin.boolean
61100
62−(enumerator) @type.enum.variant
101+(enumerator name: (identifier) @type.enum.variant)
63102
64103(string_literal) @string
65104(system_lib_string) @string
@@ -73,19 +112,28 @@
73112(call_expression
74113 function: (field_expression
75114 field: (field_identifier) @function))
115+(call_expression (argument_list (identifier) @variable))
76116(function_declarator
77− declarator: (identifier) @function)
117+ declarator: [(identifier) (field_identifier)] @function)
118+(parameter_declaration
119+ declarator: (identifier) @variable.parameter)
120+(parameter_declaration
121+ (pointer_declarator
122+ declarator: (identifier) @variable.parameter))
78123(preproc_function_def
79124 name: (identifier) @function.special)
80125
126+(attribute
127+ name: (identifier) @attribute)
128+
81129(field_identifier) @variable.other.member
82130(statement_identifier) @label
83131(type_identifier) @type
84−(primitive_type) @type
132+(primitive_type) @type.builtin
85133(sized_type_specifier) @type
86134
87135((identifier) @constant
88− (#match? @constant "^[A-Z][A-Z\\d_]*$"))
136+ (#match? @constant "^[A-Z][A-Z\\d_]*$"))
89137
90138(identifier) @variable
91139
runtime/queries/cpp/highlights.scm+78−30
@@ -1,5 +1,3 @@
1−; inherits: c
2−
31; Functions
42
53(call_expression
@@ -12,56 +10,106 @@
1210(template_method
1311 name: (field_identifier) @function)
1412
15−(template_function
16− name: (identifier) @function)
17−
1813(function_declarator
1914 declarator: (qualified_identifier
2015 name: (identifier) @function))
2116
2217(function_declarator
2318 declarator: (qualified_identifier
24− name: (identifier) @function))
19+ name: (qualified_identifier
20+ name: (identifier) @function)))
2521
2622(function_declarator
2723 declarator: (field_identifier) @function)
2824
2925; Types
3026
31−((namespace_identifier) @type
32− (#match? @type "^[A-Z]"))
27+(using_declaration ("using" "namespace" (identifier) @namespace))
28+(using_declaration ("using" "namespace" (qualified_identifier name: (identifier) @namespace)))
29+(namespace_definition name: (identifier) @namespace)
30+(namespace_identifier) @namespace
31+
32+(qualified_identifier name: (identifier) @type.enum.variant)
3333
3434(auto) @type
35+"decltype" @type
3536
3637; Constants
3738
3839(this) @variable.builtin
39−(nullptr) @constant
40+(nullptr) @constant.builtin
4041
4142; Keywords
4243
43−"catch" @keyword
44−"class" @keyword
45−"constexpr" @keyword
46−"delete" @keyword
47−"explicit" @keyword
48−"final" @keyword
49−"friend" @keyword
50−"mutable" @keyword
51−"namespace" @keyword
52−"noexcept" @keyword
53−"new" @keyword
54−"override" @keyword
55−"private" @keyword
56−"protected" @keyword
57−"public" @keyword
58−"template" @keyword
59−"throw" @keyword
60−"try" @keyword
61−"typename" @keyword
62−"using" @keyword
63−"virtual" @keyword
44+(template_argument_list (["<" ">"] @punctuation.bracket))
45+(template_parameter_list (["<" ">"] @punctuation.bracket))
46+(default_method_clause "default" @keyword)
47+
48+"static_assert" @function.special
49+
50+[
51+ "<=>"
52+ "[]"
53+ "()"
54+] @operator
55+
56+[
57+ "co_await"
58+ "co_return"
59+ "co_yield"
60+ "concept"
61+ "delete"
62+ "final"
63+ "new"
64+ "operator"
65+ "requires"
66+ "using"
67+] @keyword
68+
69+[
70+ "catch"
71+ "noexcept"
72+ "throw"
73+ "try"
74+] @keyword.control.exception
75+
76+
77+[
78+ "and"
79+ "and_eq"
80+ "bitor"
81+ "bitand"
82+ "not"
83+ "not_eq"
84+ "or"
85+ "or_eq"
86+ "xor"
87+ "xor_eq"
88+] @keyword.operator
89+
90+[
91+ "class"
92+ "namespace"
93+ "typename"
94+] @keyword.storage.type
95+
96+[
97+ "constexpr"
98+ "constinit"
99+ "consteval"
100+ "explicit"
101+ "friend"
102+ "mutable"
103+ "private"
104+ "protected"
105+ "public"
106+ "override"
107+ "template"
108+ "virtual"
109+] @keyword.storage.modifier
64110
65111; Strings
66112
67113(raw_string_literal) @string
114+
115+; inherits: c
runtime/queries/wgsl/highlights.scm+89−86
@@ -2,57 +2,26 @@
22(float_literal) @constant.numeric.float
33(bool_literal) @constant.builtin.boolean
44
5−(global_constant_declaration) @variable
6−(global_variable_declaration) @variable
7−(compound_statement) @variable
8−(const_expression) @function
9−
10−(variable_identifier_declaration
11− (identifier) @variable
12− (type_declaration) @type)
13−
14−(function_declaration
15− (identifier) @function
16− (function_return_type_declaration
17− (type_declaration) @type))
18−
19−(parameter
20− (variable_identifier_declaration
21− (identifier) @variable.parameter
22− (type_declaration) @type))
23−
24−(struct_declaration
25− (identifier) @type)
26−
27−(struct_declaration
28− (struct_member
29− (variable_identifier_declaration
30− (identifier) @variable.other.member
31− (type_declaration) @type)))
5+[
6+ "bitcast"
7+ "discard"
8+ "enable"
9+ "fallthrough"
10+] @keyword
3211
33−(type_constructor_or_function_call_expression
34− (type_declaration) @function)
12+[
13+ "let"
14+ "override"
15+ "struct"
16+ "type"
17+ "var"
18+ (texel_format)
19+] @keyword.storage.type
3520
3621[
37− "struct"
38− "bitcast"
39− "discard"
40− "enable"
41− "fallthrough"
42− "fn"
43− "let"
44− "private"
45− "read"
46− "read_write"
47− "storage"
48− "type"
49− "uniform"
50− "var"
51− "workgroup"
52− "write"
53− "override"
54− (texel_format)
55−] @keyword
22+ (access_mode)
23+ (address_space)
24+] @keyword.storage.modifier
5625
5726"fn" @keyword.function
5827
@@ -62,53 +31,87 @@
6231
6332["(" ")" "[" "]" "{" "}"] @punctuation.bracket
6433
34+(type_declaration ["<" ">"] @punctuation.bracket)
35+
6536[
66− "loop"
67− "for"
68− "while"
69− "break"
70− "continue"
71− "continuing"
37+ "break"
38+ "continue"
39+ "continuing"
40+] @keyword.control
41+
42+[
43+ "loop"
44+ "for"
45+ "while"
7246] @keyword.control.repeat
7347
7448[
75− "if"
76− "else"
77− "switch"
78− "case"
79− "default"
49+ "if"
50+ "else"
51+ "switch"
52+ "case"
53+ "default"
8054] @keyword.control.conditional
8155
8256[
83− "&"
84− "&&"
85− "/"
86− "!"
87− "="
88− "=="
89− "!="
90− ">"
91− ">="
92− ">>"
93− "<"
94− "<="
95− "<<"
96− "%"
97− "-"
98− "+"
99− "|"
100− "||"
101− "*"
102− "~"
103− "^"
104− "@"
105− "++"
106− "--"
57+ "!"
58+ "!="
59+ "%"
60+ "%="
61+ "&"
62+ "&&"
63+ "&="
64+ "*"
65+ "*="
66+ "+"
67+ "++"
68+ "+="
69+ "-"
70+ "--"
71+ "-="
72+ "->"
73+ "/"
74+ "/="
75+ "<"
76+ "<<"
77+ "<="
78+ "="
79+ "=="
80+ ">"
81+ ">="
82+ ">>"
83+ "@"
84+ "^"
85+ "^="
86+ "|"
87+ "|="
88+ "||"
89+ "~"
10790] @operator
10891
92+(function_declaration
93+ (identifier) @function)
94+
95+(parameter
96+ (variable_identifier_declaration
97+ (identifier) @variable.parameter))
98+
99+(struct_declaration
100+ (identifier) @type)
101+
102+(struct_declaration
103+ (struct_member
104+ (variable_identifier_declaration
105+ (identifier) @variable.other.member)))
106+
107+(type_constructor_or_function_call_expression
108+ (type_declaration (identifier) @function))
109+
110+(type_declaration _ @type)
111+
109112(attribute
110− (identifier) @attribute)
113+ (identifier) @attribute)
111114
112−(comment) @comment
115+(identifier) @variable
113116
114−(ERROR) @error
117+(comment) @comment