mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-18 03:10:04 -04:00
feat(nim): added nim parser and queries (#5556)
* feat(nim): added nim parser and queries * correct scanner.cc to scanner.c Co-authored-by: Christian Clason <c.clason@uni-graz.at> * fix(nim): corrected capture for @function.macro * feat(nim highlights): added @field capture for discriminator field in object variant * bumped parser version, adapted highlights.scm and condensed injections.scm * improved nim_format_string highlights.scm * bump nim parser version again * removed overlap between queries for generalized strings in injections.scm * improved formattin] in nim_format_string/injections.scm Co-authored-by: ObserverOfTime <chronobserver@disroot.org> * corrected asm parser name in injections.scm Co-authored-by: ObserverOfTime <chronobserver@disroot.org> * improved formatting in highlights.scm Co-authored-by: ObserverOfTime <chronobserver@disroot.org> * removed @error capture from highlights.scm Co-authored-by: ObserverOfTime <chronobserver@disroot.org> * improved wording in comment in highlights.scm Co-authored-by: ObserverOfTime <chronobserver@disroot.org> * removed priority from (dot_expression left: @none) capture, since it's at the end of the file anyways * removed comments listing unused captures * reverted @error capture in nim_format_string/highlights.scm back to @none * condensed string alternatives in injections.scm Co-authored-by: ObserverOfTime <chronobserver@disroot.org> * condensed string alternatives in injections.scm (second part) Co-authored-by: ObserverOfTime <chronobserver@disroot.org> * added comment to explain reasoning behind priority use * swapped order of @punctuation.delimiter and @operator to get rid of superfluous comment * moved macro and template keywords to @preproc capture * removed priorities in highlights.scm and shifted @parameter capture behind @type capture * improved formatting in locals.scm * added queries for missing cases of @definition.namespace capture in locals.scm * removed some trailing whitespace * added @namespace queries for highlights.scm * bumped parser version again * removed superfluous @type capture * removed `@type`s `has-ancestor` and removed `(_ (_ ...` structures, but added priorities * added missing @constant capture to some queries in highlights.scm * fixed priority numbers so they work when injecting nim (in markdown) * added @none captures back to injection targets * added (assembly_statement) injection query * added indent queries * removed indents.scm again * added some missing queries for dot_generic_call, concept_declaration and pragma_statement --------- Co-authored-by: Christian Clason <c.clason@uni-graz.at> Co-authored-by: ObserverOfTime <chronobserver@disroot.org>
This commit is contained in:
parent
6f8387f05d
commit
aeb5ad8ae1
8 changed files with 1213 additions and 0 deletions
|
|
@ -380,6 +380,12 @@
|
||||||
"nickel": {
|
"nickel": {
|
||||||
"revision": "b759233581fd8bae239e905c67a9ba453205da78"
|
"revision": "b759233581fd8bae239e905c67a9ba453205da78"
|
||||||
},
|
},
|
||||||
|
"nim": {
|
||||||
|
"revision": "7550f55c3f3dab32c6cb42d22907d75876a0ca74"
|
||||||
|
},
|
||||||
|
"nim_format_string": {
|
||||||
|
"revision": "b60f0e982a74fb5df93d26a468120cfe67e7e1af"
|
||||||
|
},
|
||||||
"ninja": {
|
"ninja": {
|
||||||
"revision": "0a95cfdc0745b6ae82f60d3a339b37f19b7b9267"
|
"revision": "0a95cfdc0745b6ae82f60d3a339b37f19b7b9267"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1146,6 +1146,22 @@ list.nickel = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list.nim = {
|
||||||
|
install_info = {
|
||||||
|
url = "https://github.com/alaviss/tree-sitter-nim",
|
||||||
|
files = { "src/parser.c", "src/scanner.c" },
|
||||||
|
},
|
||||||
|
maintainers = { "@aMOPel" },
|
||||||
|
}
|
||||||
|
|
||||||
|
list.nim_format_string = {
|
||||||
|
install_info = {
|
||||||
|
url = "https://github.com/aMOPel/tree-sitter-nim-format-string",
|
||||||
|
files = { "src/parser.c" },
|
||||||
|
},
|
||||||
|
maintainers = { "@aMOPel" },
|
||||||
|
}
|
||||||
|
|
||||||
list.ninja = {
|
list.ninja = {
|
||||||
install_info = {
|
install_info = {
|
||||||
url = "https://github.com/alemuller/tree-sitter-ninja",
|
url = "https://github.com/alemuller/tree-sitter-ninja",
|
||||||
|
|
|
||||||
47
queries/nim/folds.scm
Normal file
47
queries/nim/folds.scm
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
[
|
||||||
|
(const_section)
|
||||||
|
(var_section)
|
||||||
|
(let_section)
|
||||||
|
(type_section)
|
||||||
|
(using_section)
|
||||||
|
|
||||||
|
(object_declaration)
|
||||||
|
(tuple_type)
|
||||||
|
(enum_declaration)
|
||||||
|
|
||||||
|
(case)
|
||||||
|
(if)
|
||||||
|
(when)
|
||||||
|
(of_branch)
|
||||||
|
(elif_branch)
|
||||||
|
(else_branch)
|
||||||
|
|
||||||
|
(for)
|
||||||
|
(while)
|
||||||
|
(block)
|
||||||
|
(static_statement)
|
||||||
|
(pragma_statement)
|
||||||
|
|
||||||
|
(try)
|
||||||
|
(except_branch)
|
||||||
|
(finally_branch)
|
||||||
|
|
||||||
|
(do_block)
|
||||||
|
(call
|
||||||
|
(argument_list
|
||||||
|
(statement_list)))
|
||||||
|
|
||||||
|
(proc_declaration)
|
||||||
|
(func_declaration)
|
||||||
|
(method_declaration)
|
||||||
|
(iterator_declaration)
|
||||||
|
(converter_declaration)
|
||||||
|
(template_declaration)
|
||||||
|
(macro_declaration)
|
||||||
|
|
||||||
|
(proc_expression)
|
||||||
|
(func_expression)
|
||||||
|
(iterator_expression)
|
||||||
|
|
||||||
|
(concept_declaration)
|
||||||
|
] @fold
|
||||||
738
queries/nim/highlights.scm
Normal file
738
queries/nim/highlights.scm
Normal file
|
|
@ -0,0 +1,738 @@
|
||||||
|
; SPDX-FileCopyrightText: 2023 Leorize <leorize+oss@disroot.org>, aMOPel <>
|
||||||
|
; SPDX-License-Identifier: MPL-2.0
|
||||||
|
; SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; catch all rules
|
||||||
|
|
||||||
|
((identifier) @variable (#set! "priority" 99))
|
||||||
|
; NOTE: we need priority, since (identifier) is most specific and we have to
|
||||||
|
; capture nodes containing (identifier) as a whole, while overruling the
|
||||||
|
; @variable capture.
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @comment ; line and block comments
|
||||||
|
|
||||||
|
[
|
||||||
|
(comment)
|
||||||
|
(block_comment)
|
||||||
|
] @comment
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @comment.documentation ; comments documenting code
|
||||||
|
|
||||||
|
(documentation_comment "##" @comment.documentation)
|
||||||
|
(block_documentation_comment
|
||||||
|
"##[" @comment.documentation
|
||||||
|
"]##" @comment.documentation)
|
||||||
|
; NOTE: leaving content uncaptured so markdown can be injected
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @punctuation.delimiter ; delimiters (e.g. `;` / `.` / `,`)
|
||||||
|
|
||||||
|
[ "." ";" "," ":" "=" ] @punctuation.delimiter
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @operator ; symbolic operators (e.g. `+` / `*`)
|
||||||
|
|
||||||
|
(operator) @operator
|
||||||
|
|
||||||
|
(assignment "=" @operator)
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @punctuation.bracket ; brackets (e.g. `()` / `{}` / `[]`)
|
||||||
|
|
||||||
|
[ "(" ")" "[" "[:" "]" "{" "}" ] @punctuation.bracket
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @preproc ; various preprocessor directives & shebangs
|
||||||
|
|
||||||
|
[
|
||||||
|
"macro"
|
||||||
|
"template"
|
||||||
|
] @preproc
|
||||||
|
|
||||||
|
(pragma_list ["{." "}" ".}"] @preproc)
|
||||||
|
; NOTE: has to come after @punctuation.bracket
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @punctuation.special ; special symbols (e.g. `{}` in string interpolation)
|
||||||
|
|
||||||
|
(accent_quoted "`" @punctuation.special)
|
||||||
|
|
||||||
|
(exported_symbol "*" @punctuation.special)
|
||||||
|
|
||||||
|
; dereference operator
|
||||||
|
(bracket_expression !right "[" @punctuation.special . "]" @punctuation.special)
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @string ; string literals
|
||||||
|
|
||||||
|
[
|
||||||
|
(interpreted_string_literal)
|
||||||
|
(long_string_literal)
|
||||||
|
(raw_string_literal)
|
||||||
|
(generalized_string)
|
||||||
|
] @string
|
||||||
|
|
||||||
|
; injections in generalized_strings
|
||||||
|
(generalized_string (string_content) @none)
|
||||||
|
|
||||||
|
; format string injection in normal strings with & prefix
|
||||||
|
(prefix_expression
|
||||||
|
operator: (operator) @_string_prefix .
|
||||||
|
(_ (string_content) @none)
|
||||||
|
(#eq? @_string_prefix "&"))
|
||||||
|
|
||||||
|
; emit pragma injection
|
||||||
|
(pragma_statement
|
||||||
|
(pragma_list
|
||||||
|
(colon_expression
|
||||||
|
left: (identifier) @_emit_keyword (#eq? @_emit_keyword "emit")
|
||||||
|
right: (_ (string_content) @none))))
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @string.escape ; escape sequences
|
||||||
|
|
||||||
|
(escape_sequence) @string.escape
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @character ; character literals
|
||||||
|
|
||||||
|
(char_literal) @character
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @boolean ; boolean literals
|
||||||
|
|
||||||
|
((identifier) @boolean
|
||||||
|
(#any-of? @boolean "true" "false" "on" "off"))
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @number ; numeric literals
|
||||||
|
|
||||||
|
(integer_literal) @number
|
||||||
|
|
||||||
|
(custom_numeric_literal) @number
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @float ; floating-point number literals
|
||||||
|
|
||||||
|
(float_literal) @float
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @function ; function definitions
|
||||||
|
|
||||||
|
(proc_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @function
|
||||||
|
(accent_quoted (identifier) @function)
|
||||||
|
(exported_symbol (identifier) @function)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @function))
|
||||||
|
])
|
||||||
|
|
||||||
|
(func_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @function
|
||||||
|
(accent_quoted (identifier) @function)
|
||||||
|
(exported_symbol (identifier) @function)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @function))
|
||||||
|
])
|
||||||
|
|
||||||
|
(iterator_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @function
|
||||||
|
(accent_quoted (identifier) @function)
|
||||||
|
(exported_symbol (identifier) @function)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @function))
|
||||||
|
])
|
||||||
|
|
||||||
|
(converter_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @function
|
||||||
|
(accent_quoted (identifier) @function)
|
||||||
|
(exported_symbol (identifier) @function)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @function))
|
||||||
|
])
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @function.call ; function calls
|
||||||
|
|
||||||
|
(call
|
||||||
|
function: [
|
||||||
|
(identifier) @function.call
|
||||||
|
(accent_quoted (identifier) @function.call)
|
||||||
|
; generic types
|
||||||
|
(bracket_expression left: (identifier) @function.call)
|
||||||
|
(bracket_expression left: (accent_quoted (identifier) @function.call))
|
||||||
|
; dot accessor
|
||||||
|
(dot_expression right: (identifier) @function.call)
|
||||||
|
(dot_expression right: (accent_quoted (identifier) @function.call))
|
||||||
|
; both
|
||||||
|
(bracket_expression left:
|
||||||
|
(dot_expression right: (identifier) @function.call))
|
||||||
|
(bracket_expression left:
|
||||||
|
(dot_expression right: (accent_quoted (identifier) @function.call)))
|
||||||
|
])
|
||||||
|
|
||||||
|
(dot_generic_call
|
||||||
|
function: [
|
||||||
|
(identifier) @function.call
|
||||||
|
(accent_quoted (identifier) @function.call)
|
||||||
|
])
|
||||||
|
|
||||||
|
; generalized_string is a function call
|
||||||
|
; `identifier"string literal"`
|
||||||
|
; is short for
|
||||||
|
; `identifier(r"string literal")`
|
||||||
|
(generalized_string
|
||||||
|
function: [
|
||||||
|
(identifier) @function.call
|
||||||
|
(accent_quoted (identifier) @function.call)
|
||||||
|
])
|
||||||
|
|
||||||
|
; call with leading literal
|
||||||
|
(dot_expression
|
||||||
|
left: [
|
||||||
|
(nil_literal)
|
||||||
|
(integer_literal)
|
||||||
|
(float_literal)
|
||||||
|
(custom_numeric_literal)
|
||||||
|
(char_literal)
|
||||||
|
(interpreted_string_literal)
|
||||||
|
(long_string_literal)
|
||||||
|
(raw_string_literal)
|
||||||
|
(generalized_string)
|
||||||
|
(array_construction)
|
||||||
|
; for sequences
|
||||||
|
(prefix_expression
|
||||||
|
operator: (operator) @_at
|
||||||
|
(array_construction)
|
||||||
|
(#eq? @_at "@"))
|
||||||
|
(tuple_construction)
|
||||||
|
(curly_construction)
|
||||||
|
]
|
||||||
|
right: [
|
||||||
|
(identifier) @function.call
|
||||||
|
(accent_quoted (identifier) @function.call)
|
||||||
|
])
|
||||||
|
; NOTE: will double capture as @function.call if it also has argument_list
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @function.macro ; preprocessor macros
|
||||||
|
|
||||||
|
(template_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @function.macro
|
||||||
|
(accent_quoted (identifier) @function.macro)
|
||||||
|
(exported_symbol (identifier) @function.macro)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @function.macro))
|
||||||
|
])
|
||||||
|
|
||||||
|
(macro_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @function.macro
|
||||||
|
(accent_quoted (identifier) @function.macro)
|
||||||
|
(exported_symbol (identifier) @function.macro)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @function.macro))
|
||||||
|
])
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @method ; method definitions
|
||||||
|
|
||||||
|
(method_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @method
|
||||||
|
(accent_quoted (identifier) @method)
|
||||||
|
(exported_symbol (identifier) @method)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @method))
|
||||||
|
])
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @constructor ; constructor calls and definitions
|
||||||
|
|
||||||
|
(call
|
||||||
|
function: [
|
||||||
|
(identifier) @constructor
|
||||||
|
(accent_quoted (identifier) @constructor)
|
||||||
|
; generic types
|
||||||
|
(bracket_expression left: (identifier) @constructor)
|
||||||
|
(bracket_expression left: (accent_quoted (identifier) @constructor))
|
||||||
|
; dot accessor
|
||||||
|
(dot_expression right: (identifier) @constructor)
|
||||||
|
(dot_expression right: (accent_quoted (identifier) @constructor))
|
||||||
|
; both
|
||||||
|
(bracket_expression left:
|
||||||
|
(dot_expression right: (identifier) @constructor))
|
||||||
|
(bracket_expression left:
|
||||||
|
(dot_expression right: (accent_quoted (identifier) @constructor)))
|
||||||
|
]
|
||||||
|
(argument_list
|
||||||
|
(colon_expression)+))
|
||||||
|
; NOTE: this cannot detect constructors with 0 arguments
|
||||||
|
; those will be matched as @function.call instead
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @keyword ; various keywords
|
||||||
|
|
||||||
|
; unhandled but reserved keywords
|
||||||
|
; end
|
||||||
|
; interface
|
||||||
|
|
||||||
|
; static expression
|
||||||
|
; addr operator
|
||||||
|
((call
|
||||||
|
function: (identifier) @keyword)
|
||||||
|
(#any-of? @keyword "static" "addr"))
|
||||||
|
|
||||||
|
[
|
||||||
|
"const"
|
||||||
|
"let"
|
||||||
|
"var"
|
||||||
|
"type"
|
||||||
|
"concept"
|
||||||
|
"asm"
|
||||||
|
"bind"
|
||||||
|
"defer"
|
||||||
|
"do"
|
||||||
|
"mixin"
|
||||||
|
"static"
|
||||||
|
"object"
|
||||||
|
"tuple"
|
||||||
|
"enum"
|
||||||
|
"block"
|
||||||
|
"using"
|
||||||
|
"discard"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @keyword.function ; keywords that define a function (e.g. `func` in Go, `def` in Python)
|
||||||
|
|
||||||
|
[
|
||||||
|
"proc"
|
||||||
|
"func"
|
||||||
|
"method"
|
||||||
|
"converter"
|
||||||
|
"iterator"
|
||||||
|
] @keyword.function
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @keyword.operator ; operators that are English words (e.g. `and` / `or`)
|
||||||
|
|
||||||
|
[
|
||||||
|
"and"
|
||||||
|
"or"
|
||||||
|
"xor"
|
||||||
|
"not"
|
||||||
|
"div"
|
||||||
|
"mod"
|
||||||
|
"shl"
|
||||||
|
"shr"
|
||||||
|
"from"
|
||||||
|
"as"
|
||||||
|
"of"
|
||||||
|
"in"
|
||||||
|
"notin"
|
||||||
|
"is"
|
||||||
|
"isnot"
|
||||||
|
"cast"
|
||||||
|
] @keyword.operator
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @keyword.return ; keywords like `return` and `yield`
|
||||||
|
|
||||||
|
[
|
||||||
|
"return"
|
||||||
|
"yield"
|
||||||
|
] @keyword.return
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @conditional ; keywords related to conditionals (e.g. `if` / `else`)
|
||||||
|
|
||||||
|
[
|
||||||
|
"if"
|
||||||
|
"when"
|
||||||
|
"case"
|
||||||
|
"elif"
|
||||||
|
"else"
|
||||||
|
] @conditional
|
||||||
|
|
||||||
|
(of_branch "of" @conditional)
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @repeat ; keywords related to loops (e.g. `for` / `while`)
|
||||||
|
|
||||||
|
[
|
||||||
|
"for"
|
||||||
|
"while"
|
||||||
|
"continue"
|
||||||
|
"break"
|
||||||
|
] @repeat
|
||||||
|
|
||||||
|
(for "in" @repeat)
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @label ; GOTO and other labels (e.g. `label:` in C)
|
||||||
|
|
||||||
|
(block
|
||||||
|
label: [
|
||||||
|
(identifier) @label
|
||||||
|
(accent_quoted (identifier) @label)
|
||||||
|
])
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @include ; keywords for including modules (e.g. `import` / `from` in Python)
|
||||||
|
|
||||||
|
[
|
||||||
|
"import"
|
||||||
|
"include"
|
||||||
|
"export"
|
||||||
|
] @include
|
||||||
|
|
||||||
|
(import_from_statement "from" @include)
|
||||||
|
|
||||||
|
(except_clause "except" @include)
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @exception ; keywords related to exceptions (e.g. `throw` / `catch`)
|
||||||
|
|
||||||
|
[
|
||||||
|
"try"
|
||||||
|
"except"
|
||||||
|
"finally"
|
||||||
|
"raise"
|
||||||
|
] @exception
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @type ; type or class definitions and annotations
|
||||||
|
|
||||||
|
(type_expression) @type
|
||||||
|
|
||||||
|
; overrule identifiers in pragmas in (proc_type)s
|
||||||
|
(proc_type
|
||||||
|
pragmas: (pragma_list (_) @variable)
|
||||||
|
(#set! "priority" 101))
|
||||||
|
(iterator_type
|
||||||
|
pragmas: (pragma_list (_) @variable)
|
||||||
|
(#set! "priority" 101))
|
||||||
|
|
||||||
|
; generic types when declaring
|
||||||
|
((generic_parameter_list
|
||||||
|
(parameter_declaration
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @type
|
||||||
|
(accent_quoted (identifier) @type)
|
||||||
|
])))))
|
||||||
|
|
||||||
|
; generic types when calling
|
||||||
|
(call
|
||||||
|
function: (bracket_expression
|
||||||
|
right: (argument_list) @type))
|
||||||
|
; NOTE: this also falsely matches
|
||||||
|
; when accessing and directly call elements from an array of routines
|
||||||
|
; eg `array_of_routines[index](arguments), but that is an uncommon case
|
||||||
|
; NOTE: this will falsly capture (identifier)s that aren't types as well, eg
|
||||||
|
; array[enum1..enum2, int]
|
||||||
|
|
||||||
|
(dot_generic_call
|
||||||
|
generic_arguments: (_) @type)
|
||||||
|
|
||||||
|
; right side of `is` operator is always type
|
||||||
|
(infix_expression
|
||||||
|
operator: [ "is" "isnot" ]
|
||||||
|
right: (_) @type)
|
||||||
|
|
||||||
|
; except branch always contains types of errors
|
||||||
|
; Eg: `except module.exception[gen_type]:`
|
||||||
|
(except_branch
|
||||||
|
values: (expression_list) @type)
|
||||||
|
|
||||||
|
; overrule special case in (except_branch) with "as" operator
|
||||||
|
; `except module.exception[gen_type] as variable:`
|
||||||
|
(except_branch
|
||||||
|
values: (expression_list
|
||||||
|
(infix_expression
|
||||||
|
operator: "as"
|
||||||
|
right: [
|
||||||
|
(identifier) @variable
|
||||||
|
(accent_quoted (identifier) @variable)
|
||||||
|
])))
|
||||||
|
|
||||||
|
; for inline tuple types
|
||||||
|
; `type a = tuple[a: int]`
|
||||||
|
(tuple_type
|
||||||
|
"tuple" @type
|
||||||
|
(field_declaration_list))
|
||||||
|
; NOTE: this is consistent with other generic types like `seq[int]`
|
||||||
|
; but inconsistent with multiline tuple declaration,
|
||||||
|
; where `tuple` is captured as @keyword
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @parameter ; parameters of a function
|
||||||
|
|
||||||
|
; named parameters when calling
|
||||||
|
; call(parameter_name=arg)
|
||||||
|
(argument_list
|
||||||
|
(equal_expression
|
||||||
|
left: [
|
||||||
|
(identifier) @parameter
|
||||||
|
(accent_quoted (identifier) @parameter)
|
||||||
|
]))
|
||||||
|
|
||||||
|
; parameters in function declaration
|
||||||
|
(parameter_declaration_list
|
||||||
|
(parameter_declaration
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @parameter
|
||||||
|
(accent_quoted (identifier) @parameter)
|
||||||
|
]))))
|
||||||
|
; NOTE: needs to be after @type
|
||||||
|
|
||||||
|
; for loop variables
|
||||||
|
(for
|
||||||
|
left:
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @parameter
|
||||||
|
(accent_quoted (identifier) @parameter)
|
||||||
|
])))
|
||||||
|
|
||||||
|
((tuple_deconstruct_declaration
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @parameter
|
||||||
|
(accent_quoted (identifier) @parameter)
|
||||||
|
])) @_tuple_decons
|
||||||
|
(#has-ancestor? @_tuple_decons for))
|
||||||
|
|
||||||
|
(concept_declaration
|
||||||
|
parameters:
|
||||||
|
(parameter_list [
|
||||||
|
(identifier) @parameter
|
||||||
|
(accent_quoted (identifier) @parameter)
|
||||||
|
]))
|
||||||
|
(var_parameter [
|
||||||
|
(identifier) @parameter
|
||||||
|
(accent_quoted (identifier) @parameter)
|
||||||
|
])
|
||||||
|
(type_parameter [
|
||||||
|
(identifier) @parameter
|
||||||
|
(accent_quoted (identifier) @parameter)
|
||||||
|
])
|
||||||
|
(static_parameter [
|
||||||
|
(identifier) @parameter
|
||||||
|
(accent_quoted (identifier) @parameter)
|
||||||
|
])
|
||||||
|
(ref_parameter [
|
||||||
|
(identifier) @parameter
|
||||||
|
(accent_quoted (identifier) @parameter)
|
||||||
|
])
|
||||||
|
(pointer_parameter [
|
||||||
|
(identifier) @parameter
|
||||||
|
(accent_quoted (identifier) @parameter)
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @type.definition ; type definitions (e.g. `typedef` in C)
|
||||||
|
|
||||||
|
(type_section
|
||||||
|
(type_declaration
|
||||||
|
(type_symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @type.definition
|
||||||
|
(accent_quoted (identifier) @type.definition)
|
||||||
|
(exported_symbol (identifier) @type.definition)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @type.definition))
|
||||||
|
])))
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @type.qualifier ; type qualifiers (e.g. `const`)
|
||||||
|
|
||||||
|
(var_type "var" @type.qualifier)
|
||||||
|
(out_type "out" @type.qualifier)
|
||||||
|
(distinct_type "distinct" @type.qualifier)
|
||||||
|
(ref_type "ref" @type.qualifier)
|
||||||
|
(pointer_type "ptr" @type.qualifier)
|
||||||
|
|
||||||
|
(var_parameter "var" @type.qualifier)
|
||||||
|
(type_parameter "type" @type.qualifier)
|
||||||
|
(static_parameter "static" @type.qualifier)
|
||||||
|
(ref_parameter "ref" @type.qualifier)
|
||||||
|
(pointer_parameter "ptr" @type.qualifier)
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @field ; object and struct fields
|
||||||
|
|
||||||
|
; fields in object/tuple declaration
|
||||||
|
(field_declaration
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @field
|
||||||
|
(accent_quoted (identifier) @field)
|
||||||
|
(exported_symbol (identifier) @field)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @field))
|
||||||
|
])))
|
||||||
|
|
||||||
|
; fields in object construction
|
||||||
|
(call
|
||||||
|
(argument_list
|
||||||
|
(colon_expression
|
||||||
|
left: [
|
||||||
|
(identifier) @field
|
||||||
|
(accent_quoted (identifier) @field)
|
||||||
|
])))
|
||||||
|
|
||||||
|
; fields in tuple construction
|
||||||
|
(tuple_construction
|
||||||
|
(colon_expression
|
||||||
|
left: [
|
||||||
|
(identifier) @field
|
||||||
|
(accent_quoted (identifier) @field)
|
||||||
|
]))
|
||||||
|
|
||||||
|
(variant_declaration
|
||||||
|
(variant_discriminator_declaration
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @field
|
||||||
|
(accent_quoted (identifier) @field)
|
||||||
|
(exported_symbol (identifier) @field)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @field))
|
||||||
|
]))))
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @variable.builtin ; built-in variable names (e.g. `this`)
|
||||||
|
|
||||||
|
(blank_identifier) @variable.builtin
|
||||||
|
|
||||||
|
((identifier) @variable.builtin
|
||||||
|
(#eq? @variable.builtin "result"))
|
||||||
|
; NOTE: technically needs `has-ancestor some routine declaration` but it's
|
||||||
|
; not worth it
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @constant ; constant identifiers
|
||||||
|
|
||||||
|
; identifiers in "case" "of" branches have to be enums
|
||||||
|
(case
|
||||||
|
(of_branch values:
|
||||||
|
(expression_list (_) @constant)))
|
||||||
|
|
||||||
|
; in variant objects with "case" "of"
|
||||||
|
(variant_declaration
|
||||||
|
(of_branch values:
|
||||||
|
(expression_list (_) @constant)))
|
||||||
|
|
||||||
|
; enum declaration
|
||||||
|
(enum_field_declaration
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @constant
|
||||||
|
(accent_quoted (identifier) @constant)
|
||||||
|
]))
|
||||||
|
|
||||||
|
; constants/enums in array construction
|
||||||
|
(array_construction
|
||||||
|
(colon_expression
|
||||||
|
left: (_) @constant))
|
||||||
|
|
||||||
|
; constant declaration
|
||||||
|
(const_section
|
||||||
|
(variable_declaration
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @constant
|
||||||
|
(accent_quoted (identifier) @constant)
|
||||||
|
(exported_symbol (identifier) @constant)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @constant))
|
||||||
|
]))))
|
||||||
|
|
||||||
|
((tuple_deconstruct_declaration
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @constant
|
||||||
|
(accent_quoted (identifier) @constant)
|
||||||
|
(exported_symbol (identifier) @constant)
|
||||||
|
(exported_symbol (accent_quoted (identifier) @constant))
|
||||||
|
])) @_tuple_decons
|
||||||
|
(#has-ancestor? @_tuple_decons const_section))
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @constant.builtin ; built-in constant values
|
||||||
|
|
||||||
|
(nil_literal) @constant.builtin
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; @namespace ; modules or namespaces
|
||||||
|
|
||||||
|
(import_statement
|
||||||
|
(expression_list
|
||||||
|
(identifier) @namespace))
|
||||||
|
|
||||||
|
(import_statement
|
||||||
|
(expression_list
|
||||||
|
(infix_expression
|
||||||
|
operator: "as"
|
||||||
|
right: (identifier) @namespace)))
|
||||||
|
|
||||||
|
(import_statement
|
||||||
|
(expression_list
|
||||||
|
(infix_expression
|
||||||
|
operator: (operator) @_operator
|
||||||
|
right: [
|
||||||
|
(identifier) @namespace
|
||||||
|
(array_construction (identifier) @namespace)
|
||||||
|
]))
|
||||||
|
(#eq? @_operator "/"))
|
||||||
|
|
||||||
|
(import_from_statement
|
||||||
|
module: (infix_expression
|
||||||
|
operator: (operator) @_operator
|
||||||
|
right: (identifier) @namespace)
|
||||||
|
(#eq? @_operator "/"))
|
||||||
|
|
||||||
|
(export_statement
|
||||||
|
(expression_list
|
||||||
|
(identifier) @namespace))
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; overrule things
|
||||||
|
|
||||||
|
; left identifier in dot_expression
|
||||||
|
(dot_expression left: [
|
||||||
|
(identifier) @none
|
||||||
|
(accent_quoted (identifier) @none)
|
||||||
|
])
|
||||||
|
; NOTE: we can't know what the left identifier is, so better leave it alone
|
||||||
|
; for consistency
|
||||||
|
|
||||||
|
; discard literals is like a comment
|
||||||
|
(discard_statement
|
||||||
|
"discard" @comment
|
||||||
|
[
|
||||||
|
(nil_literal)
|
||||||
|
(integer_literal)
|
||||||
|
(float_literal)
|
||||||
|
(custom_numeric_literal)
|
||||||
|
(char_literal)
|
||||||
|
(interpreted_string_literal)
|
||||||
|
(long_string_literal)
|
||||||
|
(raw_string_literal)
|
||||||
|
(generalized_string)
|
||||||
|
(array_construction)
|
||||||
|
; for sequences
|
||||||
|
(prefix_expression
|
||||||
|
operator: (operator) @_at
|
||||||
|
(array_construction)
|
||||||
|
(#eq? @_at "@"))
|
||||||
|
(tuple_construction)
|
||||||
|
(curly_construction)
|
||||||
|
] @comment)
|
||||||
75
queries/nim/injections.scm
Normal file
75
queries/nim/injections.scm
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
; =============================================================================
|
||||||
|
; generalized_strings
|
||||||
|
|
||||||
|
; regex in generalized_strings
|
||||||
|
(generalized_string
|
||||||
|
function: (identifier) @_string_prefix .
|
||||||
|
(string_content) @injection.content
|
||||||
|
(#set! injection.language "regex")
|
||||||
|
(#any-of? @_string_prefix "re" "rex"))
|
||||||
|
|
||||||
|
; format string in generalized_strings
|
||||||
|
(generalized_string
|
||||||
|
function: (identifier) @_string_prefix .
|
||||||
|
(string_content) @injection.content
|
||||||
|
(#set! injection.language "nim_format_string")
|
||||||
|
(#eq? @_string_prefix "fmt"))
|
||||||
|
|
||||||
|
; format string in normal strings with & prefix
|
||||||
|
(prefix_expression
|
||||||
|
operator: (operator) @_string_prefix .
|
||||||
|
(_ (string_content) @injection.content)
|
||||||
|
(#set! injection.language "nim_format_string")
|
||||||
|
(#eq? @_string_prefix "&"))
|
||||||
|
|
||||||
|
; sql in generalized_strings
|
||||||
|
; and anyhting you like as long as the function name is the same as the injected language's parser
|
||||||
|
(generalized_string
|
||||||
|
function: (identifier) @injection.language
|
||||||
|
(string_content) @injection.content
|
||||||
|
(#not-any-of? @injection.language "re" "rex" "fmt"))
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; emit pragma
|
||||||
|
|
||||||
|
; C / CPP / OBJC / JAVASCRIPT
|
||||||
|
; a `#<no whitespace><language name>`
|
||||||
|
; has to directly precede the {.emit: "<language code>".} pragma
|
||||||
|
|
||||||
|
; eg.:
|
||||||
|
; #objc
|
||||||
|
; {.emit: "<objc code>".}
|
||||||
|
; OR
|
||||||
|
; #javascript
|
||||||
|
; {.emit: "<javascript code>".}
|
||||||
|
|
||||||
|
; normal strings
|
||||||
|
((comment (comment_content) @injection.language)
|
||||||
|
.
|
||||||
|
(pragma_statement
|
||||||
|
(pragma_list
|
||||||
|
(colon_expression
|
||||||
|
left: (identifier) @_emit_keyword (#eq? @_emit_keyword "emit")
|
||||||
|
right: (_ (string_content) @injection.content)))))
|
||||||
|
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; asm statement
|
||||||
|
|
||||||
|
; works same as emit pragma, needs preceding comment with language name
|
||||||
|
((comment (comment_content) @injection.language)
|
||||||
|
.
|
||||||
|
(assembly_statement (_ (string_content) @injection.content)))
|
||||||
|
|
||||||
|
; =============================================================================
|
||||||
|
; comments
|
||||||
|
|
||||||
|
; NOTE: ts "comment" parser heavily impacts performance
|
||||||
|
|
||||||
|
; markdown parser in documentation_comment
|
||||||
|
(documentation_comment (comment_content) @injection.content
|
||||||
|
(#set! injection.language "markdown_inline"))
|
||||||
|
|
||||||
|
; markdown parser in block_documentation_comment
|
||||||
|
(block_documentation_comment (comment_content) @injection.content
|
||||||
|
(#set! injection.language "markdown"))
|
||||||
310
queries/nim/locals.scm
Normal file
310
queries/nim/locals.scm
Normal file
|
|
@ -0,0 +1,310 @@
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @definition ; various definitions
|
||||||
|
|
||||||
|
(block
|
||||||
|
label: [
|
||||||
|
(identifier) @definition
|
||||||
|
(accent_quoted) @definition
|
||||||
|
])
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @definition.constant ; constants
|
||||||
|
|
||||||
|
(const_section
|
||||||
|
(variable_declaration
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.constant
|
||||||
|
(accent_quoted) @definition.constant
|
||||||
|
(exported_symbol (identifier) @definition.constant)
|
||||||
|
(exported_symbol (accent_quoted) @definition.constant)
|
||||||
|
]))
|
||||||
|
type: (type_expression)? @definition.associated))
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @definition.function ; functions
|
||||||
|
|
||||||
|
(proc_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.function
|
||||||
|
(accent_quoted) @definition.function
|
||||||
|
(exported_symbol (identifier) @definition.function)
|
||||||
|
(exported_symbol (accent_quoted) @definition.function)
|
||||||
|
]
|
||||||
|
(#set! "definition.function.scope" "parent"))
|
||||||
|
|
||||||
|
(func_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.function
|
||||||
|
(accent_quoted) @definition.function
|
||||||
|
(exported_symbol (identifier) @definition.function)
|
||||||
|
(exported_symbol (accent_quoted) @definition.function)
|
||||||
|
]
|
||||||
|
(#set! "definition.function.scope" "parent"))
|
||||||
|
|
||||||
|
(iterator_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.function
|
||||||
|
(accent_quoted) @definition.function
|
||||||
|
(exported_symbol (identifier) @definition.function)
|
||||||
|
(exported_symbol (accent_quoted) @definition.function)
|
||||||
|
]
|
||||||
|
(#set! "definition.function.scope" "parent"))
|
||||||
|
|
||||||
|
(converter_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.function
|
||||||
|
(accent_quoted) @definition.function
|
||||||
|
(exported_symbol (identifier) @definition.function)
|
||||||
|
(exported_symbol (accent_quoted) @definition.function)
|
||||||
|
]
|
||||||
|
(#set! "definition.function.scope" "parent"))
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @definition.method ; methods
|
||||||
|
|
||||||
|
(method_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.method
|
||||||
|
(accent_quoted) @definition.method
|
||||||
|
(exported_symbol (identifier) @definition.method)
|
||||||
|
(exported_symbol (accent_quoted) @definition.method)
|
||||||
|
]
|
||||||
|
(#set! "definition.method.scope" "parent"))
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @definition.var ; variables
|
||||||
|
|
||||||
|
(var_section
|
||||||
|
(variable_declaration
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.var
|
||||||
|
(accent_quoted) @definition.var
|
||||||
|
(exported_symbol (identifier) @definition.var)
|
||||||
|
(exported_symbol (accent_quoted) @definition.var)
|
||||||
|
]))
|
||||||
|
type: (type_expression)? @definition.associated))
|
||||||
|
|
||||||
|
(let_section
|
||||||
|
(variable_declaration
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.var
|
||||||
|
(accent_quoted) @definition.var
|
||||||
|
(exported_symbol (identifier) @definition.var)
|
||||||
|
(exported_symbol (accent_quoted) @definition.var)
|
||||||
|
]))
|
||||||
|
type: (type_expression)? @definition.associated))
|
||||||
|
|
||||||
|
(for
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.var
|
||||||
|
(accent_quoted) @definition.var
|
||||||
|
])))
|
||||||
|
|
||||||
|
(try
|
||||||
|
(except_branch
|
||||||
|
values: (expression_list
|
||||||
|
(infix_expression
|
||||||
|
right: [
|
||||||
|
(identifier) @definition.var
|
||||||
|
(accent_quoted) @definition.var
|
||||||
|
]))))
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @definition.parameter ; parameters
|
||||||
|
|
||||||
|
(parameter_declaration
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.parameter
|
||||||
|
(accent_quoted) @definition.parameter
|
||||||
|
]))
|
||||||
|
type: (type_expression)? @definition.associated)
|
||||||
|
|
||||||
|
(concept_declaration
|
||||||
|
parameters:
|
||||||
|
(parameter_list [
|
||||||
|
(identifier) @definition.parameter
|
||||||
|
(accent_quoted (identifier) @definition.parameter)
|
||||||
|
]))
|
||||||
|
(var_parameter [
|
||||||
|
(identifier) @definition.parameter
|
||||||
|
(accent_quoted (identifier) @definition.parameter)
|
||||||
|
])
|
||||||
|
(type_parameter [
|
||||||
|
(identifier) @definition.parameter
|
||||||
|
(accent_quoted (identifier) @definition.parameter)
|
||||||
|
])
|
||||||
|
(static_parameter [
|
||||||
|
(identifier) @definition.parameter
|
||||||
|
(accent_quoted (identifier) @definition.parameter)
|
||||||
|
])
|
||||||
|
(ref_parameter [
|
||||||
|
(identifier) @definition.parameter
|
||||||
|
(accent_quoted (identifier) @definition.parameter)
|
||||||
|
])
|
||||||
|
(pointer_parameter [
|
||||||
|
(identifier) @definition.parameter
|
||||||
|
(accent_quoted (identifier) @definition.parameter)
|
||||||
|
])
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @definition.macro ; preprocessor macros
|
||||||
|
|
||||||
|
(template_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.macro
|
||||||
|
(accent_quoted) @definition.macro
|
||||||
|
(exported_symbol (identifier) @definition.macro)
|
||||||
|
(exported_symbol (accent_quoted) @definition.macro)
|
||||||
|
]
|
||||||
|
(#set! "definition.macro.scope" "parent"))
|
||||||
|
|
||||||
|
(macro_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.macro
|
||||||
|
(accent_quoted) @definition.macro
|
||||||
|
(exported_symbol (identifier) @definition.macro)
|
||||||
|
(exported_symbol (accent_quoted) @definition.macro)
|
||||||
|
]
|
||||||
|
(#set! "definition.macro.scope" "parent"))
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @definition.type ; types or classes
|
||||||
|
|
||||||
|
(type_declaration
|
||||||
|
(type_symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.type
|
||||||
|
(accent_quoted) @definition.type
|
||||||
|
(exported_symbol (identifier) @definition.type)
|
||||||
|
(exported_symbol (accent_quoted) @definition.type)
|
||||||
|
]))
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @definition.field ; fields or properties
|
||||||
|
|
||||||
|
(object_declaration
|
||||||
|
(field_declaration_list
|
||||||
|
(field_declaration
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.field
|
||||||
|
(accent_quoted) @definition.field
|
||||||
|
(exported_symbol (identifier) @definition.field)
|
||||||
|
(exported_symbol (accent_quoted) @definition.field)
|
||||||
|
]))
|
||||||
|
type: (type_expression)? @definition.associated)))
|
||||||
|
|
||||||
|
(tuple_type
|
||||||
|
(field_declaration
|
||||||
|
(symbol_declaration_list
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.field
|
||||||
|
(accent_quoted) @definition.field
|
||||||
|
]))
|
||||||
|
type: (type_expression)? @definition.associated))
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @definition.enum ; enumerations
|
||||||
|
|
||||||
|
(enum_declaration
|
||||||
|
(enum_field_declaration
|
||||||
|
(symbol_declaration
|
||||||
|
name: [
|
||||||
|
(identifier) @definition.enum
|
||||||
|
(accent_quoted) @definition.enum
|
||||||
|
])))
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @definition.namespace ; modules or namespaces
|
||||||
|
; @definition.import ; imported names
|
||||||
|
|
||||||
|
(import_statement
|
||||||
|
(expression_list
|
||||||
|
(identifier) @definition.namespace))
|
||||||
|
|
||||||
|
(import_statement
|
||||||
|
(expression_list
|
||||||
|
(infix_expression
|
||||||
|
operator: "as"
|
||||||
|
right: (identifier) @definition.namespace)))
|
||||||
|
|
||||||
|
(import_statement
|
||||||
|
(expression_list
|
||||||
|
(infix_expression
|
||||||
|
operator: (operator) @_operator
|
||||||
|
right: [
|
||||||
|
(identifier) @definition.namespace
|
||||||
|
(array_construction (identifier) @definition.namespace)
|
||||||
|
]))
|
||||||
|
(#eq? @_operator "/"))
|
||||||
|
|
||||||
|
(import_from_statement
|
||||||
|
module: (infix_expression
|
||||||
|
operator: (operator) @_operator
|
||||||
|
right: (identifier) @definition.namespace)
|
||||||
|
(expression_list [
|
||||||
|
(identifier) @definition.import
|
||||||
|
(accent_quoted) @definition.import
|
||||||
|
])
|
||||||
|
(#eq? @_operator "/"))
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @scope ; scope block
|
||||||
|
|
||||||
|
; (when)
|
||||||
|
; NOTE: `when` does actually not create a scope
|
||||||
|
|
||||||
|
(if
|
||||||
|
consequence: (statement_list) @scope
|
||||||
|
alternative: (elif_branch)* @scope
|
||||||
|
alternative: (else_branch)? @scope)
|
||||||
|
|
||||||
|
(case
|
||||||
|
(of_branch)* @scope
|
||||||
|
(elif_branch)* @scope
|
||||||
|
(else_branch)? @scope)
|
||||||
|
|
||||||
|
(try
|
||||||
|
body: (statement_list) @scope
|
||||||
|
(except_branch) @scope
|
||||||
|
(finally_branch)? @scope)
|
||||||
|
|
||||||
|
[
|
||||||
|
(for)
|
||||||
|
(while)
|
||||||
|
(block)
|
||||||
|
(static_statement)
|
||||||
|
|
||||||
|
(proc_declaration)
|
||||||
|
(func_declaration)
|
||||||
|
(method_declaration)
|
||||||
|
(iterator_declaration)
|
||||||
|
(converter_declaration)
|
||||||
|
(template_declaration)
|
||||||
|
(macro_declaration)
|
||||||
|
|
||||||
|
(proc_expression)
|
||||||
|
(func_expression)
|
||||||
|
(iterator_expression)
|
||||||
|
|
||||||
|
(concept_declaration)
|
||||||
|
] @scope
|
||||||
|
|
||||||
|
; ==============================================================================
|
||||||
|
; @reference ; identifier reference
|
||||||
|
|
||||||
|
(identifier) @reference
|
||||||
|
(accent_quoted) @reference
|
||||||
19
queries/nim_format_string/highlights.scm
Normal file
19
queries/nim_format_string/highlights.scm
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
(string_literal)
|
||||||
|
(matching_curlies
|
||||||
|
opening_curly: (opening_curly) @punctuation.special
|
||||||
|
equals: (equals)? @punctuation.special
|
||||||
|
closing_curly: (closing_curly) @punctuation.special)
|
||||||
|
|
||||||
|
(format_specifiers
|
||||||
|
colon: (colon) @punctuation.delimiter
|
||||||
|
fill_align: (fill_align)? @conditional.ternary
|
||||||
|
sign: (sign)? @operator
|
||||||
|
hash: (hash)? @punctuation.special
|
||||||
|
zero: (zero)? @field
|
||||||
|
min_width: (min_width)? @number
|
||||||
|
precision: (precision)? @number
|
||||||
|
type: (type)? @type)
|
||||||
|
|
||||||
|
(matching_curlies
|
||||||
|
nim_expression: (nim_expression
|
||||||
|
escaped_curly: (escaped_curly)+ @string.escape) @none)
|
||||||
2
queries/nim_format_string/injections.scm
Normal file
2
queries/nim_format_string/injections.scm
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
((matching_curlies (nim_expression !escaped_curly) @injection.content)
|
||||||
|
(#set! injection.language "nim"))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue