diff --git a/.gitmodules b/.gitmodules index 4878ff0c..ffab25c6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -564,3 +564,9 @@ update = none ignore = dirty branch = main +[submodule "repos/nim"] + path = repos/nim + url = https://github.com/alaviss/tree-sitter-nim + update = none + ignore = dirty + branch = main diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e2ed67d..afc9e1b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +- Add `Nim` support ## 0.12.86 - 2023-12-09 - Register `qss-mode` with `CSS` diff --git a/queries/nim/highlights.scm b/queries/nim/highlights.scm new file mode 100644 index 00000000..e309dfc1 --- /dev/null +++ b/queries/nim/highlights.scm @@ -0,0 +1,185 @@ +; SPDX-FileCopyrightText: 2023 Leorize +; SPDX-License-Identifier: MPL-2.0 + +; Punctuations +[ "." ";" "," ":" ] @punctuation.delimiter +[ "(" ")" "[" "]" "{" "}" "{." ".}" ] @punctuation.bracket + +; Special +(blank_identifier) @variable.builtin + +; Calls +(call + function: [ + (identifier) @function.call + (dot_expression + right: (identifier) @function.call) + ]) +(generalized_string + function: [ + (identifier) @function.call + (dot_expression + right: (identifier) @function.call) + ]) + +; Declarations +(exported_symbol "*" @type.qualifier) +(_ "=" @punctuation.delimiter [body: (_) value: (_)]) +(proc_declaration name: (_) @function) +(func_declaration name: (_) @function) +(converter_declaration name: (_) @function) +(method_declaration name: (_) @method) +(template_declaration name: (_) @function.macro) +(macro_declaration name: (_) @function.macro) +(parameter_declaration + (symbol_declaration_list + (symbol_declaration name: (_) @parameter))) +(symbol_declaration name: (_) @variable) +(_ + [ + type: [ + (type_expression (identifier)) + (type_expression (accent_quoted (identifier))) + ] @type + return_type: [ + (type_expression (identifier)) + (type_expression (accent_quoted (identifier))) + ] @type + ]) + +; Exceptions +[ + "try" + "except" + "finally" + "raise" +] @exception + +(except_branch values: (expression_list + [ + (identifier) @type + (infix_expression + left: (identifier) @type + operator: "as" + right: (identifier) @variable) + ])) + +; Expressions +(dot_expression + right: (identifier) @field) + +; Literal/comments +[ + (comment) + (block_comment) +] @comment + +[ + (documentation_comment) + (block_documentation_comment) +] @comment.documentation + +(interpreted_string_literal) @string +(long_string_literal) @string +(raw_string_literal) @string +(generalized_string) @string +(char_literal) @character +(escape_sequence) @string.escape +(integer_literal) @number +(float_literal) @float +(custom_numeric_literal) @number +(nil_literal) @constant.builtin + +; Keyword +[ + "if" + "when" + "case" + "elif" + "else" +] @conditional + +(of_branch "of" @conditional) + +[ + "import" + "include" + "export" +] @include + +(import_from_statement "from" @include) +(except_clause "except" @include) + +[ + "for" + "while" + "continue" + "break" +] @repeat + +(for "in" @repeat) + +[ + "macro" + "template" + "const" + "let" + "var" + "asm" + "bind" + "block" + "concept" + "defer" + "discard" + "distinct" + "do" + "enum" + "mixin" + "nil" + "object" + "out" + "ptr" + "ref" + "static" + "tuple" + "type" +] @keyword + +[ + "proc" + "func" + "method" + "converter" + "iterator" +] @keyword.function + +[ + "and" + "or" + "xor" + "not" + "div" + "mod" + "shl" + "shr" + "from" + "as" + "of" + "in" + "notin" + "is" + "isnot" + "cast" +] @keyword.operator + +[ + "return" + "yield" +] @keyword.return + +; Operators +(infix_expression operator: _ @operator) +(prefix_expression operator: _ @operator) +[ + "=" +] @operator diff --git a/repos/nim b/repos/nim new file mode 160000 index 00000000..1f9308c9 --- /dev/null +++ b/repos/nim @@ -0,0 +1 @@ +Subproject commit 1f9308c9e440ddbc67c0aaeb9396c992d266b281 diff --git a/tree-sitter-langs.el b/tree-sitter-langs.el index cbde2f6b..ae745550 100644 --- a/tree-sitter-langs.el +++ b/tree-sitter-langs.el @@ -175,6 +175,7 @@ See `tree-sitter-langs-repos'." (matlab-mode . matlab) (mermaid-mode . mermaid) (meson-mode . meson) + (nim-mode . nim) (noir-mode . noir) (ocaml-mode . ocaml) (org-mode . org)