mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-20 12:20:02 -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
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue