Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Nim support #295

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,12 @@
[submodule "repos/actionscript"]
path = repos/actionscript
url = https://github.com/Rileran/tree-sitter-actionscript
update = none
ignore = dirty
branch = main
jcs090218 marked this conversation as resolved.
Show resolved Hide resolved
[submodule "repos/nim"]
path = repos/nim
url = https://github.com/alaviss/tree-sitter-nim
update = none
ignore = dirty
branch = main
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
- Add `Nim` support

## 0.12.86 - 2023-12-09
- Register `qss-mode` with `CSS`
Expand Down
185 changes: 185 additions & 0 deletions queries/nim/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
; SPDX-FileCopyrightText: 2023 Leorize <[email protected]>
; 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
1 change: 1 addition & 0 deletions repos/nim
Submodule nim added at 1f9308
1 change: 1 addition & 0 deletions tree-sitter-langs.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading