aboutsummaryrefslogtreecommitdiffstats
path: root/queries
diff options
context:
space:
mode:
authorThomas Vigouroux <39092278+vigoux@users.noreply.github.com>2020-07-08 12:35:53 +0200
committerGitHub <noreply@github.com>2020-07-08 12:35:53 +0200
commit0d2385407eddb95e66a43710798f27bd9256186a (patch)
treea9f124af46bde9bde5b187be3567b8952d092381 /queries
parentdocs: advertise module-template in CONTRIBUTING.md (diff)
downloadnvim-treesitter-0d2385407eddb95e66a43710798f27bd9256186a.tar
nvim-treesitter-0d2385407eddb95e66a43710798f27bd9256186a.tar.gz
nvim-treesitter-0d2385407eddb95e66a43710798f27bd9256186a.tar.bz2
nvim-treesitter-0d2385407eddb95e66a43710798f27bd9256186a.tar.lz
nvim-treesitter-0d2385407eddb95e66a43710798f27bd9256186a.tar.xz
nvim-treesitter-0d2385407eddb95e66a43710798f27bd9256186a.tar.zst
nvim-treesitter-0d2385407eddb95e66a43710798f27bd9256186a.zip
Add Rust queries (#57)
* queries(rust): add highlight query. Also slightly changes the way constructors are highlighted. * highglight(rust): use new query syntax
Diffstat (limited to 'queries')
-rw-r--r--queries/rust/highlights.scm167
1 files changed, 167 insertions, 0 deletions
diff --git a/queries/rust/highlights.scm b/queries/rust/highlights.scm
new file mode 100644
index 000000000..9e66a0f93
--- /dev/null
+++ b/queries/rust/highlights.scm
@@ -0,0 +1,167 @@
+; Forked from https://github.com/tree-sitter/tree-sitter-rust
+; Copyright (c) 2017 Maxim Sokolov
+; Licensed under the MIT license.
+
+; Identifier conventions
+
+; Assume all-caps names are constants
+((identifier) @constant
+ (#match? @constant "^[A-Z][A-Z\\d_]+$'"))
+
+; Other identifiers
+
+(type_identifier) @type
+(primitive_type) @type.builtin
+(field_identifier) @field
+
+
+; Function calls
+(call_expression
+ function: (identifier) @function)
+(call_expression
+ function: (field_expression
+ field: (field_identifier) @function))
+
+(generic_function
+ function: (identifier) @function)
+(generic_function
+ function: (scoped_identifier
+ name: (identifier) @function))
+(generic_function
+ function: (field_expression
+ field: (field_identifier) @function))
+
+; Assume other uppercase names are enum constructors
+([(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]"))
+((scoped_identifier
+ name: (identifier) @type)
+ (#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
+ "!" @function.macro)
+
+; Function definitions
+
+(function_item (identifier) @function)
+(function_signature_item (identifier) @function)
+
+[
+(line_comment)
+(block_comment)
+ ] @comment
+
+[
+"("
+")"
+"["
+"]"
+ ] @punctuation.bracket
+
+(type_arguments
+ "<" @punctuation.bracket
+ ">" @punctuation.bracket)
+(type_parameters
+ "<" @punctuation.bracket
+ ">" @punctuation.bracket)
+
+[
+"::"
+"."
+";"
+ ] @punctuation.delimiter
+
+(parameter (identifier) @parameter)
+
+(lifetime (identifier) @label)
+
+(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)
+
+[
+"continue"
+"else"
+"if"
+] @conditional
+
+[
+"for"
+"in"
+"loop"
+"while"
+] @repeat
+
+[
+(char_literal)
+(string_literal)
+(raw_string_literal)
+] @string
+
+(boolean_literal) @boolean
+(integer_literal) @number
+(float_literal) @float
+
+(escape_sequence) @string.escape
+
+[
+"as"
+"*"
+"&"
+"'"
+ ] @operator
+
+(closure_parameters "|" @operator "|" @operator)