Crate beancount_parser

source ·
Expand description

A rust parsing library for beancount files

At its core, this library provides is a Parser type that is an iterator over the directives.

Example

use beancount_parser::{Directive, Parser, Error};

let beancount = r#"
2022-09-11 * "Coffee beans"
  Expenses:Groceries   10 CHF
  Assets:Bank
"#;

let directives: Vec<Directive<'_>> = Parser::new(beancount).collect::<Result<_, _>>()?;
let transaction = directives[0].as_transaction().unwrap();
assert_eq!(transaction.narration(), Some("Coffee beans"));

let first_posting_amount = transaction.postings()[0].amount().unwrap();
assert_eq!(first_posting_amount.currency(), "CHF");
assert_eq!(first_posting_amount.value().try_into_f64()?, 10.0);

Re-exports

Modules

Structs

Enums