Skip to content

Queries

The queries/ directory contains portable Tree-sitter queries. They use common capture names and avoid predicates tied to a particular host.

queries/highlights.scm captures comments, paths, quoted values, escapes, numbers, user and group arguments, braces, operators, and directive names. Known Logrotate directives use @keyword; an unknown directive uses @property. User and group arguments for create, createolddir, and su use @variable.parameter.

((directive
name: (directive_name) @keyword)
(#match? @keyword "^(daily|weekly|monthly|rotate|compress)$"))
[
(path_pattern)
(quoted_path)
] @string.special.path

The repository’s full query contains the complete reviewed directive set. Copy the file unchanged when a host supports the standard captures, then add refinements in the host integration.

queries/injections.scm assigns Bash to script_body:

((script_body) @injection.content
(#set! injection.language "bash"))

Only the body is injected. The opening directive and endscript remain Logrotate syntax. The parser does not execute the captured text.

queries/folds.scm marks complete rotation blocks and script blocks:

[
(rotation_block)
(script_block)
] @fold

A host may translate @fold to a native capture name or reuse it directly.

The npm package exports the query files through tree-sitter-logrotate/queries/*. Node and Python bindings also expose highlight and injection query strings when their binding generator supports those constants. Rust includes query constants behind the corresponding build configuration.

Copy queries into the host runtime layout. Pin the grammar commit and query files together because query node names form part of the compatibility contract.

Run the parser and highlight checks after changing a node or query:

Terminal window
npm run test:parser
npm run test:highlight
npm run test:node

The highlight test rejects invalid captures and patterns. Node tests confirm the expected query matches and syntax tree.