|
@@ -13,7 +13,7 @@ mod format;
|
|
mod parse;
|
|
mod parse;
|
|
pub mod spec;
|
|
pub mod spec;
|
|
|
|
|
|
-pub use format::format_ledger;
|
|
|
|
|
|
+pub use format::{format_ledger,format_entire_ledger};
|
|
pub use parse::parse_ledger;
|
|
pub use parse::parse_ledger;
|
|
|
|
|
|
pub struct UnitTag;
|
|
pub struct UnitTag;
|
|
@@ -115,7 +115,7 @@ impl Transaction {
|
|
pub type TransactionRef = std::rc::Rc<std::cell::RefCell<Transaction>>;
|
|
pub type TransactionRef = std::rc::Rc<std::cell::RefCell<Transaction>>;
|
|
|
|
|
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
|
-enum RawLedgerEntry {
|
|
|
|
|
|
+pub enum RawLedgerEntry {
|
|
Transaction(Transaction),
|
|
Transaction(Transaction),
|
|
Comment(Spanned<String>),
|
|
Comment(Spanned<String>),
|
|
}
|
|
}
|
|
@@ -157,16 +157,16 @@ impl LedgerEntry {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn as_transaction_mut(&mut self) -> Option<&mut Transaction> {
|
|
|
|
|
|
+ /*pub fn as_transaction_mut(&mut self) -> Option<&mut Transaction> {
|
|
match self {
|
|
match self {
|
|
Self::Transaction(tx) => Some(tx),
|
|
Self::Transaction(tx) => Some(tx),
|
|
_ => None,
|
|
_ => None,
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
pub fn span(&self) -> io::Span {
|
|
pub fn span(&self) -> io::Span {
|
|
match self {
|
|
match self {
|
|
- Self::Transaction(ts) => ts.source.unwrap_or_default(),
|
|
|
|
|
|
+ Self::Transaction(ts) => ts.borrow().source.unwrap_or_default(),
|
|
Self::Comment(c) => c.span(),
|
|
Self::Comment(c) => c.span(),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -181,7 +181,7 @@ pub struct Hoard {
|
|
|
|
|
|
raw_ledger_data: Vec<RawLedgerEntry>,
|
|
raw_ledger_data: Vec<RawLedgerEntry>,
|
|
|
|
|
|
- account_ledger_data: HashMap<AccountName, Vec<Transaction>>,
|
|
|
|
|
|
+ account_ledger_data: HashMap<AccountName, Vec<TransactionRef>>,
|
|
}
|
|
}
|
|
|
|
|
|
impl Hoard {
|
|
impl Hoard {
|
|
@@ -288,41 +288,38 @@ impl Hoard {
|
|
|
|
|
|
fn preprocess_ledger_data(&mut self) {
|
|
fn preprocess_ledger_data(&mut self) {
|
|
for entry in &self.raw_ledger_data {
|
|
for entry in &self.raw_ledger_data {
|
|
- let RawLedgerEntry::Transaction(tx) = &entry else {
|
|
|
|
- continue;
|
|
|
|
|
|
+ let tx = match entry {
|
|
|
|
+ RawLedgerEntry::Transaction(tx) => tx,
|
|
|
|
+ RawLedgerEntry::Comment(c) => {
|
|
|
|
+ self.comments.push(c.clone());
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+ let txn_ref = std::rc::Rc::new(std::cell::RefCell::new(tx.clone()));
|
|
for bal in &tx.changes {
|
|
for bal in &tx.changes {
|
|
self.account_ledger_data
|
|
self.account_ledger_data
|
|
.entry(*bal.account)
|
|
.entry(*bal.account)
|
|
.or_default()
|
|
.or_default()
|
|
- .push(tx.clone());
|
|
|
|
|
|
+ .push(txn_ref.clone());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn all_ledger_data(&self) -> &[LedgerEntry] {
|
|
|
|
- self.ledger_data.as_slice()
|
|
|
|
|
|
+ pub fn all_raw_ledger_data(&self) -> &[RawLedgerEntry] {
|
|
|
|
+ self.raw_ledger_data.as_slice()
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn all_ledger_data_mut(&mut self) -> &mut [LedgerEntry] {
|
|
|
|
- self.ledger_data.as_mut_slice()
|
|
|
|
|
|
+ pub fn all_raw_ledger_data_mut(&mut self) -> &mut [RawLedgerEntry] {
|
|
|
|
+ self.raw_ledger_data.as_mut_slice()
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn ledger_data_for(&self, aname: AccountName) -> Option<&[Transaction]> {
|
|
|
|
|
|
+ pub fn ledger_data_for(&self, aname: AccountName) -> Option<&[TransactionRef]> {
|
|
self.account_ledger_data.get(&aname).map(Vec::as_slice)
|
|
self.account_ledger_data.get(&aname).map(Vec::as_slice)
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn ledger_data_for_mut(
|
|
|
|
- &mut self,
|
|
|
|
- aname: AccountName,
|
|
|
|
- ) -> Option<&mut [Transaction]> {
|
|
|
|
- self.account_ledger_data
|
|
|
|
- .get_mut(&aname)
|
|
|
|
- .map(Vec::as_mut_slice)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- pub fn ledger_data_from(&self, source: io::SourceFile) -> impl Iterator<Item = &LedgerEntry> {
|
|
|
|
- self.all_ledger_data()
|
|
|
|
|
|
+ pub fn raw_ledger_data_from(&self, source: io::SourceFile) -> impl Iterator<Item = &RawLedgerEntry> {
|
|
|
|
+ self.all_raw_ledger_data()
|
|
.iter()
|
|
.iter()
|
|
.filter(move |le| le.span().context == Some(source))
|
|
.filter(move |le| le.span().context == Some(source))
|
|
}
|
|
}
|
|
@@ -347,7 +344,7 @@ impl Hoard {
|
|
let mut running = HashMap::<UnitName, Decimal>::new();
|
|
let mut running = HashMap::<UnitName, Decimal>::new();
|
|
|
|
|
|
for le in self.ledger_data_for(aname)? {
|
|
for le in self.ledger_data_for(aname)? {
|
|
- for b in &le.changes {
|
|
|
|
|
|
+ for b in &le.borrow().changes {
|
|
if *b.account != aname {
|
|
if *b.account != aname {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|