Queries
The queries/ directory contains portable Tree-sitter queries. They use common capture names and
avoid predicates tied to a particular host.
Highlighting
Section titled “Highlighting”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.pathThe 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.
Shell injection
Section titled “Shell injection”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.
Folding
Section titled “Folding”queries/folds.scm marks complete rotation blocks and script blocks:
[ (rotation_block) (script_block)] @foldA host may translate @fold to a native capture name or reuse it directly.
Package access
Section titled “Package access”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.
Validate changes
Section titled “Validate changes”Run the parser and highlight checks after changing a node or query:
npm run test:parsernpm run test:highlightnpm run test:nodeThe highlight test rejects invalid captures and patterns. Node tests confirm the expected query matches and syntax tree.