Skip to content

Commit

Permalink
feat(nim): added nim support
Browse files Browse the repository at this point in the history
  • Loading branch information
aMOPel authored and lewis6991 committed Sep 23, 2023
1 parent b6c763d commit 6edf360
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Note: if you need support for Neovim 0.6.x please use the tag `compat/0.6`.
- [x] `lua`
- [x] `markdown`
- [x] `matlab`
- [x] `nim`
- [x] `nix`
- [x] `norg`
- [x] `ocaml_interface`
Expand Down
48 changes: 48 additions & 0 deletions queries/nim/context.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

; declarations
(const_section (variable_declaration) @context.end) @context
(var_section (variable_declaration) @context.end) @context
(let_section (variable_declaration) @context.end) @context
(using_section (variable_declaration) @context.end) @context

; types
(type_section (type_declaration) @context.end) @context
(object_declaration (field_declaration_list) @context.end) @context
(tuple_type . (field_declaration) @context.end) @context
(enum_declaration . (enum_field_declaration) @context.end) @context

; routines
(proc_declaration body: (statement_list) @context.end) @context
(func_declaration body: (statement_list) @context.end) @context
(method_declaration body: (statement_list) @context.end) @context
(iterator_declaration body: (statement_list) @context.end) @context
(converter_declaration body: (statement_list) @context.end) @context
(template_declaration body: (statement_list) @context.end) @context
(macro_declaration body: (statement_list) @context.end) @context

; routine expressions
(proc_expression body: (statement_list) @context.end) @context
(func_expression body: (statement_list) @context.end) @context
(iterator_expression body: (statement_list) @context.end) @context

; calls
(do_block body: (statement_list) @context.end) @context
(call (argument_list ":" (statement_list) @context.end)) @context

; single line statements
(for body: (statement_list) @context.end) @context
(while body: (statement_list) @context.end) @context
(block body: (statement_list) @context.end) @context
(static_statement body: (statement_list) @context.end) @context

; multi line statements
(try body: (statement_list) @context.end) @context
(except_branch (statement_list) @context.end) @context
(finally_branch (statement_list) @context.end) @context

(if consequence: (statement_list) @context.end) @context
(when consequence: (statement_list) @context.end) @context
(elif_branch (statement_list) @context.end) @context
(else_branch (statement_list) @context.end) @context
(case value: (_) . (_) @context.end) @context
(of_branch (statement_list) @context.end) @context
243 changes: 243 additions & 0 deletions test/test.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
const



C = 5
var



v = 5
let



l = 5
using



u: int
type



O = object of RootObj



f: int
T = tuple



f: int
E = enum



F1
F2

proc p[
T
](
a: int
):
int
{.nimcall.}
=







discard

func f() =




discard

method m(a: O) =




discard

iterator i(): int =




discard

converter c(a: int): int =




discard

template t() =




discard

macro ma(body: untyped) =




discard

let pe = proc (): int =




discard

let fe = func (): int =




discard

let ie = iterator (): int =




discard

import std/algorithm
var array1 = [3,2,1]
sort(array1) do (x, y: int) -> int:




1

ma:


ma:


ma:


ma:


ma:


discard


# Foot of Mount Doom
for x in
[0,1,2]:



while
true:



block label:



static:



try:



discard

except
ValueError as e:






discard

finally:



if
true:




discard

elif
true:



discard

else:

when
true:




discard

elif
true:




discard

else:
let en = E.F2
case en:
of
F1:



discard

elif
true:



discard

else:



echo "You have climbed Mount Doom!"

0 comments on commit 6edf360

Please sign in to comment.