Crate deb822_lossless

source ·
Expand description

Lossless parser for deb822 style files.

This parser can be used to parse files in the deb822 format, while preserving all whitespace and comments. It is based on the rowan library, which is a lossless parser library for Rust.

Once parsed, the file can be traversed or modified, and then written back to a file.

§Example

use deb822_lossless::Deb822;
use std::str::FromStr;

let input = r#"Package: deb822-lossless
Maintainer: Jelmer Vernooij <jelmer@debian.org>
Homepage: https://github.com/jelmer/deb822-lossless
Section: rust

Package: deb822-lossless
Architecture: any
Description: Lossless parser for deb822 style files.
  This parser can be used to parse files in the deb822 format, while preserving
  all whitespace and comments. It is based on the [rowan] library, which is a
  lossless parser library for Rust.
"#;

let deb822 = Deb822::from_str(input).unwrap();
assert_eq!(deb822.paragraphs().count(), 2);
let homepage = deb822.paragraphs().nth(0).unwrap().get("Homepage");
assert_eq!(homepage.as_deref(), Some("https://github.com/jelmer/deb822-lossless"));

Structs§

Enums§

  • Second, implementing the Language trait teaches rowan to convert between these two SyntaxKind types, allowing for a nicer SyntaxNode API where “kinds” are values from our enum SyntaxKind, instead of plain u16 values.
  • Let’s start with defining all kinds of tokens and composite nodes.