9858bd9f1e74e4d770438c01ba6875e34438764b — Chris Waldon 1 year, 4 days ago 8b8bd21 master
ledger: add method to parse io.ReadCloser with name

I already have an open file, but I want to be able to resolve includes
easily relative to the file. This adds a function that invokes the
parser correctly for that scenario.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
1 files changed, 19 insertions(+), 1 deletions(-)

M parse.go
M parse.go => parse.go +19 -1
@@ 12,8 12,8 @@ import (

	date "github.com/joyt/godate"

@@ 54,6 54,24 @@ func ParseLedger(ledgerReader io.Reader) (generalLedger []*Transaction, err erro

// ParseNamedLedger parses a ledger file from a reader assuming that it was loaded
// from the path in name. It will search for included ledger files relative to the
// given path.
func ParseNamedLedger(name string, ledgerReader io.Reader) (generalLedger []*Transaction, err error) {
	parseLedger(name, ledgerReader, func(t *Transaction, e error) (stop bool) {
		if e != nil {
			err = e
			stop = true

		generalLedger = append(generalLedger, t)


// ParseLedgerAsync parses a ledger file and returns a Transaction and error channels .
func ParseLedgerAsync(ledgerReader io.Reader) (c chan *Transaction, e chan error) {
	c = make(chan *Transaction)