2021-07-08 18:11:20 +02:00
|
|
|
; -------
|
|
|
|
; Tree-Sitter doesn't allow overrides in regards to captures,
|
|
|
|
; though it is possible to affect the child node of a captured
|
|
|
|
; node. Thus, the approach here is to flip the order so that
|
|
|
|
; overrides are unnecessary.
|
|
|
|
; -------
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
; -------
|
|
|
|
; Types
|
|
|
|
; -------
|
2021-05-16 11:58:27 +02:00
|
|
|
|
2023-11-03 22:21:01 +01:00
|
|
|
(type_parameters
|
|
|
|
(type_identifier) @type.parameter)
|
|
|
|
(constrained_type_parameter
|
|
|
|
left: (type_identifier) @type.parameter)
|
|
|
|
(optional_type_parameter
|
|
|
|
name: (type_identifier) @type.parameter)
|
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
; ---
|
|
|
|
; Primitives
|
|
|
|
; ---
|
2021-05-16 11:58:27 +02:00
|
|
|
|
2021-11-03 04:00:52 +01:00
|
|
|
(escape_sequence) @constant.character.escape
|
2021-07-08 18:11:20 +02:00
|
|
|
(primitive_type) @type.builtin
|
2021-09-02 07:58:57 +02:00
|
|
|
(boolean_literal) @constant.builtin.boolean
|
2021-11-03 04:00:52 +01:00
|
|
|
(integer_literal) @constant.numeric.integer
|
|
|
|
(float_literal) @constant.numeric.float
|
|
|
|
(char_literal) @constant.character
|
2021-07-08 18:11:20 +02:00
|
|
|
[
|
|
|
|
(string_literal)
|
|
|
|
(raw_string_literal)
|
|
|
|
] @string
|
|
|
|
[
|
|
|
|
(line_comment)
|
|
|
|
(block_comment)
|
|
|
|
] @comment
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
; ---
|
|
|
|
; Extraneous
|
|
|
|
; ---
|
2021-05-16 11:58:27 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
(self) @variable.builtin
|
|
|
|
(enum_variant (identifier) @type.enum.variant)
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
(field_initializer
|
2021-11-03 04:00:52 +01:00
|
|
|
(field_identifier) @variable.other.member)
|
2021-08-18 18:02:15 +02:00
|
|
|
(shorthand_field_initializer
|
2021-11-03 04:00:52 +01:00
|
|
|
(identifier) @variable.other.member)
|
|
|
|
(shorthand_field_identifier) @variable.other.member
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
(lifetime
|
|
|
|
"'" @label
|
|
|
|
(identifier) @label)
|
|
|
|
(loop_label
|
2022-12-22 00:10:45 +01:00
|
|
|
"'" @label
|
|
|
|
(identifier) @label)
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
; ---
|
|
|
|
; Punctuation
|
|
|
|
; ---
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
[
|
|
|
|
"::"
|
|
|
|
"."
|
|
|
|
";"
|
2022-06-29 03:10:19 +02:00
|
|
|
","
|
2021-07-08 18:11:20 +02:00
|
|
|
] @punctuation.delimiter
|
2021-05-16 11:58:27 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
[
|
|
|
|
"("
|
|
|
|
")"
|
|
|
|
"["
|
|
|
|
"]"
|
2021-08-18 18:02:15 +02:00
|
|
|
"{"
|
|
|
|
"}"
|
2022-08-17 23:20:44 +02:00
|
|
|
"#"
|
2021-07-08 18:11:20 +02:00
|
|
|
] @punctuation.bracket
|
|
|
|
(type_arguments
|
|
|
|
[
|
|
|
|
"<"
|
|
|
|
">"
|
|
|
|
] @punctuation.bracket)
|
|
|
|
(type_parameters
|
|
|
|
[
|
|
|
|
"<"
|
|
|
|
">"
|
|
|
|
] @punctuation.bracket)
|
2022-08-12 02:00:03 +02:00
|
|
|
(closure_parameters
|
|
|
|
"|" @punctuation.bracket)
|
2021-05-16 11:58:27 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
; ---
|
2021-11-03 04:00:52 +01:00
|
|
|
; Variables
|
2021-07-08 18:11:20 +02:00
|
|
|
; ---
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-11-03 04:00:52 +01:00
|
|
|
(let_declaration
|
|
|
|
pattern: [
|
|
|
|
((identifier) @variable)
|
|
|
|
((tuple_pattern
|
|
|
|
(identifier) @variable))
|
|
|
|
])
|
|
|
|
|
|
|
|
; It needs to be anonymous to not conflict with `call_expression` further below.
|
|
|
|
(_
|
|
|
|
value: (field_expression
|
|
|
|
value: (identifier)? @variable
|
|
|
|
field: (field_identifier) @variable.other.member))
|
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
(parameter
|
|
|
|
pattern: (identifier) @variable.parameter)
|
|
|
|
(closure_parameters
|
|
|
|
(identifier) @variable.parameter)
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
; -------
|
|
|
|
; Keywords
|
|
|
|
; -------
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
(for_expression
|
2022-10-29 17:36:26 +02:00
|
|
|
"for" @keyword.control.repeat)
|
2021-07-08 18:11:20 +02:00
|
|
|
((identifier) @keyword.control
|
|
|
|
(#match? @keyword.control "^yield$"))
|
2022-10-29 17:36:26 +02:00
|
|
|
|
|
|
|
"in" @keyword.control
|
|
|
|
|
|
|
|
[
|
|
|
|
"match"
|
|
|
|
"if"
|
|
|
|
"else"
|
|
|
|
] @keyword.control.conditional
|
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
[
|
|
|
|
"while"
|
|
|
|
"loop"
|
2022-10-29 17:36:26 +02:00
|
|
|
] @keyword.control.repeat
|
|
|
|
|
|
|
|
[
|
2021-07-08 18:11:20 +02:00
|
|
|
"break"
|
|
|
|
"continue"
|
|
|
|
"return"
|
|
|
|
"await"
|
2022-10-29 17:36:26 +02:00
|
|
|
] @keyword.control.return
|
2021-07-08 18:11:20 +02:00
|
|
|
|
2021-12-23 04:10:24 +01:00
|
|
|
"use" @keyword.control.import
|
|
|
|
(mod_item "mod" @keyword.control.import !body)
|
|
|
|
(use_as_clause "as" @keyword.control.import)
|
|
|
|
|
|
|
|
(type_cast_expression "as" @keyword.operator)
|
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
[
|
|
|
|
(crate)
|
|
|
|
(super)
|
|
|
|
"as"
|
|
|
|
"pub"
|
|
|
|
"mod"
|
|
|
|
"extern"
|
|
|
|
|
|
|
|
"impl"
|
|
|
|
"where"
|
|
|
|
"trait"
|
|
|
|
"for"
|
|
|
|
|
|
|
|
"default"
|
|
|
|
"async"
|
|
|
|
] @keyword
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2022-10-29 17:36:26 +02:00
|
|
|
[
|
|
|
|
"struct"
|
|
|
|
"enum"
|
|
|
|
"union"
|
|
|
|
"type"
|
|
|
|
] @keyword.storage.type
|
|
|
|
|
|
|
|
"let" @keyword.storage
|
2022-06-29 03:10:19 +02:00
|
|
|
"fn" @keyword.function
|
2022-12-22 00:10:45 +01:00
|
|
|
"unsafe" @keyword.special
|
|
|
|
"macro_rules!" @function.macro
|
2022-06-29 03:10:19 +02:00
|
|
|
|
2022-06-14 19:35:36 +02:00
|
|
|
(mutable_specifier) @keyword.storage.modifier.mut
|
|
|
|
|
|
|
|
(reference_type "&" @keyword.storage.modifier.ref)
|
|
|
|
(self_parameter "&" @keyword.storage.modifier.ref)
|
|
|
|
|
|
|
|
[
|
|
|
|
"static"
|
|
|
|
"const"
|
|
|
|
"ref"
|
|
|
|
"move"
|
|
|
|
"dyn"
|
|
|
|
] @keyword.storage.modifier
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-09-07 06:00:52 +02:00
|
|
|
; TODO: variable.mut to highlight mutable identifiers via locals.scm
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2024-01-02 16:38:13 +01:00
|
|
|
; -------
|
|
|
|
; Constructors
|
|
|
|
; -------
|
|
|
|
; TODO: this is largely guesswork, remove it once we get actual info from locals.scm or r-a
|
|
|
|
|
|
|
|
(struct_expression
|
|
|
|
name: (type_identifier) @constructor)
|
|
|
|
|
|
|
|
(tuple_struct_pattern
|
|
|
|
type: [
|
|
|
|
(identifier) @constructor
|
|
|
|
(scoped_identifier
|
|
|
|
name: (identifier) @constructor)
|
|
|
|
])
|
|
|
|
(struct_pattern
|
|
|
|
type: [
|
|
|
|
((type_identifier) @constructor)
|
|
|
|
(scoped_type_identifier
|
|
|
|
name: (type_identifier) @constructor)
|
|
|
|
])
|
|
|
|
(match_pattern
|
|
|
|
((identifier) @constructor) (#match? @constructor "^[A-Z]"))
|
|
|
|
(or_pattern
|
|
|
|
((identifier) @constructor)
|
|
|
|
((identifier) @constructor)
|
|
|
|
(#match? @constructor "^[A-Z]"))
|
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
; -------
|
|
|
|
; Guess Other Types
|
|
|
|
; -------
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
((identifier) @constant
|
2022-09-22 00:55:28 +02:00
|
|
|
(#match? @constant "^[A-Z][A-Z\\d_]*$"))
|
2021-07-08 18:11:20 +02:00
|
|
|
|
|
|
|
; ---
|
|
|
|
; PascalCase identifiers in call_expressions (e.g. `Ok()`)
|
|
|
|
; are assumed to be enum constructors.
|
|
|
|
; ---
|
|
|
|
|
|
|
|
(call_expression
|
|
|
|
function: [
|
2024-01-02 16:38:13 +01:00
|
|
|
((identifier) @constructor
|
|
|
|
(#match? @constructor "^[A-Z]"))
|
2021-07-08 18:11:20 +02:00
|
|
|
(scoped_identifier
|
2024-01-02 16:38:13 +01:00
|
|
|
name: ((identifier) @constructor
|
|
|
|
(#match? @constructor "^[A-Z]")))
|
2021-07-08 18:11:20 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
; ---
|
2024-01-02 16:38:13 +01:00
|
|
|
; PascalCase identifiers under a path which is also PascalCase
|
|
|
|
; are assumed to be constructors if they have methods or fields.
|
2021-07-08 18:11:20 +02:00
|
|
|
; ---
|
|
|
|
|
2024-01-02 16:38:13 +01:00
|
|
|
(field_expression
|
|
|
|
value: (scoped_identifier
|
|
|
|
path: [
|
|
|
|
(identifier) @type
|
|
|
|
(scoped_identifier
|
|
|
|
name: (identifier) @type)
|
|
|
|
]
|
|
|
|
name: (identifier) @constructor
|
|
|
|
(#match? @type "^[A-Z]")
|
|
|
|
(#match? @constructor "^[A-Z]")))
|
2021-04-08 16:18:25 +02:00
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
; ---
|
|
|
|
; Other PascalCase identifiers are assumed to be structs.
|
|
|
|
; ---
|
|
|
|
|
|
|
|
((identifier) @type
|
|
|
|
(#match? @type "^[A-Z]"))
|
|
|
|
|
|
|
|
; -------
|
|
|
|
; Functions
|
|
|
|
; -------
|
|
|
|
|
|
|
|
(call_expression
|
|
|
|
function: [
|
|
|
|
((identifier) @function)
|
|
|
|
(scoped_identifier
|
|
|
|
name: (identifier) @function)
|
|
|
|
(field_expression
|
|
|
|
field: (field_identifier) @function)
|
|
|
|
])
|
|
|
|
(generic_function
|
|
|
|
function: [
|
|
|
|
((identifier) @function)
|
|
|
|
(scoped_identifier
|
|
|
|
name: (identifier) @function)
|
|
|
|
(field_expression
|
|
|
|
field: (field_identifier) @function.method)
|
|
|
|
])
|
|
|
|
|
|
|
|
(function_item
|
|
|
|
name: (identifier) @function)
|
|
|
|
|
2022-10-03 16:56:50 +02:00
|
|
|
(function_signature_item
|
|
|
|
name: (identifier) @function)
|
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
; ---
|
|
|
|
; Macros
|
|
|
|
; ---
|
2022-12-12 09:49:57 +01:00
|
|
|
|
2023-01-09 03:26:08 +01:00
|
|
|
(attribute
|
|
|
|
(identifier) @special
|
|
|
|
arguments: (token_tree (identifier) @type)
|
|
|
|
(#eq? @special "derive")
|
|
|
|
)
|
|
|
|
|
2022-11-11 23:51:58 +01:00
|
|
|
(attribute
|
2021-12-20 03:47:40 +01:00
|
|
|
(identifier) @function.macro)
|
2022-11-11 23:51:58 +01:00
|
|
|
(attribute
|
2022-11-08 20:41:09 +01:00
|
|
|
[
|
|
|
|
(identifier) @function.macro
|
|
|
|
(scoped_identifier
|
|
|
|
name: (identifier) @function.macro)
|
|
|
|
]
|
2022-09-07 05:45:51 +02:00
|
|
|
(token_tree (identifier) @function.macro)?)
|
2021-12-20 03:47:40 +01:00
|
|
|
|
2021-04-08 16:18:25 +02:00
|
|
|
(inner_attribute_item) @attribute
|
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
(macro_definition
|
|
|
|
name: (identifier) @function.macro)
|
|
|
|
(macro_invocation
|
|
|
|
macro: [
|
|
|
|
((identifier) @function.macro)
|
|
|
|
(scoped_identifier
|
|
|
|
name: (identifier) @function.macro)
|
|
|
|
]
|
|
|
|
"!" @function.macro)
|
|
|
|
|
|
|
|
(metavariable) @variable.parameter
|
2021-12-20 03:47:40 +01:00
|
|
|
(fragment_specifier) @type
|
2021-07-08 18:11:20 +02:00
|
|
|
|
|
|
|
; -------
|
|
|
|
; Operators
|
|
|
|
; -------
|
|
|
|
|
2021-05-16 11:58:27 +02:00
|
|
|
[
|
2021-07-08 18:11:20 +02:00
|
|
|
"*"
|
|
|
|
"'"
|
|
|
|
"->"
|
|
|
|
"=>"
|
|
|
|
"<="
|
|
|
|
"="
|
|
|
|
"=="
|
|
|
|
"!"
|
|
|
|
"!="
|
|
|
|
"%"
|
|
|
|
"%="
|
|
|
|
"&"
|
|
|
|
"&="
|
|
|
|
"&&"
|
|
|
|
"|"
|
|
|
|
"|="
|
|
|
|
"||"
|
|
|
|
"^"
|
|
|
|
"^="
|
|
|
|
"*"
|
|
|
|
"*="
|
|
|
|
"-"
|
|
|
|
"-="
|
|
|
|
"+"
|
|
|
|
"+="
|
|
|
|
"/"
|
|
|
|
"/="
|
|
|
|
">"
|
|
|
|
"<"
|
|
|
|
">="
|
|
|
|
">>"
|
|
|
|
"<<"
|
|
|
|
">>="
|
2022-06-18 18:44:21 +02:00
|
|
|
"<<="
|
2021-07-08 18:11:20 +02:00
|
|
|
"@"
|
|
|
|
".."
|
|
|
|
"..="
|
|
|
|
"'"
|
2021-05-16 11:58:27 +02:00
|
|
|
] @operator
|
|
|
|
|
2021-07-08 18:11:20 +02:00
|
|
|
; -------
|
|
|
|
; Paths
|
|
|
|
; -------
|
|
|
|
|
|
|
|
(use_declaration
|
|
|
|
argument: (identifier) @namespace)
|
|
|
|
(use_wildcard
|
|
|
|
(identifier) @namespace)
|
|
|
|
(extern_crate_declaration
|
|
|
|
name: (identifier) @namespace)
|
|
|
|
(mod_item
|
|
|
|
name: (identifier) @namespace)
|
|
|
|
(scoped_use_list
|
|
|
|
path: (identifier)? @namespace)
|
|
|
|
(use_list
|
|
|
|
(identifier) @namespace)
|
|
|
|
(use_as_clause
|
|
|
|
path: (identifier)? @namespace
|
|
|
|
alias: (identifier) @namespace)
|
|
|
|
|
|
|
|
; ---
|
|
|
|
; Remaining Paths
|
|
|
|
; ---
|
|
|
|
|
|
|
|
(scoped_identifier
|
|
|
|
path: (identifier)? @namespace
|
|
|
|
name: (identifier) @namespace)
|
|
|
|
(scoped_type_identifier
|
|
|
|
path: (identifier) @namespace)
|
|
|
|
|
|
|
|
; -------
|
|
|
|
; Remaining Identifiers
|
|
|
|
; -------
|
|
|
|
|
2021-05-16 11:58:27 +02:00
|
|
|
"?" @special
|
2021-07-08 18:11:20 +02:00
|
|
|
|
|
|
|
(type_identifier) @type
|
|
|
|
(identifier) @variable
|
2021-11-03 04:00:52 +01:00
|
|
|
(field_identifier) @variable.other.member
|