|
@@ -9,13 +9,12 @@ pub use rust_decimal::Decimal;
|
|
|
|
|
|
use crate::prelude::*;
|
|
use crate::prelude::*;
|
|
|
|
|
|
-pub mod spec;
|
|
|
|
-
|
|
|
|
|
|
+mod format;
|
|
mod parse;
|
|
mod parse;
|
|
-pub use parse::parse_ledger;
|
|
|
|
|
|
+pub mod spec;
|
|
|
|
|
|
-mod format;
|
|
|
|
pub use format::format_ledger;
|
|
pub use format::format_ledger;
|
|
|
|
+pub use parse::parse_ledger;
|
|
|
|
|
|
pub struct UnitTag;
|
|
pub struct UnitTag;
|
|
impl stringstore::NamespaceTag for UnitTag {
|
|
impl stringstore::NamespaceTag for UnitTag {
|
|
@@ -50,6 +49,8 @@ impl std::fmt::Debug for Datestamp {
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq)]
|
|
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq)]
|
|
pub struct Change {
|
|
pub struct Change {
|
|
|
|
+ pub source: Option<io::Span>,
|
|
|
|
+
|
|
pub account: Spanned<AccountName>,
|
|
pub account: Spanned<AccountName>,
|
|
pub amount: Spanned<Decimal>,
|
|
pub amount: Spanned<Decimal>,
|
|
pub balance: Option<Spanned<Decimal>>,
|
|
pub balance: Option<Spanned<Decimal>>,
|
|
@@ -58,10 +59,12 @@ pub struct Change {
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
|
|
#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
|
|
pub struct Transaction {
|
|
pub struct Transaction {
|
|
|
|
+ pub source: Option<io::Span>,
|
|
|
|
+
|
|
pub datestamp: Datestamp,
|
|
pub datestamp: Datestamp,
|
|
pub title: Option<String>,
|
|
pub title: Option<String>,
|
|
pub annotations: Vec<String>,
|
|
pub annotations: Vec<String>,
|
|
- pub changes: Vec<Spanned<Change>>,
|
|
|
|
|
|
+ pub changes: Vec<Change>,
|
|
}
|
|
}
|
|
|
|
|
|
impl Transaction {
|
|
impl Transaction {
|
|
@@ -69,14 +72,14 @@ impl Transaction {
|
|
self.changes.iter().any(|b| b.account.as_ref() == &account)
|
|
self.changes.iter().any(|b| b.account.as_ref() == &account)
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn change_for(&self, account: AccountName) -> Option<&Spanned<Change>> {
|
|
|
|
|
|
+ pub fn change_for(&self, account: AccountName) -> Option<&Change> {
|
|
self.changes.iter().find(|b| b.account.as_ref() == &account)
|
|
self.changes.iter().find(|b| b.account.as_ref() == &account)
|
|
}
|
|
}
|
|
|
|
|
|
pub fn split_changes(
|
|
pub fn split_changes(
|
|
&self,
|
|
&self,
|
|
account: AccountName,
|
|
account: AccountName,
|
|
- ) -> Option<(&Spanned<Change>, impl Iterator<Item = &Spanned<Change>>)> {
|
|
|
|
|
|
+ ) -> Option<(&Change, impl Iterator<Item = &Change>)> {
|
|
let index = self
|
|
let index = self
|
|
.changes
|
|
.changes
|
|
.iter()
|
|
.iter()
|