vikingowl 9b7625de68 feat: add impl blocks, const, try operator, loop labels, object patterns
Cover five missing language constructs identified from comparison with
the existing tree-sitter-rune crate by zhuhaow:

- impl_item: impl blocks with optional name and visibility
- const_item: const declarations with visibility support
- try_expression: postfix ? operator at precedence 13
- loop_label/label: 'name: labels on loop/while/for, referenced in
  break/continue
- object_pattern/object_pattern_entry: #{ key: pat } destructuring in
  match with shorthand, string keys, and rest patterns

All 55 tests pass (28 existing + 27 new).
2026-03-27 11:56:55 +01:00

tree-sitter-rune

Rune grammar for tree-sitter.

Provides syntax highlighting, indentation, code folding, and scope tracking for .rn files.

Supported Syntax

  • Functions (fn, pub fn, async fn)
  • Structs (named, tuple, unit)
  • Enums (unit, tuple, struct variants)
  • Modules and imports (mod, use)
  • Control flow (if/else, match with guards, loop, while, for)
  • Pattern matching (tuple, struct, enum, or-patterns, wildcards, rest)
  • Closures (sync and async)
  • Template literals (`hello ${name}`)
  • Object literals (#{ key: value })
  • Generators (yield)
  • Async/await and select blocks
  • is / is not type checking
  • Macro invocations (println!())

Installation

Neovim (nvim-treesitter)

Step 1: Register the parser and filetype in your Neovim config:

local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.rune = {
  install_info = {
    url = "https://somegit.dev/vikingowl/tree-sitter-rune",
    files = { "src/parser.c", "src/scanner.c" },
    branch = "main",
  },
  filetype = "rune",
}

vim.filetype.add({ extension = { rn = "rune" } })
vim.treesitter.language.register("rune", "rune")

Step 2: Install the parser:

:TSInstall rune

Step 3: Copy query files for highlighting, indentation, and folding:

# Clone the repo and copy queries to your Neovim runtime
git clone https://somegit.dev/vikingowl/tree-sitter-rune.git /tmp/tree-sitter-rune
mkdir -p ~/.config/nvim/queries/rune
cp /tmp/tree-sitter-rune/queries/*.scm ~/.config/nvim/queries/rune/
rm -rf /tmp/tree-sitter-rune

Restart Neovim and open any .rn file.

AstroNvim

Create lua/plugins/rune.lua:

return {
  {
    "AstroNvim/astrocore",
    opts = {
      filetypes = {
        extension = { rn = "rune" },
      },
    },
  },
  {
    "nvim-treesitter/nvim-treesitter",
    opts = function(_, opts)
      local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
      parser_config.rune = {
        install_info = {
          url = "https://somegit.dev/vikingowl/tree-sitter-rune",
          files = { "src/parser.c", "src/scanner.c" },
          branch = "main",
        },
        filetype = "rune",
      }
      vim.treesitter.language.register("rune", "rune")
    end,
  },
}

Then run :TSInstall rune and copy the query files as shown above.

Formatter Integration (optional)

Rune ships a built-in formatter (rune fmt) since v0.13. Install the CLI first:

cargo install rune-cli

conform.nvim

require("conform").setup({
  formatters_by_ft = {
    rune = { "rune_fmt" },
  },
  formatters = {
    rune_fmt = {
      command = "rune",
      args = { "fmt", "$FILENAME" },
      stdin = false,
    },
  },
})

none-ls (null-ls)

local null_ls = require("null-ls")
local h = require("null-ls.helpers")

local rune_fmt = h.make_builtin({
  name = "rune_fmt",
  method = null_ls.methods.FORMATTING,
  filetypes = { "rune" },
  generator_opts = {
    command = "rune",
    args = { "fmt", "$FILENAME" },
    to_temp_file = true,
    from_temp_file = true,
  },
  factory = h.formatter_factory,
})

Development

Prerequisites

Build

npm install
npx tree-sitter generate

Test

npx tree-sitter test

Parse a file

npx tree-sitter parse path/to/file.rn

Preview highlighting

npx tree-sitter highlight path/to/file.rn

Query Files

File Purpose
queries/highlights.scm Syntax highlighting
queries/indents.scm Auto-indentation
queries/folds.scm Code folding
queries/locals.scm Scope/variable tracking
queries/tags.scm Code navigation (definitions, references)

License

MIT

Description
No description provided
Readme MIT 294 KiB
Languages
C 97%
JavaScript 1.5%
C++ 1%
Scheme 0.3%
Rust 0.1%