d1e6f6a4cbf082cb76774918d0c6fae2e33b12ff
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,matchwith 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
selectblocks is/is nottype checking- Macro invocations (
println!())
Installation
Neovim (nvim-treesitter)
Add a custom parser in your Neovim config:
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.rune = {
install_info = {
url = "https://github.com/TODO/tree-sitter-rune",
files = { "src/parser.c", "src/scanner.c" },
branch = "main",
},
filetype = "rune",
}
vim.filetype.add({
extension = {
rn = "rune",
},
})
Then run :TSInstall rune.
Formatter Integration
Rune ships a built-in formatter (rune fmt) since v0.13. To integrate with conform.nvim:
require("conform").setup({
formatters_by_ft = {
rune = { "rune_fmt" },
},
formatters = {
rune_fmt = {
command = "rune",
args = { "fmt", "$FILENAME" },
stdin = false,
},
},
})
Development
Prerequisites
- Node.js (v18+)
- tree-sitter CLI (
cargo install tree-sitter-cliornpm i -g tree-sitter-cli) - C compiler
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
Languages
C
97%
JavaScript
1.5%
C++
1%
Scheme
0.3%
Rust
0.1%