Drop counterparty, the generic parsers and .money/

counterparty was a structured field only nlb could fill honestly. revolut
and traderepublic invented one by running an IBAN-shaped regex over the
description they had just built, and the two spellings disagreed --
SI56 1234 5678 9012 345 against SI56123456789012345 -- so a literal rule
pattern that worked on one account silently matched nothing on another. It
is gone from the model, the index, the rule keys, ls --wide and the rules
screen. nlb now appends its IBAN column to the end of the description,
where the other two already keep theirs, so match = "*SI56*" works
everywhere. That changes those descriptions and with them their
fingerprints, so a statement overlapping an already-imported period will
re-add rather than dedupe those rows until the index is rebuilt. An index
built by an older binary drops the column when it is opened.

The index itself moves from .money/index.db up to index.db beside
rules.toml. Nothing looks in the old location, so an existing one has to be
moved by hand -- otherwise the tool quietly starts a fresh index and the
manual tags in the old file, the only thing statements cannot reproduce,
stay behind in it.

The csv and cmd parsers are gone along with the [csv] and [cmd] config they
carried. cmd shelled out to the Python extractors, which were ported to Go
and deleted, so it bridged to nothing; csv was a generic column-mapped
fallback that no account used, and between them they were the largest
configuration surface in the tool. A bank is now described in Go, where it
can be tested. The importer tests register their own three-column parser
rather than borrow a bank's, so they stay about the directory walk, dedupe
and per-file error reporting.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-11 22:51:20 +02:00
co-authored by Claude Opus 5
parent 2a2c0c1db9
commit 16c2585637
23 changed files with 182 additions and 627 deletions
+19 -12
View File
@@ -18,8 +18,8 @@ func init() {
// nlbParser reads an NLB izpisek PDF.
//
// A transaction starts on a line beginning with a dd.mm.yy date and ends with
// the signed amount and the running balance. Long descriptions and the
// counterparty account wrap onto indented continuation lines below.
// the signed amount and the running balance. Long descriptions and the other
// side's account number wrap onto indented continuation lines below.
type nlbParser struct {
digits int
}
@@ -37,7 +37,9 @@ var (
`(?P<balance>[-\x{2212}]?[\d.,]+[-\x{2212}]?)\s*$`)
// Columns inside a line are separated by four or more spaces.
nlbFieldSplit = regexp.MustCompile(`\s{4,}`)
// A Slovenian IBAN, which is the counterparty account when present.
// A Slovenian IBAN, which NLB prints in a column of its own. It is split
// out only so that its wrapped fragments can be rejoined; the result goes
// onto the end of the description, where every other parser keeps it.
nlbAccount = regexp.MustCompile(`^SI\d{2}(?:\s?\d{4}){3}\s?\d{3}$`)
)
@@ -63,9 +65,12 @@ func (p *nlbParser) Parse(path string, acc *config.Account) ([]RawTxn, error) {
// be tested against captured pdftotext output.
func parseNLBText(text string, digits int) ([]RawTxn, error) {
var (
txns []RawTxn
accts []string // counterparty per transaction, built up alongside
descAt int // description column of the last transaction line
txns []RawTxn
// The account column per transaction, built up alongside because it
// wraps in fragments of its own and has to be rejoined before it can
// be appended to the description.
trailing []string
descAt int // description column of the last transaction line
)
for _, page := range pages(text) {
@@ -84,7 +89,7 @@ func parseNLBText(text string, digits int) ([]RawTxn, error) {
return nil, fmt.Errorf("line %d: %w", i+1, err)
}
txns = append(txns, txn)
accts = append(accts, account)
trailing = append(trailing, account)
descAt = col
continue
}
@@ -104,20 +109,22 @@ func parseNLBText(text string, digits int) ([]RawTxn, error) {
last := len(txns) - 1
txns[last].Description += " " + parts[0]
if len(parts) > 1 {
accts[last] = strings.TrimSpace(accts[last] + " " + parts[1])
trailing[last] = strings.TrimSpace(trailing[last] + " " + parts[1])
}
}
}
// The account column goes last rather than in the position it occupied on
// the page, so that an IBAN wrapped over several lines stays contiguous
// and a glob can match it.
for i := range txns {
txns[i].Counterparty = accts[i]
txns[i].Description = strings.Join(strings.Fields(txns[i].Description), " ")
txns[i].Description = strings.Join(strings.Fields(txns[i].Description+" "+trailing[i]), " ")
}
return txns, nil
}
// parseNLBLine parses one transaction line, returning the transaction, the
// counterparty account found among its columns, and the column at which the
// account number found among its columns, and the column at which the
// description starts, which is where its wrapped lines will sit.
func parseNLBLine(line string, digits int) (RawTxn, string, int, error) {
trimmed := strings.TrimRight(line, " \t\r")
@@ -154,7 +161,7 @@ func parseNLBLine(line string, digits int) (RawTxn, string, int, error) {
return RawTxn{}, "", 0, fmt.Errorf("balance %q: %w", balance, err)
}
// The middle holds the description and, sometimes, the counterparty IBAN.
// The middle holds the description and, sometimes, the IBAN.
var (
account string
desc []string