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