diff options
| author | Amaan Qureshi <amaanq12@gmail.com> | 2023-03-11 03:02:30 -0500 |
|---|---|---|
| committer | Amaan Qureshi <amaanq12@gmail.com> | 2023-03-11 03:45:31 -0500 |
| commit | 207a86e4c91898a6eaf476271faa6e09f1109709 (patch) | |
| tree | 4613345b1dd56bbc29d96a602e785c348ab48685 /queries/hare | |
| parent | highlights(prql): change `loop` and `case` highlight (diff) | |
| download | nvim-treesitter-207a86e4c91898a6eaf476271faa6e09f1109709.tar nvim-treesitter-207a86e4c91898a6eaf476271faa6e09f1109709.tar.gz nvim-treesitter-207a86e4c91898a6eaf476271faa6e09f1109709.tar.bz2 nvim-treesitter-207a86e4c91898a6eaf476271faa6e09f1109709.tar.lz nvim-treesitter-207a86e4c91898a6eaf476271faa6e09f1109709.tar.xz nvim-treesitter-207a86e4c91898a6eaf476271faa6e09f1109709.tar.zst nvim-treesitter-207a86e4c91898a6eaf476271faa6e09f1109709.zip | |
feat: add Hare
Diffstat (limited to 'queries/hare')
| -rw-r--r-- | queries/hare/folds.scm | 21 | ||||
| -rw-r--r-- | queries/hare/highlights.scm | 255 | ||||
| -rw-r--r-- | queries/hare/indents.scm | 36 | ||||
| -rw-r--r-- | queries/hare/injections.scm | 8 | ||||
| -rw-r--r-- | queries/hare/locals.scm | 47 |
5 files changed, 367 insertions, 0 deletions
diff --git a/queries/hare/folds.scm b/queries/hare/folds.scm new file mode 100644 index 000000000..28f18b175 --- /dev/null +++ b/queries/hare/folds.scm @@ -0,0 +1,21 @@ +[ + (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/queries/hare/highlights.scm b/queries/hare/highlights.scm new file mode 100644 index 000000000..063af31b3 --- /dev/null +++ b/queries/hare/highlights.scm @@ -0,0 +1,255 @@ +; 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" +] @include + +(use_statement + (scoped_type_identifier + (identifier) @namespace)) +(use_statement + (identifier) @namespace "{") +(use_statement + . (identifier) @namespace .) + +((scoped_type_identifier + path: (_) @namespace) + (#set! "priority" 105)) + +; Keywords + +[ + "def" + "enum" + "export" + "let" + "struct" + "type" + "union" +] @keyword + +[ + "fn" +] @keyword.function + +[ + "defer" + "yield" + "return" +] @keyword.return + +[ + "as" + "is" +] @keyword.operator + +; Typedefs + +(type_declaration + "type" (identifier) @type.definition . "=") + +; Qualifiers + +[ + "const" + "static" + "nullable" +] @type.qualifier + +; 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) @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 + (_) @parameter . ":") + +; Fields + +((member_expression + "." (_) @field) + (#set! "priority" 105)) + +(field + . (identifier) @field) + +(field_assignment + . (identifier) @field) + +; Repeats + +[ + "for" +] @repeat + +; Conditionals + +[ + "if" + "else" + "break" + "switch" + "match" + "case" +] @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) @float + +(boolean) @boolean + +[ + (void) + (null) +] @constant.builtin + +; Comments + +(comment) @comment @spell + +; Errors + +(ERROR) @error diff --git a/queries/hare/indents.scm b/queries/hare/indents.scm new file mode 100644 index 000000000..0324f09c6 --- /dev/null +++ b/queries/hare/indents.scm @@ -0,0 +1,36 @@ +[ + (enum_type) + (struct_type) + (tuple_type) + (union_type) + + (block) + (for_statement) + (call_expression) + (case) + + (array_literal) + (struct_literal) + (tuple_literal) +] @indent + +(if_statement + ("(" condition: (_) ")") @indent) + +[ + "}" + "]" + ")" +] @indent_end + +[ "{" "}" ] @branch + +[ "[" "]" ] @branch + +[ "(" ")" ] @branch + +[ + (ERROR) + (comment) + (concatenated_string) +] @auto diff --git a/queries/hare/injections.scm b/queries/hare/injections.scm new file mode 100644 index 000000000..2992a948d --- /dev/null +++ b/queries/hare/injections.scm @@ -0,0 +1,8 @@ +(comment) @comment + +((call_expression + . (_) @_fnname + . "(" + . (_ [(string_content) (raw_string_content)] @regex) + . ")") + (#any-of? @_fnname "compile" "regex::compile")) diff --git a/queries/hare/locals.scm b/queries/hare/locals.scm new file mode 100644 index 000000000..62eb6665b --- /dev/null +++ b/queries/hare/locals.scm @@ -0,0 +1,47 @@ +; Scopes + +[ + (module) + (function_declaration) + (if_statement) + (for_statement) + (match_expression) + (switch_expression) +] @scope + +; References + +[ + (identifier) + (scoped_type_identifier) +] @reference + +; Definitions + +(global_binding + (identifier) @definition.constant . ":" (_)) + +(const_declaration + "const" (identifier) @definition.constant . "=") + +(field + . (identifier) @definition.field) + +(field_assignment + . (identifier) @definition.field) + +(function_declaration + "fn" . (identifier) @definition.function) + +(parameter + (_) @definition.parameter . ":") + +(type_declaration + "type" (identifier) @definition.type . "=") + +(type_declaration + "type" (identifier) @definition.enum . "=" (enum_type)) + +(let_declaration + "let" . (identifier) @definition.variable ","?) + |
