diff options
| author | aMOPel <36712072+aMOPel@users.noreply.github.com> | 2023-11-30 16:21:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-01 00:21:43 +0900 |
| commit | 36f81e698ee67cba76f698a5a86fb7c6ecdeb7b0 (patch) | |
| tree | 28fc1af80cc50283c6a06f4d428400de0e09e572 /queries | |
| parent | fix(luarocks): enable automatic runtime path detection (diff) | |
| download | nvim-treesitter-36f81e698ee67cba76f698a5a86fb7c6ecdeb7b0.tar nvim-treesitter-36f81e698ee67cba76f698a5a86fb7c6ecdeb7b0.tar.gz nvim-treesitter-36f81e698ee67cba76f698a5a86fb7c6ecdeb7b0.tar.bz2 nvim-treesitter-36f81e698ee67cba76f698a5a86fb7c6ecdeb7b0.tar.lz nvim-treesitter-36f81e698ee67cba76f698a5a86fb7c6ecdeb7b0.tar.xz nvim-treesitter-36f81e698ee67cba76f698a5a86fb7c6ecdeb7b0.tar.zst nvim-treesitter-36f81e698ee67cba76f698a5a86fb7c6ecdeb7b0.zip | |
feat(nim): added some captures and fixed some bugs (#5664)
* fix(nim): literals in pragmas in types would be falsly highlighted as `@variable`
* style(nim): removed trailing whitespace
* fix(nim): identifiers in (type_expression (pragma_expression)) would be
captured as `@type`
* fix(nim): changed generic parameters when declaring from @type to @parameter
* feat(nim): added @constant capture for (identifier)s x, y in
`array[x..y, type]`
* feat(nim): added @function.call capture for (identifier)s in second
argument to `varargs[type, routine]`
Diffstat (limited to 'queries')
| -rw-r--r-- | queries/nim/highlights.scm | 103 |
1 files changed, 78 insertions, 25 deletions
diff --git a/queries/nim/highlights.scm b/queries/nim/highlights.scm index e3aa64d2c..a743c544b 100644 --- a/queries/nim/highlights.scm +++ b/queries/nim/highlights.scm @@ -10,6 +10,25 @@ ; capture nodes containing (identifier) as a whole, while overruling the ; @variable capture. +(type_expression) @type +; NOTE: has to be after +; ((identifier) @variable (#set! "priority" 99)) + +; overrule identifiers in pragmas in (proc_type)s and (pragma_expression)s +(proc_type + pragmas: + (pragma_list) @variable) +(iterator_type + pragmas: + (pragma_list) @variable) +(type_expression + (pragma_expression + right: + (pragma_list) @variable)) +; NOTE: has to be after +; (type_expression) @type +; and before @preproc and all literals + ; ============================================================================= ; @comment ; line and block comments @@ -22,8 +41,8 @@ ; @comment.documentation ; comments documenting code (documentation_comment "##" @comment.documentation) -(block_documentation_comment - "##[" @comment.documentation +(block_documentation_comment + "##[" @comment.documentation "]##" @comment.documentation) ; NOTE: leaving content uncaptured so markdown can be injected @@ -217,6 +236,22 @@ ]) ; NOTE: will double capture as @function.call if it also has argument_list +; function.calls in `varargs[type, routine]` +(bracket_expression + left: (identifier) @_varargs + right: + (argument_list + . + (_) + . + [ + (identifier) @function.call + (accent_quoted (identifier) @function.call) + (dot_expression right: (identifier) @function.call) + (dot_expression right: (accent_quoted (identifier) @function.call)) + ]) + (#eq? @_varargs "varargs")) + ; ============================================================================= ; @function.macro ; preprocessor macros @@ -405,26 +440,6 @@ ; ============================================================================= ; @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 @@ -432,8 +447,6 @@ ; 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) @@ -491,6 +504,16 @@ ])))) ; NOTE: needs to be after @type +; generic types when declaring +((generic_parameter_list + (parameter_declaration + (symbol_declaration_list + (symbol_declaration + name: [ + (identifier) @parameter + (accent_quoted (identifier) @parameter) + ]))))) + ; for loop variables (for left: @@ -510,7 +533,7 @@ (#has-ancestor? @_tuple_decons for)) (concept_declaration - parameters: + parameters: (parameter_list [ (identifier) @parameter (accent_quoted (identifier) @parameter) @@ -665,6 +688,36 @@ ])) @_tuple_decons (#has-ancestor? @_tuple_decons const_section)) +; constants x and y in `array[x..y, type]` +(bracket_expression + left: (identifier) @_array + right: + (argument_list + . + (infix_expression + right: [ + (identifier) @constant + (accent_quoted (identifier) @constant) + (dot_expression right: (identifier) @constant) + (dot_expression right: (accent_quoted (identifier) @constant)) + ])) + (#any-of? @_array "array" "range")) +(bracket_expression + left: (identifier) @_array + right: + (argument_list + . + (infix_expression + left: [ + (identifier) @constant + (accent_quoted (identifier) @constant) + (dot_expression right: (identifier) @constant) + (dot_expression right: (accent_quoted (identifier) @constant)) + ])) + (#any-of? @_array "array" "range")) +; NOTE: can only do this for (infix_expression)s, since standalone identifiers +; could be ordinal types and constants + ; ============================================================================= ; @constant.builtin ; built-in constant values |
