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
pub use crate::account::Account;pub use crate::account::Type;pub use crate::amount::Amount;pub use crate::transaction::Transaction;
Modules
- Types for representing an
Account - Types for representing an
Amount - Types for representing an
Transaction
Structs
- Account balance assertion directive
- The close account directive
- A date
- Main error type
- Include directive
- Open account directive
- Padding directive
- Parser of a beancount document
- A price directive
Enums
- A directive