|
|
@ -1,176 +1,256 @@
|
|
|
|
; Identifier conventions
|
|
|
|
; -------
|
|
|
|
|
|
|
|
; 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.
|
|
|
|
|
|
|
|
; -------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Assume all-caps names are constants
|
|
|
|
|
|
|
|
((identifier) @constant
|
|
|
|
|
|
|
|
(#match? @constant "^[A-Z][A-Z\\d_]+$"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Assume other uppercase names are enum constructors
|
|
|
|
; -------
|
|
|
|
(enum_variant) @type.enum.variant
|
|
|
|
; Types
|
|
|
|
((identifier) @constructor
|
|
|
|
; -------
|
|
|
|
(#match? @constructor "^[A-Z]"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Assume that uppercase names in paths are types
|
|
|
|
; ---
|
|
|
|
(mod_item
|
|
|
|
; Primitives
|
|
|
|
name: (identifier) @namespace)
|
|
|
|
; ---
|
|
|
|
(scoped_identifier
|
|
|
|
|
|
|
|
path: (identifier) @namespace)
|
|
|
|
|
|
|
|
(scoped_identifier
|
|
|
|
|
|
|
|
(scoped_identifier
|
|
|
|
|
|
|
|
name: (identifier) @namespace))
|
|
|
|
|
|
|
|
(scoped_type_identifier
|
|
|
|
|
|
|
|
path: (identifier) @namespace)
|
|
|
|
|
|
|
|
(scoped_type_identifier
|
|
|
|
|
|
|
|
(scoped_identifier
|
|
|
|
|
|
|
|
name: (identifier) @namespace))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
((scoped_identifier
|
|
|
|
(escape_sequence) @escape
|
|
|
|
path: (identifier) @type)
|
|
|
|
(primitive_type) @type.builtin
|
|
|
|
(#match? @type "^[A-Z]"))
|
|
|
|
(boolean_literal) @constant.builtin
|
|
|
|
((scoped_identifier
|
|
|
|
[
|
|
|
|
path: (scoped_identifier
|
|
|
|
(integer_literal)
|
|
|
|
name: (identifier) @type))
|
|
|
|
(float_literal)
|
|
|
|
(#match? @type "^[A-Z]"))
|
|
|
|
] @number
|
|
|
|
|
|
|
|
[
|
|
|
|
|
|
|
|
(char_literal)
|
|
|
|
|
|
|
|
(string_literal)
|
|
|
|
|
|
|
|
(raw_string_literal)
|
|
|
|
|
|
|
|
] @string
|
|
|
|
|
|
|
|
[
|
|
|
|
|
|
|
|
(line_comment)
|
|
|
|
|
|
|
|
(block_comment)
|
|
|
|
|
|
|
|
] @comment
|
|
|
|
|
|
|
|
|
|
|
|
; Namespaces
|
|
|
|
; ---
|
|
|
|
|
|
|
|
; Extraneous
|
|
|
|
|
|
|
|
; ---
|
|
|
|
|
|
|
|
|
|
|
|
(crate) @namespace
|
|
|
|
(self) @variable.builtin
|
|
|
|
(extern_crate_declaration
|
|
|
|
(enum_variant (identifier) @type.enum.variant)
|
|
|
|
(crate)
|
|
|
|
|
|
|
|
name: (identifier) @namespace)
|
|
|
|
|
|
|
|
(scoped_use_list
|
|
|
|
|
|
|
|
path: (identifier) @namespace)
|
|
|
|
|
|
|
|
(scoped_use_list
|
|
|
|
|
|
|
|
path: (scoped_identifier
|
|
|
|
|
|
|
|
(identifier) @namespace))
|
|
|
|
|
|
|
|
(use_list (scoped_identifier (identifier) @namespace . (_)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Function calls
|
|
|
|
(field_initializer
|
|
|
|
|
|
|
|
(field_identifier) @property)
|
|
|
|
|
|
|
|
(shorthand_field_initializer) @variable
|
|
|
|
|
|
|
|
(shorthand_field_identifier) @variable
|
|
|
|
|
|
|
|
|
|
|
|
(call_expression
|
|
|
|
(lifetime
|
|
|
|
function: (identifier) @function)
|
|
|
|
"'" @label
|
|
|
|
(call_expression
|
|
|
|
(identifier) @label)
|
|
|
|
function: (field_expression
|
|
|
|
(loop_label
|
|
|
|
field: (field_identifier) @function.method))
|
|
|
|
(identifier) @type)
|
|
|
|
(call_expression
|
|
|
|
|
|
|
|
function: (scoped_identifier
|
|
|
|
; ---
|
|
|
|
|
|
|
|
; Punctuation
|
|
|
|
|
|
|
|
; ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
"::"
|
|
|
|
"::"
|
|
|
|
name: (identifier) @function))
|
|
|
|
"."
|
|
|
|
|
|
|
|
";"
|
|
|
|
|
|
|
|
] @punctuation.delimiter
|
|
|
|
|
|
|
|
|
|
|
|
(generic_function
|
|
|
|
[
|
|
|
|
function: (identifier) @function)
|
|
|
|
"("
|
|
|
|
(generic_function
|
|
|
|
")"
|
|
|
|
function: (scoped_identifier
|
|
|
|
"["
|
|
|
|
name: (identifier) @function))
|
|
|
|
"]"
|
|
|
|
(generic_function
|
|
|
|
] @punctuation.bracket
|
|
|
|
function: (field_expression
|
|
|
|
(type_arguments
|
|
|
|
field: (field_identifier) @function.method))
|
|
|
|
[
|
|
|
|
|
|
|
|
"<"
|
|
|
|
|
|
|
|
">"
|
|
|
|
|
|
|
|
] @punctuation.bracket)
|
|
|
|
|
|
|
|
(type_parameters
|
|
|
|
|
|
|
|
[
|
|
|
|
|
|
|
|
"<"
|
|
|
|
|
|
|
|
">"
|
|
|
|
|
|
|
|
] @punctuation.bracket)
|
|
|
|
|
|
|
|
|
|
|
|
(macro_invocation
|
|
|
|
; ---
|
|
|
|
macro: (identifier) @function.macro
|
|
|
|
; Parameters
|
|
|
|
"!" @function.macro)
|
|
|
|
; ---
|
|
|
|
(macro_invocation
|
|
|
|
|
|
|
|
macro: (scoped_identifier
|
|
|
|
|
|
|
|
(identifier) @function.macro .))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; (metavariable) @variable
|
|
|
|
(parameter
|
|
|
|
(metavariable) @function.macro
|
|
|
|
pattern: (identifier) @variable.parameter)
|
|
|
|
|
|
|
|
(closure_parameters
|
|
|
|
|
|
|
|
(identifier) @variable.parameter)
|
|
|
|
|
|
|
|
|
|
|
|
"$" @function.macro
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; Function definitions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(function_item (identifier) @function)
|
|
|
|
; -------
|
|
|
|
(function_signature_item (identifier) @function)
|
|
|
|
; Keywords
|
|
|
|
|
|
|
|
; -------
|
|
|
|
|
|
|
|
|
|
|
|
; Other identifiers
|
|
|
|
(for_expression
|
|
|
|
|
|
|
|
"for" @keyword.control)
|
|
|
|
|
|
|
|
((identifier) @keyword.control
|
|
|
|
|
|
|
|
(#match? @keyword.control "^yield$"))
|
|
|
|
|
|
|
|
[
|
|
|
|
|
|
|
|
"while"
|
|
|
|
|
|
|
|
"loop"
|
|
|
|
|
|
|
|
"in"
|
|
|
|
|
|
|
|
"break"
|
|
|
|
|
|
|
|
"continue"
|
|
|
|
|
|
|
|
|
|
|
|
(type_identifier) @type
|
|
|
|
"match"
|
|
|
|
(primitive_type) @type.builtin
|
|
|
|
"if"
|
|
|
|
(field_identifier) @property
|
|
|
|
"else"
|
|
|
|
|
|
|
|
"return"
|
|
|
|
|
|
|
|
|
|
|
|
(line_comment) @comment
|
|
|
|
"await"
|
|
|
|
(block_comment) @comment
|
|
|
|
] @keyword.control
|
|
|
|
|
|
|
|
|
|
|
|
"(" @punctuation.bracket
|
|
|
|
[
|
|
|
|
")" @punctuation.bracket
|
|
|
|
(crate)
|
|
|
|
"[" @punctuation.bracket
|
|
|
|
(super)
|
|
|
|
"]" @punctuation.bracket
|
|
|
|
"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
|
|
|
|
|
|
|
|
|
|
|
|
(type_arguments
|
|
|
|
|
|
|
|
"<" @punctuation.bracket
|
|
|
|
|
|
|
|
">" @punctuation.bracket)
|
|
|
|
|
|
|
|
(type_parameters
|
|
|
|
|
|
|
|
"<" @punctuation.bracket
|
|
|
|
|
|
|
|
">" @punctuation.bracket)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"::" @punctuation.delimiter
|
|
|
|
|
|
|
|
"." @punctuation.delimiter
|
|
|
|
|
|
|
|
";" @punctuation.delimiter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(parameter (identifier) @variable.parameter)
|
|
|
|
|
|
|
|
(closure_parameters (_) @variable.parameter)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(lifetime (identifier) @label)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"async" @keyword
|
|
|
|
|
|
|
|
"break" @keyword
|
|
|
|
|
|
|
|
"const" @keyword
|
|
|
|
|
|
|
|
"continue" @keyword
|
|
|
|
|
|
|
|
(crate) @keyword
|
|
|
|
|
|
|
|
"default" @keyword
|
|
|
|
|
|
|
|
"dyn" @keyword
|
|
|
|
|
|
|
|
"else" @keyword
|
|
|
|
|
|
|
|
"enum" @keyword
|
|
|
|
|
|
|
|
"extern" @keyword
|
|
|
|
|
|
|
|
"fn" @keyword
|
|
|
|
|
|
|
|
"for" @keyword
|
|
|
|
|
|
|
|
"if" @keyword
|
|
|
|
|
|
|
|
"impl" @keyword
|
|
|
|
|
|
|
|
"in" @keyword
|
|
|
|
|
|
|
|
"let" @keyword
|
|
|
|
|
|
|
|
"let" @keyword
|
|
|
|
|
|
|
|
"loop" @keyword
|
|
|
|
|
|
|
|
"macro_rules!" @keyword
|
|
|
|
|
|
|
|
"match" @keyword
|
|
|
|
|
|
|
|
"mod" @keyword
|
|
|
|
|
|
|
|
"move" @keyword
|
|
|
|
|
|
|
|
"pub" @keyword
|
|
|
|
|
|
|
|
"ref" @keyword
|
|
|
|
|
|
|
|
"return" @keyword
|
|
|
|
|
|
|
|
"static" @keyword
|
|
|
|
|
|
|
|
"struct" @keyword
|
|
|
|
|
|
|
|
"trait" @keyword
|
|
|
|
|
|
|
|
"type" @keyword
|
|
|
|
|
|
|
|
"union" @keyword
|
|
|
|
|
|
|
|
"unsafe" @keyword
|
|
|
|
|
|
|
|
"use" @keyword
|
|
|
|
|
|
|
|
"where" @keyword
|
|
|
|
|
|
|
|
"while" @keyword
|
|
|
|
|
|
|
|
(mutable_specifier) @keyword.mut
|
|
|
|
(mutable_specifier) @keyword.mut
|
|
|
|
(use_list (self) @keyword)
|
|
|
|
|
|
|
|
(scoped_use_list (self) @keyword)
|
|
|
|
|
|
|
|
(scoped_identifier (self) @keyword)
|
|
|
|
|
|
|
|
(super) @keyword
|
|
|
|
|
|
|
|
"as" @keyword
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(self) @variable.builtin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
|
|
|
|
(char_literal)
|
|
|
|
|
|
|
|
(string_literal)
|
|
|
|
|
|
|
|
(raw_string_literal)
|
|
|
|
|
|
|
|
] @string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(boolean_literal) @constant.builtin
|
|
|
|
; -------
|
|
|
|
(integer_literal) @number
|
|
|
|
; Guess Other Types
|
|
|
|
(float_literal) @number
|
|
|
|
; -------
|
|
|
|
|
|
|
|
|
|
|
|
(escape_sequence) @escape
|
|
|
|
((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)
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; ---
|
|
|
|
|
|
|
|
; 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)
|
|
|
|
(attribute_item) @attribute
|
|
|
|
(attribute_item) @attribute
|
|
|
|
(inner_attribute_item) @attribute
|
|
|
|
(inner_attribute_item) @attribute
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(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
|
|
|
|
|
|
|
|
; -------
|
|
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
[
|
|
|
|
"*"
|
|
|
|
"*"
|
|
|
|
"'"
|
|
|
|
"'"
|
|
|
@ -211,4 +291,46 @@
|
|
|
|
"'"
|
|
|
|
"'"
|
|
|
|
] @operator
|
|
|
|
] @operator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; -------
|
|
|
|
|
|
|
|
; 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
|
|
|
|
|
|
|
|
; -------
|
|
|
|
|
|
|
|
|
|
|
|
"?" @special
|
|
|
|
"?" @special
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(type_identifier) @type
|
|
|
|
|
|
|
|
(identifier) @variable
|
|
|
|
|
|
|
|
(field_identifier) @variable
|
|
|
|