tree-sitter-logrotate
tree-sitter-logrotate parses logrotate configuration and state files with Tree-sitter. The configuration grammar recognizes global directives, rotation stanzas, path lists, comments, includes, quoted arguments, and all five raw script blocks. The state grammar recognizes version 1 and version 2 headers, quoted paths, and timestamps. Script text is preserved as scriptbody and is never executed.
The committed parser uses Tree-sitter language ABI 15. The reviewed syntax baseline is logrotate revision 3be1e9ccffe0c2245ed596183c74913d553f9f18, which includes the logrotate 3.22 syntax reviewed for the first release.
The user and integration documentation covers package setup, syntax trees, portable queries, editor setup, and compatibility.
Consumers
The repository publishes both generated parsers through C source, npm, PyPI, crates.io, Maven Central, Go, Swift Package Manager, Zig, and standalone WASM artifacts. Configuration highlight, shell-injection, and fold queries live in queries/; the state highlight query lives in src/state/queries/.
The editor setup guide covers Neovim, Helix, and Zed. Each setup pins both parsers and their queries to one grammar revision.
Neovim
Neovim 0.12.0 or newer, the current main branch of nvim-treesitter, the Tree-sitter CLI, and a C compiler are required. Native vim.pack users can add both packages in init.lua:
Native vim.pack
vim.api.nvim_create_autocmd("PackChanged", {
callback = function(event)
local name, kind = event.data.spec.name, event.data.kind
if name == "tree-sitter-logrotate" and (kind == "install" or kind == "update") then
vim.cmd.source(vim.fs.joinpath(event.data.path, "build.lua"))
end
end,
})
vim.pack.add({
{
src = "https://github.com/nvim-treesitter/nvim-treesitter",}, }, { load = true })
vim.pack.add({ { src = "https://github.com/willibrandon/tree-sitter-logrotate", version = vim.version.range("0.2"), }, }, { load = true })
### LazyVim
Create `lua/plugins/logrotate.lua`:
return { { "willibrandon/tree-sitter-logrotate", version = "", dependencies = { "nvim-treesitter/nvim-treesitter" }, }, }
Both installations compile the configuration and state parsers plus the Bash parser used inside
script blocks. Run `:checkhealth tree-sitter-logrotate` after restarting Neovim.
### Usage
Open `logrotate.conf`, a direct child of `logrotate.d`, `*.logrotate`, `*.logrotate.conf`,
`logrotate.status`, or `logrotate/status`. The plugin also recognizes complete first-line stanzas,
state headers, and files reached through an `include` from an open configuration.
Configuration buffers provide Tree-sitter highlighting, Bash highlighting inside all five script
blocks, indentation, folding, `#` comments, `%` matching between script directives and `endscript`,uses the same source automatically; use CTRL-Y to accept a selected directive and Enter to insert an indented newline.
Use :LogrotateInstall, :LogrotateUpdate, and :LogrotateUninstall to manage the two parsers. Use :checkhealth tree-sitter-logrotate to verify the complete installation.