aboutsummaryrefslogtreecommitdiffstats
path: root/runtime/queries/hare
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-06-12 09:54:30 -0600
committerChristian Clason <c.clason@uni-graz.at>2025-05-12 18:43:40 +0200
commit692b051b09935653befdb8f7ba8afdb640adf17b (patch)
tree167162b6b129ae04f68c5735078521a72917c742 /runtime/queries/hare
parentfeat(c-family): inherit injections (diff)
downloadnvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'runtime/queries/hare')
-rw-r--r--runtime/queries/hare/folds.scm18
-rw-r--r--runtime/queries/hare/highlights.scm272
-rw-r--r--runtime/queries/hare/indents.scm45
-rw-r--r--runtime/queries/hare/injections.scm18
-rw-r--r--runtime/queries/hare/locals.scm65
5 files changed, 418 insertions, 0 deletions
diff --git a/runtime/queries/hare/folds.scm b/runtime/queries/hare/folds.scm
new file mode 100644
index 000000000..58b10bfdc
--- /dev/null
+++ b/runtime/queries/hare/folds.scm
@@ -0,0 +1,18 @@
+[
+ (imports)
+ (function_declaration)
+ (enum_type)
+ (struct_type)
+ (tuple_type)
+ (union_type)
+ (block)
+ (if_statement)
+ (for_statement)
+ (call_expression)
+ (switch_expression)
+ (match_expression)
+ (case)
+ (array_literal)
+ (struct_literal)
+ (tuple_literal)
+] @fold
diff --git a/runtime/queries/hare/highlights.scm b/runtime/queries/hare/highlights.scm
new file mode 100644
index 000000000..deaecd283
--- /dev/null
+++ b/runtime/queries/hare/highlights.scm
@@ -0,0 +1,272 @@
+; Variables
+(identifier) @variable
+
+; Types
+(type) @type
+
+(scoped_type_identifier
+ (identifier)
+ .
+ (identifier) @type)
+
+(struct_literal
+ .
+ (identifier) @type)
+
+(builtin_type) @type.builtin
+
+; Constants
+((identifier) @constant
+ (#lua-match? @constant "^[A-Z_]+$"))
+
+; Includes
+[
+ "use"
+ "export"
+] @keyword.import
+
+(use_statement
+ (scoped_type_identifier
+ (identifier) @module))
+
+(use_statement
+ (identifier) @module
+ "{")
+
+(use_statement
+ .
+ (identifier) @module .)
+
+((scoped_type_identifier
+ path: (_) @module)
+ (#set! priority 105))
+
+; Keywords
+[
+ "def"
+ "let"
+] @keyword
+
+[
+ "enum"
+ "struct"
+ "union"
+ "type"
+] @keyword.type
+
+"fn" @keyword.function
+
+[
+ "defer"
+ "yield"
+ "return"
+] @keyword.return
+
+[
+ "as"
+ "is"
+] @keyword.operator
+
+; Typedefs
+(type_declaration
+ "type"
+ (identifier) @type.definition
+ .
+ "=")
+
+; Qualifiers
+[
+ "const"
+ "static"
+ "nullable"
+] @keyword.modifier
+
+; Attributes
+[
+ "@fini"
+ "@init"
+ "@test"
+ "@noreturn"
+ "@packed"
+ (declaration_attribute)
+] @attribute
+
+; Labels
+((label) @label
+ (#set! priority 105))
+
+; Functions
+(function_declaration
+ "fn"
+ .
+ (identifier) @function)
+
+(call_expression
+ .
+ (identifier) @function.call)
+
+(call_expression
+ .
+ (scoped_type_identifier
+ .
+ (identifier)
+ .
+ "::"
+ .
+ (identifier) @function.method.call))
+
+((call_expression
+ .
+ (identifier) @function.builtin)
+ (#any-of? @function.builtin "align" "assert" "free" "len" "offset" "size"))
+
+(size_expression
+ "size" @function.builtin)
+
+((function_declaration
+ "fn"
+ .
+ (identifier) @constructor)
+ (#eq? @constructor "init"))
+
+((call_expression
+ .
+ (identifier) @constructor)
+ (#eq? @constructor "init"))
+
+; Parameters
+(parameter
+ (_) @variable.parameter
+ .
+ ":")
+
+; Fields
+((member_expression
+ "."
+ (_) @variable.member)
+ (#set! priority 105))
+
+(field
+ .
+ (identifier) @variable.member)
+
+(field_assignment
+ .
+ (identifier) @variable.member)
+
+; Repeats
+"for" @keyword.repeat
+
+; Conditionals
+[
+ "if"
+ "else"
+ "break"
+ "switch"
+ "match"
+ "case"
+] @keyword.conditional
+
+; Operators
+[
+ "+"
+ "-"
+ "*"
+ "/"
+ "%"
+ "||"
+ "&&"
+ "^^"
+ "|"
+ "&"
+ "^"
+ "=="
+ "!="
+ ">"
+ ">="
+ "<="
+ "<"
+ "<<"
+ ">>"
+ "~"
+ "!"
+ "+="
+ "-="
+ "*="
+ "/="
+ "%="
+ "<<="
+ ">>="
+ "|="
+ "&="
+ "^="
+ "||="
+ "&&="
+ "^^="
+ "="
+ "?"
+] @operator
+
+; Punctuation
+[
+ "{"
+ "}"
+] @punctuation.bracket
+
+[
+ "["
+ "]"
+] @punctuation.bracket
+
+[
+ "("
+ ")"
+] @punctuation.bracket
+
+[
+ ".."
+ "..."
+ "_"
+] @punctuation.special
+
+(pointer_type
+ "*" @punctuation.special)
+
+(slice_type
+ "*" @punctuation.special)
+
+(error_type
+ "!" @punctuation.special)
+
+[
+ ","
+ "."
+ ":"
+ ";"
+ "::"
+ "=>"
+] @punctuation.delimiter
+
+; Literals
+[
+ (string)
+ (raw_string)
+] @string
+
+(rune) @character
+
+(escape_sequence) @string.escape
+
+(number) @number
+
+(float) @number.float
+
+(boolean) @boolean
+
+[
+ (void)
+ (null)
+] @constant.builtin
+
+; Comments
+(comment) @comment @spell
diff --git a/runtime/queries/hare/indents.scm b/runtime/queries/hare/indents.scm
new file mode 100644
index 000000000..9e41ea6d0
--- /dev/null
+++ b/runtime/queries/hare/indents.scm
@@ -0,0 +1,45 @@
+[
+ (enum_type)
+ (struct_type)
+ (tuple_type)
+ (union_type)
+ (block)
+ (for_statement)
+ (call_expression)
+ (case)
+ (array_literal)
+ (struct_literal)
+ (tuple_literal)
+] @indent.begin
+
+(if_statement
+ ("("
+ condition: (_)
+ ")") @indent.begin)
+
+[
+ "}"
+ "]"
+ ")"
+] @indent.end
+
+[
+ "{"
+ "}"
+] @indent.branch
+
+[
+ "["
+ "]"
+] @indent.branch
+
+[
+ "("
+ ")"
+] @indent.branch
+
+[
+ (ERROR)
+ (comment)
+ (concatenated_string)
+] @indent.auto
diff --git a/runtime/queries/hare/injections.scm b/runtime/queries/hare/injections.scm
new file mode 100644
index 000000000..88a3f1cdd
--- /dev/null
+++ b/runtime/queries/hare/injections.scm
@@ -0,0 +1,18 @@
+((comment) @injection.content
+ (#set! injection.language "comment"))
+
+((call_expression
+ .
+ (_) @_fnname
+ .
+ "("
+ .
+ (_
+ [
+ (string_content)
+ (raw_string_content)
+ ] @injection.content)
+ .
+ ")")
+ (#any-of? @_fnname "compile" "regex::compile")
+ (#set! injection.language "regex"))
diff --git a/runtime/queries/hare/locals.scm b/runtime/queries/hare/locals.scm
new file mode 100644
index 000000000..12a214bf7
--- /dev/null
+++ b/runtime/queries/hare/locals.scm
@@ -0,0 +1,65 @@
+; Scopes
+[
+ (module)
+ (function_declaration)
+ (if_statement)
+ (for_statement)
+ (match_expression)
+ (switch_expression)
+] @local.scope
+
+; References
+[
+ (identifier)
+ (scoped_type_identifier)
+] @local.reference
+
+; Definitions
+(global_binding
+ (identifier) @local.definition.constant
+ .
+ ":"
+ (_))
+
+(const_declaration
+ "const"
+ (identifier) @local.definition.constant
+ .
+ "=")
+
+(field
+ .
+ (identifier) @local.definition.field)
+
+(field_assignment
+ .
+ (identifier) @local.definition.field)
+
+(function_declaration
+ "fn"
+ .
+ (identifier) @local.definition.function)
+
+(parameter
+ (_) @local.definition.parameter
+ .
+ ":")
+
+(type_declaration
+ "type"
+ (identifier) @local.definition.type
+ .
+ "=")
+
+(type_declaration
+ "type"
+ (identifier) @local.definition.enum
+ .
+ "="
+ (enum_type))
+
+(let_declaration
+ "let"
+ .
+ (identifier) @local.definition.var
+ ","?)