Skip to main content

Crate rpm_spec

Crate rpm_spec 

Source
Expand description

Parser and pretty-printer for RPM .spec files.

This crate exposes a distribution-independent AST suitable for tooling such as formatters, linters, and static analyzers. Macros are preserved as AST nodes (never expanded), so consumers can inspect or rewrite the source without losing structural information.

§Overview

§Crate layout

§Cargo features

The default feature set is ["parser", "printer"]. Every feature is additive.

FeatureDefaultEffect
parseryesCompiles the parser module and its entry points. Pulls in nom.
printeryesCompiles the printer module. No extra dependencies.
serdenoDerives Serialize / Deserialize on the AST, diagnostics and config types.
tracingnoAdds #[tracing::instrument] on hot-path parser entry points.

§Quick start

Parse a spec, inspect diagnostics, and round-trip back to source:

use rpm_spec::{parser, printer};

let src = "Name:           foo\nVersion:        1.0\n";
let result = parser::parse_str_with_spans(src);
assert!(result.diagnostics.is_empty());

let printed = printer::print(&result.spec);
assert!(printed.contains("Name:"));

§Generic T parameter

Every “large” AST node carries a data: T field; the root is ast::SpecFile<T>. T defaults to (). parser::parse_str returns parse_result::ParseResult<()>, while parser::parse_str_with_spans populates T with ast::Span (byte offset plus 1-based line and column at both ends). Validators may choose a richer type to thread their own per-node data (resolved macro values, validator diagnostic ids, …) and map between representations.

§Macro names are verbatim

ast::MacroRef::name, ast::MacroDef::name, ast::BuildCondition::name, and the Other variants of ast::Tag, ast::TagQualifier, and ast::BuiltinMacro preserve the exact text written in the source — case is not normalised. This invariant exists so that downstream validators can match names against distribution-specific registries.

§Crate-level lints

The crate is #![forbid(unsafe_code)] (no unsafe blocks anywhere) and #![deny(missing_docs)] (every public item must be documented).

Modules§

ast
Abstract syntax tree for RPM .spec files.
error
Fatal error types for the parser and printer.
parse_result
Result type and diagnostics returned by the parser.
parser
RPM .spec parser.
printer
Pretty-printer that renders a crate::ast::SpecFile back into spec source text.