0.1.0 |
|
---|
#7 in #parser-implementations
26KB
713 lines
opam-file-rs: Parser and printer for the opam file syntax with Rust
Parsing OPAM
Parse OPAM file.
use opam_file_rs;
fn main () {
let opam = r#"
opam-verion: "2.0"
version: "0.1.0"
name: "opam-file-rs"
dev-repo: "git+https://github.com/puripuri2100/opam-file-rs"
license: "MIT"
maintainer: "Naoki Kaneko <puripuri2100@gmail.com>"
depends: [
"lalrpop-util" {>= "0.19.4"}
"thiserror" {>= "1.0.23"}
]
"#;
assert!(opam_file_rs::parse(opam).is_ok());
}
Convert to a OPAM file format.
A data structure can be converted to an OPAM file format by value::format_opam_file
.
use opam_file_rs;
fn main() {
let opam_str = r#"
opam-verion: "2.0"
version: "0.1.0"
name: "opam-file-rs"
dev-repo: "git+https://github.com/puripuri2100/opam-file-rs"
license: "MIT"
maintainer: "Naoki Kaneko <puripuri2100@gmail.com>"
depends: [
"lalrpop-util" {>= "0.19.4"}
"thiserror" {>= "1.0.23"}
]
"#;
let opam = opam_file_rs::parse(opam_str).unwrap();
println!("{}", opam_file_rs::value::format_opam_file(opam));
}
(c) 2021 Naoki Kaneko (a.k.a. "puripuri2100")
Dependencies
~0.3–2.5MB
~42K SLoC