Skip to main content

Module dcf

Module dcf 

Source
Expand description

A lossless CST parser for DCF (Debian Control Format) — R’s DESCRIPTION format.

This is a second grammar in this crate, independent of the R one. It exists because DESCRIPTION is not just a bag of facts to scrape: it wants spans (for diagnostics), record structure, and byte-for-byte round-tripping (for formatting).

  • syntax — SyntaxKind, DcfLanguage, and the node/token aliases.
  • parser — parse, reconstruct, and ParseOutput.
  • ast — typed wrappers; the way to read a document from outside this module, so no consumer ever has to name the second SyntaxKind.

Losslessness holds exactly as it does for the R grammar: reconstruct(text) == text, byte for byte. Errors never abort the parse — diagnostics ride a side channel and every byte stays in the tree.

use arity_parser::dcf;

let output = dcf::parse("Package: mypkg\nDepends: R (>= 4.1.0)\n");
let value = output.document().field("Depends").unwrap().folded_value();
assert_eq!(value, "R (>= 4.1.0)");

Two SyntaxKind enums now exist in this crate. They are distinct types sharing a name, disambiguated by module path — never glob-import both.

Re-exports§

pub use ast::CommentLine;
pub use ast::Document;
pub use ast::Field;
pub use ast::MalformedLine;
pub use ast::Record;
pub use ast::ValueLine;
pub use deps::DEPENDENCY_FIELDS;
pub use deps::DependencyEntry;
pub use deps::VersionConstraint;
pub use deps::VersionOp;
pub use deps::dependency_entries;
pub use deps::is_dependency_field;
pub use parser::ParseOutput;
pub use parser::parse;
pub use parser::reconstruct;
pub use syntax::DcfLanguage;
pub use syntax::SyntaxElement;
pub use syntax::SyntaxKind;
pub use syntax::SyntaxNode;
pub use syntax::SyntaxToken;
pub use crate::parser::ParseDiagnostic;

Modules§

ast
Zero-cost typed wrappers over the DCF CST, in the same mould as crate::ast.
deps
The dependency-field grammar: name (>= version), name, ....
parser
The DCF parser: one forward pass over physical lines.
syntax
The DCF grammar’s node kinds and its rowan language definition.