2021-07-08 20:11:20 +04: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 18:18:25 +04:00
|
|
|
|
2021-05-16 13:58:27 +04:00
|
|
|
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
; -------
|
|
|
|
; Types
|
|
|
|
; -------
|
2021-05-16 13:58:27 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
; ---
|
|
|
|
; Primitives
|
|
|
|
; ---
|
2021-05-16 13:58:27 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
(escape_sequence) @escape
|
|
|
|
(primitive_type) @type.builtin
|
|
|
|
(boolean_literal) @constant.builtin
|
|
|
|
[
|
|
|
|
(integer_literal)
|
|
|
|
(float_literal)
|
|
|
|
] @number
|
|
|
|
[
|
|
|
|
(char_literal)
|
|
|
|
(string_literal)
|
|
|
|
(raw_string_literal)
|
|
|
|
] @string
|
|
|
|
[
|
|
|
|
(line_comment)
|
|
|
|
(block_comment)
|
|
|
|
] @comment
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
; ---
|
|
|
|
; Extraneous
|
|
|
|
; ---
|
2021-05-16 13:58:27 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
(self) @variable.builtin
|
|
|
|
(enum_variant (identifier) @type.enum.variant)
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
(field_initializer
|
|
|
|
(field_identifier) @property)
|
2021-08-18 20:02:15 +04:00
|
|
|
(shorthand_field_initializer
|
|
|
|
(identifier) @variable.property)
|
|
|
|
(shorthand_field_identifier) @variable.property
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
(lifetime
|
|
|
|
"'" @label
|
|
|
|
(identifier) @label)
|
|
|
|
(loop_label
|
|
|
|
(identifier) @type)
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
; ---
|
|
|
|
; Punctuation
|
|
|
|
; ---
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
[
|
|
|
|
"::"
|
|
|
|
"."
|
|
|
|
";"
|
|
|
|
] @punctuation.delimiter
|
2021-05-16 13:58:27 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
[
|
|
|
|
"("
|
|
|
|
")"
|
|
|
|
"["
|
|
|
|
"]"
|
2021-08-18 20:02:15 +04:00
|
|
|
"{"
|
|
|
|
"}"
|
2021-07-08 20:11:20 +04:00
|
|
|
] @punctuation.bracket
|
|
|
|
(type_arguments
|
|
|
|
[
|
|
|
|
"<"
|
|
|
|
">"
|
|
|
|
] @punctuation.bracket)
|
|
|
|
(type_parameters
|
|
|
|
[
|
|
|
|
"<"
|
|
|
|
">"
|
|
|
|
] @punctuation.bracket)
|
2021-05-16 13:58:27 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
; ---
|
|
|
|
; Parameters
|
|
|
|
; ---
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
(parameter
|
|
|
|
pattern: (identifier) @variable.parameter)
|
|
|
|
(closure_parameters
|
|
|
|
(identifier) @variable.parameter)
|
2021-04-08 18:18:25 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
; -------
|
|
|
|
; Keywords
|
|
|
|
; -------
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
(for_expression
|
|
|
|
"for" @keyword.control)
|
|
|
|
((identifier) @keyword.control
|
|
|
|
(#match? @keyword.control "^yield$"))
|
|
|
|
[
|
|
|
|
"while"
|
|
|
|
"loop"
|
|
|
|
"in"
|
|
|
|
"break"
|
|
|
|
"continue"
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
"match"
|
|
|
|
"if"
|
|
|
|
"else"
|
|
|
|
"return"
|
|
|
|
|
|
|
|
"await"
|
|
|
|
] @keyword.control
|
|
|
|
|
|
|
|
[
|
|
|
|
(crate)
|
|
|
|
(super)
|
|
|
|
"as"
|
|
|
|
"use"
|
|
|
|
"pub"
|
|
|
|
"mod"
|
|
|
|
"extern"
|
|
|
|
|
|
|
|
"fn"
|
|
|
|
"struct"
|
|
|
|
"enum"
|
|
|
|
"impl"
|
|
|
|
"where"
|
|
|
|
"trait"
|
|
|
|
"for"
|
|
|
|
|
|
|
|
"type"
|
|
|
|
"union"
|
|
|
|
"unsafe"
|
|
|
|
"default"
|
|
|
|
"macro_rules!"
|
|
|
|
|
|
|
|
"let"
|
|
|
|
"ref"
|
|
|
|
"move"
|
|
|
|
|
|
|
|
"dyn"
|
|
|
|
"static"
|
|
|
|
"const"
|
|
|
|
"async"
|
|
|
|
] @keyword
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-06-04 11:43:27 +04:00
|
|
|
(mutable_specifier) @keyword.mut
|
2021-04-08 18:18:25 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
; -------
|
|
|
|
; Guess Other Types
|
|
|
|
; -------
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
((identifier) @constant
|
|
|
|
(#match? @constant "^[A-Z][A-Z\\d_]+$"))
|
|
|
|
|
|
|
|
; ---
|
|
|
|
; PascalCase identifiers in call_expressions (e.g. `Ok()`)
|
|
|
|
; are assumed to be enum constructors.
|
|
|
|
; ---
|
|
|
|
|
|
|
|
(call_expression
|
|
|
|
function: [
|
|
|
|
((identifier) @type.variant
|
|
|
|
(#match? @type.variant "^[A-Z]"))
|
|
|
|
(scoped_identifier
|
|
|
|
name: ((identifier) @type.variant
|
|
|
|
(#match? @type.variant "^[A-Z]")))
|
|
|
|
])
|
|
|
|
|
|
|
|
; ---
|
|
|
|
; Assume that types in match arms are enums and not
|
|
|
|
; tuple structs. Same for `if let` expressions.
|
|
|
|
; ---
|
|
|
|
|
|
|
|
(match_pattern
|
|
|
|
(scoped_identifier
|
|
|
|
name: (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)
|
|
|
|
])
|
2021-04-08 18:18:25 +04:00
|
|
|
|
2021-07-08 20:11:20 +04: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)
|
|
|
|
|
|
|
|
; ---
|
|
|
|
; Macros
|
|
|
|
; ---
|
|
|
|
|
|
|
|
(meta_item
|
|
|
|
(identifier) @attribute)
|
2021-04-08 18:18:25 +04:00
|
|
|
(attribute_item) @attribute
|
|
|
|
(inner_attribute_item) @attribute
|
|
|
|
|
2021-07-08 20:11:20 +04:00
|
|
|
(macro_definition
|
|
|
|
name: (identifier) @function.macro)
|
|
|
|
(macro_invocation
|
|
|
|
macro: [
|
|
|
|
((identifier) @function.macro)
|
|
|
|
(scoped_identifier
|
|
|
|
name: (identifier) @function.macro)
|
|
|
|
]
|
|
|
|
"!" @function.macro)
|
|
|
|
|
|
|
|
(metavariable) @variable.parameter
|
|
|
|
(fragment_specifier) @variable.parameter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; -------
|
|
|
|
; Operators
|
|
|
|
; -------
|
|
|
|
|
2021-05-16 13:58:27 +04:00
|
|
|
[
|
2021-07-08 20:11:20 +04:00
|
|
|
"*"
|
|
|
|
"'"
|
|
|
|
"->"
|
|
|
|
"=>"
|
|
|
|
"<="
|
|
|
|
"="
|
|
|
|
"=="
|
|
|
|
"!"
|
|
|
|
"!="
|
|
|
|
"%"
|
|
|
|
"%="
|
|
|
|
"&"
|
|
|
|
"&="
|
|
|
|
"&&"
|
|
|
|
"|"
|
|
|
|
"|="
|
|
|
|
"||"
|
|
|
|
"^"
|
|
|
|
"^="
|
|
|
|
"*"
|
|
|
|
"*="
|
|
|
|
"-"
|
|
|
|
"-="
|
|
|
|
"+"
|
|
|
|
"+="
|
|
|
|
"/"
|
|
|
|
"/="
|
|
|
|
">"
|
|
|
|
"<"
|
|
|
|
">="
|
|
|
|
">>"
|
|
|
|
"<<"
|
|
|
|
">>="
|
|
|
|
"@"
|
|
|
|
".."
|
|
|
|
"..="
|
|
|
|
"'"
|
2021-05-16 13:58:27 +04:00
|
|
|
] @operator
|
|
|
|
|
2021-07-08 20:11:20 +04: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 13:58:27 +04:00
|
|
|
"?" @special
|
2021-07-08 20:11:20 +04:00
|
|
|
|
|
|
|
(type_identifier) @type
|
|
|
|
(identifier) @variable
|
2021-08-18 20:02:15 +04:00
|
|
|
(field_identifier) @property
|