mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-02 19:46:58 -04:00
highglight(rust): use new query syntax
This commit is contained in:
parent
8a76b16814
commit
93c52129ae
1 changed files with 98 additions and 70 deletions
|
|
@ -6,7 +6,13 @@
|
|||
|
||||
; Assume all-caps names are constants
|
||||
((identifier) @constant
|
||||
(match? @constant "^[A-Z][A-Z\\d_]+$'"))
|
||||
(#match? @constant "^[A-Z][A-Z\\d_]+$'"))
|
||||
|
||||
; Other identifiers
|
||||
|
||||
(type_identifier) @type
|
||||
(primitive_type) @type.builtin
|
||||
(field_identifier) @field
|
||||
|
||||
|
||||
; Function calls
|
||||
|
|
@ -14,11 +20,7 @@
|
|||
function: (identifier) @function)
|
||||
(call_expression
|
||||
function: (field_expression
|
||||
field: (field_identifier) @method))
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
"::"
|
||||
name: (identifier) @function))
|
||||
field: (field_identifier) @function))
|
||||
|
||||
(generic_function
|
||||
function: (identifier) @function)
|
||||
|
|
@ -27,19 +29,32 @@
|
|||
name: (identifier) @function))
|
||||
(generic_function
|
||||
function: (field_expression
|
||||
field: (field_identifier) @method))
|
||||
field: (field_identifier) @function))
|
||||
|
||||
; Assume other uppercase names are enum constructors
|
||||
((identifier) @constructor
|
||||
(match? @constructor "^[A-Z]"))
|
||||
([(identifier) (field_identifier)] @constant
|
||||
(#match? @constant "^[A-Z]"))
|
||||
|
||||
; Assume that uppercase names in paths are types
|
||||
((scoped_identifier
|
||||
path: (identifier) @type)
|
||||
(match? @type "^[A-Z]"))
|
||||
(#match? @type "^[A-Z]"))
|
||||
((scoped_identifier
|
||||
name: (identifier) @type)
|
||||
(match? @type "^[A-Z]"))
|
||||
(#match? @type "^[A-Z]"))
|
||||
|
||||
;; Correct enum constructors
|
||||
(call_expression
|
||||
function: (scoped_identifier
|
||||
"::"
|
||||
name: (identifier) @constant)
|
||||
(#match? @constant "^[A-Z]"))
|
||||
|
||||
;; Assume that all `#[derive]` arguments are types
|
||||
(meta_item
|
||||
(identifier) @meta
|
||||
arguments: (meta_arguments (meta_item (identifier) @type))
|
||||
(#eq? @meta "derive"))
|
||||
|
||||
(macro_invocation
|
||||
macro: (identifier) @function.macro
|
||||
|
|
@ -50,19 +65,17 @@
|
|||
(function_item (identifier) @function)
|
||||
(function_signature_item (identifier) @function)
|
||||
|
||||
; Other identifiers
|
||||
[
|
||||
(line_comment)
|
||||
(block_comment)
|
||||
] @comment
|
||||
|
||||
(type_identifier) @type
|
||||
(primitive_type) @type.builtin
|
||||
(field_identifier) @field
|
||||
|
||||
(line_comment) @comment
|
||||
(block_comment) @comment
|
||||
|
||||
"(" @punctuation.bracket
|
||||
")" @punctuation.bracket
|
||||
"[" @punctuation.bracket
|
||||
"]" @punctuation.bracket
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
] @punctuation.bracket
|
||||
|
||||
(type_arguments
|
||||
"<" @punctuation.bracket
|
||||
|
|
@ -71,56 +84,72 @@
|
|||
"<" @punctuation.bracket
|
||||
">" @punctuation.bracket)
|
||||
|
||||
"::" @punctuation.delimiter
|
||||
"." @punctuation.delimiter
|
||||
";" @punctuation.delimiter
|
||||
[
|
||||
"::"
|
||||
"."
|
||||
";"
|
||||
] @punctuation.delimiter
|
||||
|
||||
(parameter (identifier) @parameter)
|
||||
|
||||
(lifetime (identifier) @label)
|
||||
|
||||
"break" @keyword
|
||||
"const" @keyword
|
||||
"continue" @conditional
|
||||
"default" @keyword
|
||||
"dyn" @keyword
|
||||
"else" @conditional
|
||||
"enum" @keyword
|
||||
"extern" @keyword
|
||||
"fn" @keyword
|
||||
"for" @repeat
|
||||
"if" @conditional
|
||||
"impl" @keyword
|
||||
"in" @repeat
|
||||
"let" @keyword
|
||||
"loop" @repeat
|
||||
"macro_rules!" @keyword
|
||||
"match" @keyword
|
||||
"mod" @keyword
|
||||
"move" @keyword
|
||||
"pub" @keyword
|
||||
"ref" @keyword
|
||||
"return" @keyword
|
||||
"static" @keyword
|
||||
"struct" @structure
|
||||
"trait" @keyword
|
||||
"type" @keyword
|
||||
"union" @keyword
|
||||
"unsafe" @keyword
|
||||
"use" @keyword
|
||||
"where" @keyword
|
||||
"while" @repeat
|
||||
(mutable_specifier) @keyword
|
||||
(self) @variable.builtin
|
||||
|
||||
[
|
||||
"break"
|
||||
"const"
|
||||
"default"
|
||||
"dyn"
|
||||
"enum"
|
||||
"extern"
|
||||
"fn"
|
||||
"impl"
|
||||
"let"
|
||||
"macro_rules!"
|
||||
"match"
|
||||
"mod"
|
||||
"move"
|
||||
"pub"
|
||||
"ref"
|
||||
"return"
|
||||
"static"
|
||||
"struct"
|
||||
"trait"
|
||||
"type"
|
||||
"union"
|
||||
"unsafe"
|
||||
"use"
|
||||
"where"
|
||||
(mutable_specifier)
|
||||
(super)
|
||||
; TODO(vigoux): attribute items should have some kind of injections
|
||||
(attribute_item)
|
||||
(inner_attribute_item)
|
||||
] @keyword
|
||||
|
||||
(use_list (self) @keyword)
|
||||
(scoped_use_list (self) @keyword)
|
||||
(scoped_identifier (self) @keyword)
|
||||
(super) @keyword
|
||||
|
||||
(self) @variable.builtin
|
||||
[
|
||||
"continue"
|
||||
"else"
|
||||
"if"
|
||||
] @conditional
|
||||
|
||||
(char_literal) @string
|
||||
(string_literal) @string
|
||||
(raw_string_literal) @string
|
||||
[
|
||||
"for"
|
||||
"in"
|
||||
"loop"
|
||||
"while"
|
||||
] @repeat
|
||||
|
||||
[
|
||||
(char_literal)
|
||||
(string_literal)
|
||||
(raw_string_literal)
|
||||
] @string
|
||||
|
||||
(boolean_literal) @boolean
|
||||
(integer_literal) @number
|
||||
|
|
@ -128,12 +157,11 @@
|
|||
|
||||
(escape_sequence) @string.escape
|
||||
|
||||
; TODO(vigoux): attribute items should have some kind of injections
|
||||
(attribute_item) @keyword
|
||||
(inner_attribute_item) @keyword
|
||||
[
|
||||
"as"
|
||||
"*"
|
||||
"&"
|
||||
"'"
|
||||
] @operator
|
||||
|
||||
"as" @operator
|
||||
"*" @operator
|
||||
"&" @operator
|
||||
"'" @operator
|
||||
(closure_parameters "|" @operator "|" @operator)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue