### When Statement Example Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates a basic 'when' statement with a consequence. ```nim when condition: (identifier) consequence: (statement_list (call function: (identifier) (argument_list (identifier)))) ``` -------------------------------- ### Generalized Strings in Nim Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Shows examples of generalized strings in Nim, which allow for custom string interpolation or processing. ```nim foo"very raw C:\\Windows\\System32" ``` ```nim foobar""""extra spicy"""" ``` -------------------------------- ### Nim Import From Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Provides examples of importing specific symbols from a module in Nim, including qualified module names. ```nim from system import seq, echo ``` ```nim from X import Y ``` ```nim from X/Y import Y ``` -------------------------------- ### Nim 'let' Declaration Examples Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Shows different ways to declare variables using 'let' in Nim, including tuple assignment, type annotations, and unicode identifiers. ```nim let foo, dar = 0d ``` ```nim lET bar: float = 10f32 ``` ```nim l_e_t a, c, d = 10 b: uint32 = 42 (e, f) = (1, 2) ``` ```nim let 😂 = fun ``` -------------------------------- ### Nim 'const' Declaration Examples Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Illustrates various ways to declare constants in Nim, including single values, multiple values, typed constants, and tuple deconstruction. ```nim const Foo = 0 ``` ```nim coNs_T Bar: int = 10 ``` ```nim const A = 10 B: uint32 = 42 ``` ```nim const (X, Y) = (1, 2) ``` ```nim const Z = 10 (D, E, F) = (3, 4, 5) ``` ```nim const (X, Y*) = (1, 2) ``` ```nim const foo, bar*, whatever = 10 ``` ```nim const Test* {.importc: "TEST"}.: int ``` -------------------------------- ### Nim Raise Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Provides examples of raise statements in Nim, used for signaling exceptions. Can be used with or without an expression. ```nim raise exp ``` ```nim raise ``` -------------------------------- ### Nim Empty Type Declarations Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Shows examples of empty type declarations in Nim, including one with a magic attribute. ```nim type X Y Z {.magic: "Int".} ``` -------------------------------- ### Nim Yield Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Examples of Nim's yield statement, used in generators to produce values. ```nim yield ``` ```nim yield none ``` -------------------------------- ### Nim Generalized String with Block Comment Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/deviations.txt Example of a generalized string in Nim that includes an identifier and a block comment. Generalized strings allow for more complex content. ```nim a#[]#"b" ``` -------------------------------- ### Set/Table Construction in Nim Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates the syntax for creating sets and tables (dictionaries) in Nim. ```nim {a: b, c: d} ``` ```nim {a, b, c, d} ``` ```nim {} ``` ```nim {:} ``` ```nim {a: when c: d} ``` ```nim block: {a, b, c, d} ``` -------------------------------- ### Nim 'using' Declaration Syntax Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Demonstrates the syntax for 'using' declarations in Nim, which can be used to introduce variables with specific types. ```nim using c: int n: int counter: int ``` ```nim using c: int ``` -------------------------------- ### Nim Array Construction Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates various ways to construct arrays in Nim, including empty arrays, arrays with elements, and key-value pairs. ```nim [] ``` ```nim [[a]] ``` ```nim ([a, b, c]) ``` ```nim ([x, y, z, 10, 100]) ``` ```nim ([a = b, c: d]) ``` -------------------------------- ### Array Construction in Nim Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates different ways to construct arrays in Nim, including empty arrays and arrays with various elements. ```nim [c: if c: d] ``` ```nim block: [a, b, c, d] ``` ```nim [a, b, c, d, 1, 2] ``` ```nim [a: b, c: d] ``` ```nim [] ``` ```nim [:] ``` ```nim [a: when c: d] ``` ```nim block: [a, b, c, d] ``` -------------------------------- ### Old Typeof Expressions in Nim Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Provides examples of the older `type` keyword syntax for type introspection, now largely superseded by `typeof`. ```nim proc foo(x: type y) var x: type y (type y) ``` ```nim type(x) ``` ```nim type (y) ``` ```nim type(x) is Y ``` ```nim type(x) + y * z ``` ```nim type(x) * y - y ``` ```nim type(x) + y + z ``` -------------------------------- ### Nim For Loops Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Demonstrates various forms of for loops in Nim, including iteration over sequences, pairs, tuples, and with pragmas. ```nim for x in s: 100 ``` ```nim for x, y in pairs(x): 42u32 ``` ```nim for (x, y), w, z in whatever: for foo, bar in s: 0x42f ``` ```nim for _, v {.tag.} in c.pairs: discard ``` -------------------------------- ### Nim Pragma Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates various Nim pragma statements, including those with arguments and nested pragmas. ```nim (source_file (pragma_statement (pragma_list (colon_expression left: (identifier) right: (call function: (identifier) (argument_list)))) body: (statement_list (call function: (identifier) (argument_list (identifier))))) ``` ```nim (pragma_statement (pragma_list (identifier)) body: (statement_list (identifier))) ``` ```nim (pragma_statement (pragma_list (identifier))) ``` ```nim (pragma_statement (pragma_list (cast value: (identifier)))) ``` ```nim (pragma_statement (pragma_list (colon_expression left: (identifier) right: (when condition: (identifier) consequence: (statement_list (call function: (identifier) (argument_list)))))))) ``` -------------------------------- ### Nim Continue Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Shows how to use continue statements in Nim to skip the rest of the current loop iteration and proceed to the next. ```nim con_tiNue ``` ```nim continue blck ``` -------------------------------- ### Nim Function Call with Argument List Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates a basic Nim function call with an argument list. This is a fundamental building block for many Nim programs. ```nim (call function: (identifier) (argument_list)) ``` -------------------------------- ### Nim Procedure Declaration Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Demonstrates the structure of a Nim procedure declaration with parameters and a type expression. ```nim proc example(param: int) ``` -------------------------------- ### Nim Method Declaration with Base Pragma Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Defines a method 'exists' for the 'RootObj' type. The '.base.' pragma indicates it's a base method. It prints a string to the console. ```nim method exists(x: RootObj) {.base.} = echo "doesn't" ``` -------------------------------- ### Cast Expressions in Nim Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates how to perform type casting in Nim using the `cast` keyword. ```nim cast[int](x) ``` ```nim cast(noSideEffect) ``` ```nim cast(raises: []) ``` -------------------------------- ### Nim Try Statement with Short Syntax and Finally Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates the concise syntax for Nim try statements with both except and finally blocks. ```nim try: echo x except: echo y finally: bar ``` -------------------------------- ### Nim Assembly Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Demonstrates the syntax for assembly statements in Nim, supporting both long string literals and interpreted string literals. ```nim asm """ mov ret """ ``` ```nim asm "ret" ``` -------------------------------- ### Nim Tuple, Array, and Set Literals Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates the syntax for Nim tuple, array, and set literals. These are fundamental data structures for grouping and collections. ```nim foo (x,) ``` ```nim foo [x] ``` ```nim foo {x} ``` -------------------------------- ### Nim Type Alias Syntax Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Shows how to define type aliases in Nim, including simple aliases, distinct types, and generic type aliases. Supports generic parameters. ```nim type X = int type Y = distinct int A[T] = ref T ``` -------------------------------- ### Nim Function Call with Do Block, Pragmas, and Parameters Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates a Nim function call with a 'do' block that includes parameters, a return type, pragmas, and a body. This is for advanced function definitions with specific compiler directives. ```nim (call function: (identifier) (argument_list (do_block parameters: (parameter_declaration_list (parameter_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) type: (type_expression (identifier)))) return_type: (type_expression (identifier)) pragmas: (pragma_list (identifier)) body: (statement_list (infix_expression left: (identifier) operator: (operator) right: (identifier)))))) ``` -------------------------------- ### Nim Object Declaration Syntax Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Illustrates the declaration of object types in Nim, including generic objects with fields and objects with cases (variants). ```nim type SeqData[T] = object capacity: int buffer: UncheckedArray[T] NimNodeObj = object case kind: NimNodeKind of nnkError: discard ``` -------------------------------- ### Nim Import Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Shows different ways to import modules in Nim, including importing all symbols, specific symbols, and excluding symbols. ```nim import X ``` ```nim import Y, Z, J ``` ```nim import K except F ``` -------------------------------- ### Nim Function Call with Colon, Do Block, and Else (Alternative Syntax) Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates an alternative syntax for Nim function calls with a colon parameter, 'do' block, and 'else' clause. This highlights syntactic variations for similar logic. ```nim foo x do: y else: foo ``` -------------------------------- ### Macro Declaration Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Macro declaration with a name, parameters, return type, and body. ```APIDOC ## MACRO DECLARATION ### Description Declares a macro with a name, parameters, a return type, and a body. Macros operate on the abstract syntax tree (AST) and are expanded at compile time. ### Method N/A (Declaration) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Nim Function Call with Multiple Arguments Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates a Nim function call with a mix of identifiers, string literals, and nested function calls. Demonstrates flexible argument passing. ```nim foo x, y, "string", w(call(some other)) ``` -------------------------------- ### Nim Try Statement with Short Syntax Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Shows the concise syntax for Nim try statements with an except block. ```nim try: echo x except: echo y ``` -------------------------------- ### Nim Return Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Demonstrates Nim's return statements, used to exit a procedure and optionally return a value. ```nim return ``` ```nim return X ``` -------------------------------- ### Nim Dot Generic Calls Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates Nim's dot generic call syntax, used for calling methods or functions with generic type parameters. ```nim x.parseEnum[:T] ``` ```nim x.parseEnum[:T](x, y) ``` ```nim x.foo[:T, U, V]: x ``` ```nim (dot_generic_call first_argument: (identifier) function: (identifier) generic_arguments: (generic_argument_list (identifier))) ``` ```nim (dot_generic_call first_argument: (identifier) function: (identifier) generic_arguments: (generic_argument_list (identifier)) (argument_list (identifier) (identifier))) ``` ```nim (call first_argument: (identifier) function: (identifier) generic_arguments: (generic_argument_list (identifier) (identifier) (identifier)) (argument_list (statement_list (identifier)))) ``` -------------------------------- ### Nim Function Calls Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates different forms of function calls in Nim, including those with simple arguments, argument lists, and nested structures like 'of_branch' and 'do_block'. ```nim (call function: (identifier) (argument_list (identifier))))))) ``` ```nim (call function: (identifier) (argument_list (statement_list (call function: (identifier) (argument_list (identifier) (identifier) (statement_list (call function: (identifier) (argument_list (identifier)))) (of_branch values: (expression_list (identifier) (identifier)) consequence: (statement_list (identifier)))))))) ``` ```nim (call function: (identifier) (argument_list (interpreted_string_literal (string_content)))) ``` ```nim (call function: (identifier) (argument_list (long_string_literal (string_content)))) ``` ```nim (call function: (identifier) (argument_list (identifier) (identifier) (identifier) (statement_list (identifier)) (do_block body: (statement_list (identifier))))) ``` ```nim (call function: (identifier) (argument_list (identifier) (statement_list (identifier)))) ``` ```nim (call function: (identifier) (argument_list (identifier) (statement_list (identifier)) (else_branch consequence: (statement_list (identifier))))) ``` ```nim (call function: (identifier) (argument_list (call function: (identifier) (argument_list (do_block body: (statement_list (identifier))) (else_branch consequence: (statement_list (identifier))))))) ``` ```nim (call function: (identifier) (argument_list (infix_expression left: (integer_literal) operator: (operator) right: (call function: (identifier) (argument_list))) (identifier))) ``` ```nim (call function: (identifier) (argument_list (tuple_construction (identifier)))) ``` ```nim (call function: (identifier) (argument_list (array_construction (identifier)))) ``` ```nim (call function: (identifier) (argument_list (curly_construction (identifier))))) ``` -------------------------------- ### Nim Integer Literals Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/literals.txt Demonstrates various ways to define integer literals in Nim, including decimal, hexadecimal, octal, binary, with underscores for readability, and with explicit type suffixes. ```nim 1234 ``` ```nim 1234u ``` ```nim -1234U ``` ```nim 1234'i32 ``` ```nim 1234u16 ``` ```nim 12_345_67 ``` ```nim 12_345_67I32 ``` ```nim -12_345_67'I8 ``` ```nim -0xABCDEF ``` ```nim 0xABCDEFi16 ``` ```nim -0xab_cd_ef ``` ```nim 0xab_cd_efu32 ``` ```nim -0o7050 ``` ```nim 0o7050'u16 ``` ```nim -0o70_50 ``` ```nim 0o70_50'u8 ``` ```nim -0b11011 ``` ```nim 0b11011U8 ``` ```nim 0b1_10_11 ``` ```nim -0b11_011U16 ``` -------------------------------- ### Nim Export Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Demonstrates how to export symbols from a module in Nim, with options to export specific symbols or exclude others. ```nim export X, Y ``` ```nim export foo ``` ```nim export bar except bar ``` -------------------------------- ### Tuple Construction in Nim Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Shows various ways to construct tuples in Nim, including empty tuples, tuples with named and unnamed elements, and trailing commas. ```nim (20, 42) ``` ```nim (0x2f, 0o755f) ``` ```nim (20,) ``` ```nim (x: 1, 2,) ``` ```nim (a: "string") ``` ```nim block: (a: "string", b: 42) ``` -------------------------------- ### Nim Case Statement with Multiple Values Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates a Nim case statement matching against multiple integer values. ```nim case x of 1, 2, 3: echo true echo false 10 of 2: 10f32 ``` -------------------------------- ### Template with Block Parameters Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Template declaration with block parameters. ```APIDOC ## TEMPLATE DECLARATION WITH BLOCK PARAMETERS ### Description Declares a template that accepts block parameters, allowing for more complex code structures to be passed as arguments. ### Method N/A (Declaration) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### When Statement with Else Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Shows a 'when' statement that includes an 'else' branch. ```nim when condition: (identifier) consequence: (statement_list (call function: (identifier) (argument_list (identifier)))) alternative: (else_branch consequence: (statement_list (integer_literal))) ``` -------------------------------- ### Nim Include Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Shows how to include other files or string literals in Nim code. This is often used for configuration or embedding code. ```nim include stuff, "foo.txt" ``` ```nim include X ``` -------------------------------- ### Nim Routine Expressions Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates Nim syntax for procedure and iterator types and expressions, including parameters, pragmas, and yield statements. ```nim (proc_type parameters: (parameter_declaration_list (parameter_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) type: (type_expression (identifier))) (parameter_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) type: (type_expression (identifier)))))) ``` ```nim (proc_expression parameters: (parameter_declaration_list (parameter_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) type: (type_expression (identifier)))) pragmas: (pragma_list (identifier)) body: (statement_list (infix_expression left: (identifier) operator: (operator) right: (integer_literal)))) ``` ```nim (iterator_expression parameters: (parameter_declaration_list (parameter_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) type: (type_expression (identifier)))) body: (statement_list (for left: (symbol_declaration_list (symbol_declaration name: (identifier))) right: (identifier) body: (statement_list (yield_statement (identifier)))))) ``` ```nim (proc_type) ``` ```nim (iterator_type return_type: (type_expression (identifier)))) ``` -------------------------------- ### Method Declaration Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Method declaration with a name, parameters (including the receiver), pragmas, and body. ```APIDOC ## METHOD DECLARATION ### Description Declares a method associated with a specific type. It includes the receiver type, name, parameters, optional pragmas, and a body. ### Method N/A (Declaration) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Nim Function Call with Do Block and Parameters Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates a Nim function call that includes a 'do' block with parameters, a return type, and a body. This is used for closures or lambda-like constructs. ```nim (call function: (identifier) (argument_list (do_block parameters: (parameter_declaration_list (parameter_declaration (symbol_declaration_list (symbol_declaration name: (identifier)) (symbol_declaration name: (identifier))) type: (type_expression (identifier)))) return_type: (type_expression (identifier)) body: (statement_list (infix_expression left: (identifier) operator: (operator) right: (identifier)))))) ``` -------------------------------- ### Nim Try-Except-Finally Structure Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates the Nim syntax for try-except-finally blocks, including nested structures. ```nim (try body: (statement_list (call function: (identifier) (argument_list (identifier)))) (except_branch consequence: (statement_list (call function: (identifier) (argument_list (identifier)))))) (try body: (statement_list (call function: (identifier) (argument_list (identifier)))) (except_branch consequence: (statement_list (call function: (identifier) (argument_list (identifier))))) ``` ```nim (try body: (statement_list (call function: (identifier) (argument_list (identifier)))) (finally_branch body: (statement_list (call function: (identifier) (argument_list (identifier)))))) ``` -------------------------------- ### Nim Template with Rewrite Pattern Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Defines a template 'optMul' that rewrites multiplication by 2 into addition. It takes an integer parameter and returns an integer. The rewrite pattern specifies the transformation. ```nim template optMul{`*`(a, 2)}(a: int): int = a+a ``` -------------------------------- ### Procedure with Importc Pragma Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Procedure declaration with a pragma for C import. ```APIDOC ## PROC DECLARATION WITH PRAGMA ### Description Declares a procedure that is imported from C using the `importc` pragma. ### Method N/A (Declaration) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Parenthesized Expressions in Nim Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates the use of parentheses for grouping expressions or overriding precedence in Nim. ```nim (10) ``` ```nim ("string") ``` ```nim (discard; 1;) ``` ```nim block: ("may extend outside of indent", expr) ``` -------------------------------- ### Const Declaration with When Statement Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Demonstrates a constant declaration using a 'when' statement with 'elif' and 'else' branches. ```nim const_section (variable_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) value: (when condition: (identifier) consequence: (statement_list (integer_literal)) alternative: (elif_branch condition: (identifier) consequence: (statement_list (interpreted_string_literal (string_content)))) alternative: (else_branch consequence: (statement_list (integer_literal)))) ``` -------------------------------- ### Nim Dot Expression Syntax Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates dot expressions used for member access and method calls, including variations with identifiers, strings, and parenthesized calls. ```nim (source_file (infix_expression left: (identifier) operator: (operator) right: (dot_expression left: (identifier) right: (identifier))) ``` ```nim (infix_expression left: (dot_expression left: (identifier) right: (identifier)) operator: (operator) right: (dot_expression left: (identifier) right: (identifier))) ``` ```nim (prefix_expression operator: (operator) (dot_expression left: (identifier) right: (identifier))) ``` ```nim (generalized_string function: (dot_expression left: (identifier) right: (identifier)) (string_content)) ``` ```nim (call function: (dot_expression left: (identifier) right: (identifier)) (argument_list (interpreted_string_literal (string_content)))) ``` ```nim (dot_expression left: (call function: (identifier) (argument_list (identifier))) right: (identifier))) ``` -------------------------------- ### Nim Procedure Declaration with Documentation Comment Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Defines a procedure 'bar' with a documentation comment. The comment provides information about the procedure. The body is empty. ```nim proc bar = ## comment ``` -------------------------------- ### Nim Case Statement with Simple Branches Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt A basic Nim case statement with two simple branches. ```nim case y of true: 1 of false: 2 ``` -------------------------------- ### Nim Case Statement with Boolean and Elif Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates a Nim case statement with a boolean condition and an elif clause. ```nim case x of true: stuff elif this: bar 10 else: echo "" ``` -------------------------------- ### Procedure with Documentation Comment Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Procedure declaration with a documentation comment. ```APIDOC ## PROC DECLARATION WITH DOC COMMENT ### Description Declares a procedure that includes a documentation comment, providing information about its purpose and usage. ### Method N/A (Declaration) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Nim Bind Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Illustrates the bind statement in Nim, used for variable binding. Supports multiple variables or a single variable. ```nim bind x, y, z ``` ```nim bind foo ``` ```nim bind foo.bar ``` -------------------------------- ### Nim Procedure with Generic Parameters Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Shows a Nim procedure declaration that includes generic parameters and an empty body. ```nim proc example[T]() ``` -------------------------------- ### Nim Float Literals Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/literals.txt Illustrates Nim's float literal syntax, including decimal points, underscores for readability, scientific notation (e), and explicit type suffixes (f, d, f32, f64). ```nim 12.32 ``` ```nim -12_34.567_89 ``` ```nim 12_34e10 ``` ```nim -12_34e+123_340 ``` ```nim 12_34e-1_120 ``` ```nim -1234.5678e10 ``` ```nim 12_34.56_78e-10 ``` ```nim 12.34F ``` ```nim -12.34d ``` ```nim 12.34f32 ``` ```nim 12.34f64 ``` ```nim 1234f ``` ```nim -1234d ``` ```nim 1234'F32 ``` ```nim 1234'F64 ``` ```nim -12_34.567_89'D ``` ```nim -12_34.567_89e+123'D ``` -------------------------------- ### Nim Type Expressions Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Shows different Nim type expression syntaxes, including references, distinct types, pointers, tuples, and arrays. ```nim (source_file (ref_type (type_expression (identifier))) ``` ```nim (distinct_type (type_expression (identifier))) ``` ```nim (pointer_type (type_expression (pointer_type (type_expression (identifier))))) ``` ```nim (tuple_construction (var_type (type_expression (identifier))) (var_type (type_expression (identifier)))) ``` ```nim (tuple_type (field_declaration_list))) ``` -------------------------------- ### Nested When Statement Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates a 'when' statement nested within another 'when' statement, including an 'elif' branch. ```nim when condition: (identifier) consequence: (statement_list (when condition: (identifier) consequence: (statement_list (interpreted_string_literal (string_content))) alternative: (elif_branch condition: (identifier) consequence: (statement_list (if condition: (identifier) consequence: (statement_list (call function: (identifier) (argument_list (identifier))))) ``` -------------------------------- ### Nim Template Declaration with Rewrite Pattern Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Illustrates a Nim template declaration with a simple rewrite pattern involving an infix expression. ```nim template example: expr = a + 1 ``` -------------------------------- ### Nim Generalized String with Dot Expression and Block Comment Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/deviations.txt Demonstrates a generalized string in Nim involving a dot expression (field access or method call) and a block comment. This highlights parsing of expressions within generalized strings. ```nim a.b #[]#"c" ``` -------------------------------- ### Nim Variable Declaration Syntax Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Demonstrates various ways to declare variables in Nim, including type inference, explicit typing, and tuple deconstruction. Supports exported variables with '*'. ```nim var foo = 0d vaR bar: float = 10f32 v_a_r a = 10 b: uint32 = 42 var x, y: int var z, w: float var (c, d) = (2, 3) var (x, ) = (1, ) var x*:int var y *: float ``` -------------------------------- ### Nim Static Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Demonstrates Nim's static statement, which allows code to be executed at compile time. Supports single statements or blocks. ```nim static: echo y ``` ```nim static: doX() doY() assert y, "foo" ``` -------------------------------- ### Procedure Declaration Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Standard procedure declaration with name, parameters, return type, and body. ```APIDOC ## PROC DECLARATION ### Description Declares a procedure with a name, optional parameters, an optional return type, and a body. ### Method N/A (Declaration) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Nim While Loops Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Illustrates nested while loops in Nim. The condition can be any boolean expression. ```nim while true: while false: nothing ``` -------------------------------- ### Nim Function Call with Statement List and Do Block (Conditional) Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates a Nim function call with a statement list and a 'do' block, followed by an 'else' clause. This represents conditional execution logic. ```nim foo x, y, z: x do: y ``` -------------------------------- ### Nim Source File with Complex Function Calls Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Shows a Nim source file containing complex function calls with nested structures, including other function calls and interpreted string literals. This demonstrates intricate call patterns. ```nim (call function: (identifier) (argument_list (call function: (identifier) (argument_list (identifier) (identifier) (interpreted_string_literal (string_content)) (call function: (identifier) (argument_list (call function: (identifier) (argument_list (call function: (identifier) (argument_list (identifier))))))))))) ``` -------------------------------- ### Nim Function Call with Equality Expressions Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates a Nim function call with multiple equality expressions in its argument list, including a nested 'if' statement. Useful for conditional arguments or complex comparisons. ```nim (call function: (identifier) (argument_list (equal_expression left: (identifier) right: (identifier)) (equal_expression left: (identifier) right: (if condition: (identifier) consequence: (statement_list (identifier)))) (identifier))) ``` -------------------------------- ### Parse Nim Prefix Expressions Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates the parsing of Nim prefix expressions, including unary operators like $, -, %, @, not, !, and operators used with dot notation. ```nim $a ``` ```nim -b ``` ```nim %*c ``` ```nim $a.b ``` ```nim @a.b ``` ```nim @(a.b) ``` ```nim not a.c ``` ```nim !a.u:b ``` ```nim echo $a ``` ```nim *:bar ``` ```nim ±10 ``` -------------------------------- ### Nim Assignment with Function Call Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Demonstrates a Nim assignment where the value is the result of a function call with arguments. ```nim (assignment (identifier) (call (dot_expression (identifier) (identifier)) (argument_list (proc_expression (statement_list (identifier))))))) ``` -------------------------------- ### Nim Break Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/statements.txt Illustrates the usage of break statements in Nim, which can be used to exit loops or blocks. ```nim bRe_ak ``` ```nim break blck ``` -------------------------------- ### Nim String Literals Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/literals.txt Covers Nim's string literal syntax, including empty, regular, raw strings, strings with escapes, and multiline strings using triple quotes. Raw strings do not interpret escape sequences. ```nim "" ``` ```nim r"" ``` ```nim "regular" ``` ```nim "string" ``` ```nim "string\n\n\r" ``` ```nim "a 'long\'\" string \x00 \uBEEF \u{DEADBEEF}" ``` ```nim r"raw string" ``` ```nim r"C:\Windows\System32" ``` ```nim r"C:\""Windows""\System32" ``` ```nim r"a""b" ``` ```nim r"a""" ``` ```nim """""" ``` ```nim """"""" ``` ```nim """ Mutiline long string \escapes\are \not\interpreted "strings within even" """""" ``` ```nim r""""string inside long string"""" ``` ```nim block: """ Can start at lower indentation """ ``` ```nim "# not a comment" ``` ```nim """# not a comment""" ``` ```nim r"C:\" ``` -------------------------------- ### Nim Procedure Declaration with Return Type and Body Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Defines a procedure named 'foo' that returns an integer and has a discard statement in its body. Used for basic procedure definition. ```nim proc foo(): int = discard ``` -------------------------------- ### Template Declaration Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Template declaration with a rewrite pattern, parameters, return type, and body. ```APIDOC ## TEMPLATE DECLARATION ### Description Declares a template with a name, a rewrite pattern, parameters, an optional return type, and a body. Templates are expanded at compile time. ### Method N/A (Declaration) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Nim Block Comments Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/extras.txt Use '#[' and ']#', or '##[' and ']##' for documentation comments, to create block comments. These comments can span multiple lines and can be nested. ```nim #[ something ]# ``` ```nim echo x, #[comment]# y ``` ```nim #[multi-line comments can be #[nested #[multiple times]#]#]# ``` ```nim #[random inner comments# stuff#]# ``` ```nim ##[Block doc can be #[nested]# too Block doc is not ##[self-nesting]#, though ]## ``` -------------------------------- ### Nim Command Call with Arguments Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Represents a command-line call in Nim, similar to shell commands, with arguments including integers and string literals. Used for executing external commands or scripts. ```nim echo optarg 1, " ", singlearg 2 ``` -------------------------------- ### Nim Enum Declaration (Line and Comma) Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Demonstrates a Nim enum 'LineAndComma' with fields on separate lines and one assigned a string value. ```nim type LineAndComma = enum X, Y, D = "X" ``` -------------------------------- ### Nim Block Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Shows various ways to use block statements in Nim, including anonymous blocks, named blocks, and blocks used in variable assignments. ```nim block: 10u32 ``` ```nim block named: echo foo; echo bar ``` ```nim block: let x = 10 foo(10) ``` ```nim let y = block: 100 ``` ```nim (block body: (statement_list (integer_literal))) ``` ```nim (block label: (identifier) body: (statement_list (call function: (identifier) (argument_list (identifier))) (call function: (identifier) (argument_list (identifier))))) ``` ```nim (block body: (statement_list (let_section (variable_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) value: (integer_literal))) (call function: (identifier) (argument_list (integer_literal))))) ``` ```nim (let_section (variable_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) value: (block body: (statement_list (integer_literal)))))) ``` -------------------------------- ### Nim If Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Covers the syntax and structure of if, elif, and else statements in Nim, including nested conditionals and expressions within statements. ```nim if true: echo foo ``` ```nim if false: echo bar ``` ```nim if x: if y: "string" elif z: 10u32 something bar else: 10 ``` ```nim let x = if true: 10 elif something: "string" else: 100 ``` ```nim block: var x = if true: 10 else: 1f ``` ```nim if true: expr1 else: expr2 ``` ```nim if true: foo else: bar ``` ```nim if true: proc foo = discard else: bar ``` -------------------------------- ### Nim Function Call with Nested Statements Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates a Nim function call containing a statement list with nested function calls. Useful for complex operations and chained logic. ```nim (call function: (identifier) (argument_list (statement_list (call function: (identifier) (argument_list)) (call function: (identifier) (argument_list)))))) ``` -------------------------------- ### Nim Try Statement with Multiple Excepts and Finally Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Illustrates a Nim try statement with multiple except blocks and a finally clause. ```nim try: echo "x" echo "y" except A: echo b except B, C: echo c finally: echo d ``` -------------------------------- ### When Statement with Expression Branches Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt A 'when' statement where both the consequence and alternative branches are expressions. ```nim when true: expr1 else: expr2 ``` -------------------------------- ### Tree-sitter Nim Grammar - Let Section Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Represents the structure of a 'let' section in Nim code, including variable declarations with inferred or explicit types, and tuple deconstruction. ```tree-sitter-nim (let_section (variable_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) value: (integer_literal)) (variable_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) type: (type_expression (identifier)) value: (integer_literal)) (variable_declaration (symbol_declaration_list (tuple_deconstruct_declaration (symbol_declaration name: (identifier)) (symbol_declaration name: (identifier)))) value: (tuple_construction (integer_literal) (integer_literal)))) (let_section (variable_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) value: (identifier)))) ``` -------------------------------- ### Nim AST Node Case Analysis Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Analyzes different Nim AST node types (nnkNone, nnkEmpty, nnkNilLit, literal types, string literals, comments, identifiers, symbols) and their corresponding data fields (intVal, floatVal, strVal, sons). ```nim of nnkNone, nnkEmpty, nnkNilLit: nil of nnkCharLit..nnkUInt64Lit: intVal: BiggestInt of nnkFloatLit..nnkFloat64Lit: floatVal: BiggestFloat of nnkStrLit..nnkTripleStrLit, nnkCommentStmt, nnkIdent, nnkSym: strVal: string else: sons: seq[NimNode] ``` -------------------------------- ### Nim Object with Unfinished Case Statement Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/declarations.txt Illustrates an unfinished Nim object definition with a conditional field and an incomplete case statement. ```nim Unfinished = object when x: case foo: bar of a: string ``` -------------------------------- ### Parse Nim Infix Expressions Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Shows Nim's infix expression parsing, covering arithmetic, logical, and custom operators, including operator precedence and associativity. ```nim 1 + 100 ``` ```nim a and b ``` ```nim 1 * 100 - 10 / 2 ``` ```nim abc %*% bcd ``` ```nim 1 ^/ 2 ^/ 3 ``` ```nim a => b + c ``` ```nim z ==> xyz + def => cd ``` ```nim $a + b ``` ```nim 1 * 2 and 3 * 1 or false ``` ```nim (1 + 2) * (2 + 3) ``` ```nim a += c >= b ``` ```nim c of RootObj ``` ```nim 1 - x 1 - x ``` ```nim 1 + 1: 3 else: 4 ``` ```nim 1+1 ``` ```nim 1+ 1 ``` ```nim 1 * 2 ⊛ 4 ∨ 5 ``` -------------------------------- ### Nim Command Call with Function Call Argument Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Shows a command-line call in Nim that includes a function call as an argument. This is used for dynamic argument generation or command composition. ```nim echo 1 - foo(), foo ``` -------------------------------- ### Nim Try Statement with Single Except Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Basic Nim try statement with a single except block. ```nim try: echo "x" echo "y" except A: echo b ``` -------------------------------- ### Block with Var Declaration and If-Else Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt A block containing a var declaration with an if-else structure. ```nim block body: (statement_list (var_section (variable_declaration (symbol_declaration_list (symbol_declaration name: (identifier))) value: (if condition: (identifier) consequence: (statement_list (integer_literal)) alternative: (else_branch consequence: (statement_list (float_literal))))))) ``` -------------------------------- ### Nim Bracket Expression Syntax Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt Shows bracket expressions used for array indexing or similar access patterns, combined with dot expressions and infix operations. ```nim (source_file (bracket_expression left: (dot_expression left: (identifier) right: (identifier)) right: (argument_list (identifier))) ``` ```nim (infix_expression left: (integer_literal) operator: (operator) right: (bracket_expression left: (identifier) right: (argument_list (identifier))))) ``` -------------------------------- ### Basic If Statement Source: https://github.com/alaviss/tree-sitter-nim/blob/main/test/corpus/expressions.txt A simple if statement with a consequence block. ```nim if condition: (identifier) consequence: (statement_list (call function: (identifier) (argument_list (identifier)))) ```