diff options
| author | Christian Clason <c.clason@uni-graz.at> | 2023-06-12 09:54:30 -0600 |
|---|---|---|
| committer | Christian Clason <c.clason@uni-graz.at> | 2025-05-12 18:43:40 +0200 |
| commit | 692b051b09935653befdb8f7ba8afdb640adf17b (patch) | |
| tree | 167162b6b129ae04f68c5735078521a72917c742 /runtime/queries/fennel | |
| parent | feat(c-family): inherit injections (diff) | |
| download | nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2 nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip | |
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'runtime/queries/fennel')
| -rw-r--r-- | runtime/queries/fennel/folds.scm | 51 | ||||
| -rw-r--r-- | runtime/queries/fennel/highlights.scm | 193 | ||||
| -rw-r--r-- | runtime/queries/fennel/injections.scm | 134 | ||||
| -rw-r--r-- | runtime/queries/fennel/locals.scm | 56 |
4 files changed, 434 insertions, 0 deletions
diff --git a/runtime/queries/fennel/folds.scm b/runtime/queries/fennel/folds.scm new file mode 100644 index 000000000..0862e5926 --- /dev/null +++ b/runtime/queries/fennel/folds.scm @@ -0,0 +1,51 @@ +; compounds +[ + (list) + (table) + (sequence) +] @fold + +; sub-forms / special compounds +[ + (list_binding) + (table_binding) + (sequence_binding) + (table_metadata) + (sequence_arguments) + (let_vars) + (case_guard_or_special) + (case_guard) + (case_catch) +] @fold + +; forms +[ + (quote_form) + (unquote_form) + (local_form) + (var_form) + (set_form) + (global_form) + (let_form) + (fn_form) + (lambda_form) + (hashfn_form) + (each_form) + (collect_form) + (icollect_form) + (accumulate_form) + (for_form) + (fcollect_form) + (faccumulate_form) + (case_form) + (match_form) + (case_try_form) + (match_try_form) +] @fold + +; reader macros +(quote_reader_macro + expression: (_) @fold) + +(quasi_quote_reader_macro + expression: (_) @fold) diff --git a/runtime/queries/fennel/highlights.scm b/runtime/queries/fennel/highlights.scm new file mode 100644 index 000000000..2f0b5f738 --- /dev/null +++ b/runtime/queries/fennel/highlights.scm @@ -0,0 +1,193 @@ +; Most primitive nodes +(shebang) @keyword.directive + +(comment) @comment @spell + +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @punctuation.bracket + +[ + (nil) + (nil_binding) +] @constant.builtin + +[ + (boolean) + (boolean_binding) +] @boolean + +[ + (number) + (number_binding) +] @number + +[ + (string) + (string_binding) +] @string + +[ + (symbol) + (symbol_binding) +] @variable + +(symbol_option) @keyword.directive + +(escape_sequence) @string.escape + +(multi_symbol + "." @punctuation.delimiter + member: (symbol_fragment) @variable.member) + +(list + call: (symbol) @function.call) + +(list + call: (multi_symbol + member: (symbol_fragment) @function.call .)) + +(multi_symbol_method + ":" @punctuation.delimiter + method: (symbol_fragment) @function.method.call) + +(quasi_quote_reader_macro + macro: _ @punctuation.special) + +(quote_reader_macro + macro: _ @punctuation.special) + +(unquote_reader_macro + macro: _ @punctuation.special) + +(hashfn_reader_macro + macro: _ @keyword.function) + +(sequence_arguments + (symbol_binding) @variable.parameter) + +(sequence_arguments + (rest_binding + rhs: (symbol_binding) @variable.parameter)) + +(docstring) @string.documentation + +(fn_form + name: [ + (symbol) @function + (multi_symbol + member: (symbol_fragment) @function .) + ]) + +(lambda_form + name: [ + (symbol) @function + (multi_symbol + member: (symbol_fragment) @function .) + ]) + +; NOTE: The macro name is highlighted as @variable because it +; gives a nicer contrast instead of everything being the same +; color. Rust queries use this workaround too for `macro_rules!`. +(macro_form + name: [ + (symbol) @variable + (multi_symbol + member: (symbol_fragment) @variable .) + ]) + +((symbol) @variable.parameter + (#any-of? @variable.parameter "$" "$...")) + +((symbol) @variable.parameter + (#lua-match? @variable.parameter "^%$[1-9]$")) + +((symbol) @operator + (#any-of? @operator + ; arithmetic + "+" "-" "*" "/" "//" "%" "^" + ; comparison + ">" "<" ">=" "<=" "=" "~=" + ; other + "#" "." "?." "..")) + +((symbol) @keyword.operator + (#any-of? @keyword.operator + ; comparison + "not=" + ; boolean + "and" "or" "not" + ; bitwise + "lshift" "rshift" "band" "bor" "bxor" "bnot" + ; other + "length")) + +(case_guard + call: (_) @keyword.conditional) + +(case_guard_or_special + call: (_) @keyword.conditional) + +((symbol) @keyword.function + (#any-of? @keyword.function "fn" "lambda" "λ" "hashfn")) + +((symbol) @keyword.repeat + (#any-of? @keyword.repeat "for" "each" "while")) + +((symbol) @keyword.conditional + (#any-of? @keyword.conditional "if" "when" "match" "case" "match-try" "case-try")) + +((symbol) @keyword + (#any-of? @keyword + "global" "local" "let" "set" "var" "comment" "do" "doc" "eval-compiler" "lua" "macros" "unquote" + "quote" "tset" "values" "tail!")) + +((symbol) @keyword.import + (#any-of? @keyword.import "require-macros" "import-macros" "include")) + +((symbol) @function.macro + (#any-of? @function.macro + "collect" "icollect" "fcollect" "accumulate" "faccumulate" "->" "->>" "-?>" "-?>>" "?." "doto" + "macro" "macrodebug" "partial" "pick-args" "pick-values" "with-open")) + +(case_catch + call: (symbol) @keyword) + +(import_macros_form + imports: (table_binding + (table_binding_pair + value: (symbol_binding) @function.macro))) + +; TODO: Highlight builtin methods (`table.unpack`, etc) as @function.builtin +([ + (symbol) @module.builtin + (multi_symbol + base: (symbol_fragment) @module.builtin) +] + (#any-of? @module.builtin + "vim" "_G" "debug" "io" "jit" "math" "os" "package" "string" "table" "utf8")) + +([ + (symbol) @variable.builtin + (multi_symbol + . + (symbol_fragment) @variable.builtin) +] + (#eq? @variable.builtin "arg")) + +((symbol) @variable.builtin + (#eq? @variable.builtin "...")) + +((symbol) @constant.builtin + (#eq? @constant.builtin "_VERSION")) + +((symbol) @function.builtin + (#any-of? @function.builtin + "assert" "collectgarbage" "dofile" "error" "getmetatable" "ipairs" "load" "loadfile" "next" + "pairs" "pcall" "print" "rawequal" "rawget" "rawlen" "rawset" "require" "select" "setmetatable" + "tonumber" "tostring" "type" "warn" "xpcall" "module" "setfenv" "loadstring" "unpack")) diff --git a/runtime/queries/fennel/injections.scm b/runtime/queries/fennel/injections.scm new file mode 100644 index 000000000..f6724d328 --- /dev/null +++ b/runtime/queries/fennel/injections.scm @@ -0,0 +1,134 @@ +((comment_body) @injection.content + (#set! injection.language "comment")) + +(list + call: (multi_symbol) @_vimcmd_identifier + (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec2") + . + item: (string + (string_content) @injection.content + (#set! injection.language "vim"))) + +; NOTE: Matches *exactly* `ffi.cdef` +(list + call: (multi_symbol) @_cdef_identifier + (#eq? @_cdef_identifier "ffi.cdef") + . + item: (string + (string_content) @injection.content + (#set! injection.language "c"))) + +(list + call: (multi_symbol) @_ts_query_identifier + (#any-of? @_ts_query_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse") + . + item: (_) + . + item: (_) + . + item: (string + (string_content) @injection.content + (#set! injection.language "query"))) + +(list + call: (multi_symbol) @_vimcmd_identifier + (#eq? @_vimcmd_identifier "vim.api.nvim_create_autocmd") + . + item: (_) + . + item: (table + (table_pair + key: (string + (string_content) @_command + (#eq? @_command "command")) + value: (string + (string_content) @injection.content + (#set! injection.language "vim"))))) + +(list + call: (multi_symbol) @_user_cmd + (#eq? @_user_cmd "vim.api.nvim_create_user_command") + . + item: (_) + . + item: (string + (string_content) @injection.content + (#set! injection.language "vim"))) + +(list + call: (multi_symbol) @_user_cmd + (#eq? @_user_cmd "vim.api.nvim_buf_create_user_command") + . + item: (_) + . + item: (_) + . + item: (string + (string_content) @injection.content + (#set! injection.language "vim"))) + +(list + call: (multi_symbol) @_map + (#any-of? @_map "vim.api.nvim_set_keymap" "vim.keymap.set") + . + item: (_) + . + item: (_) + . + item: (string + (string_content) @injection.content + (#set! injection.language "vim"))) + +(list + call: (multi_symbol) @_map + (#eq? @_map "vim.api.nvim_buf_set_keymap") + . + item: (_) + . + item: (_) + . + item: (_) + . + item: (string + (string_content) @injection.content + (#set! injection.language "vim"))) + +; highlight string as query if starts with `; query` +(string + (string_content) @injection.content + (#lua-match? @injection.content "^%s*;+%s?query") + (#set! injection.language "query")) + +; (string.match "123" "%d+") +(list + call: (multi_symbol + member: (symbol_fragment) @_func + . + (#any-of? @_func "find" "match" "gmatch" "gsub")) + . + item: (_) + . + item: (string + (string_content) @injection.content + (#set! injection.language "luap") + (#set! injection.include-children))) + +; (my-string:match "%d+") +(list + call: (multi_symbol_method + method: (symbol_fragment) @_method + (#any-of? @_method "find" "match" "gmatch" "gsub")) + . + item: (string + (string_content) @injection.content + (#set! injection.language "luap") + (#set! injection.include-children))) + +; (string.format "pi = %.2f" 3.14159) +(list + call: (multi_symbol) @_func + (#eq? @_func "string.format") + . + item: (string + (string_content) @injection.content + (#set! injection.language "printf"))) diff --git a/runtime/queries/fennel/locals.scm b/runtime/queries/fennel/locals.scm new file mode 100644 index 000000000..be63e728f --- /dev/null +++ b/runtime/queries/fennel/locals.scm @@ -0,0 +1,56 @@ +(program) @local.scope + +(symbol) @local.reference + +[ + (let_form) + (fn_form) + (lambda_form) + (each_form) + (for_form) + (collect_form) + (icollect_form) + (accumulate_form) + (for_form) + (fcollect_form) + (faccumulate_form) + (case_form) + (match_form) + (case_try_form) + (match_try_form) + (if_form) +] @local.scope + +(list + call: (symbol) @_call + (#any-of? @_call "while" "when" "do")) @local.scope + +(fn_form + name: [ + (symbol) @local.definition.function + (multi_symbol + member: (symbol_fragment) @local.definition.function .) + ] + args: (sequence_arguments + (symbol_binding) @local.definition.parameter) + (#set! definition.function.scope "parent")) + +(lambda_form + name: [ + (symbol) @local.definition.function + (multi_symbol + member: (symbol_fragment) @local.definition.function .) + ] + args: (sequence_arguments + (symbol_binding) @local.definition.parameter) + (#set! definition.function.scope "parent")) + +(macro_form + name: [ + (symbol) @local.definition.function + (multi_symbol + member: (symbol_fragment) @local.definition.function .) + ] + args: (sequence_arguments + (symbol_binding) @local.definition.parameter) + (#set! definition.function.scope "parent")) |
