ExLedger.Parser.Accounts (ex_ledger v0.5.6)

Account declaration parsing and alias resolution.

Summary

Functions

Extracts account declarations from ledger input.

Parses an account declaration line.

Resolves an account name or alias to the canonical account name.

Resolves all account names in transactions from aliases to canonical names.

Functions

extract_account_declarations(input)

@spec extract_account_declarations(String.t()) :: %{
  required(String.t()) => atom() | String.t()
}

Extracts account declarations from ledger input.

Returns a map where:

  • Keys are account names, values are atoms (:asset, :expense, etc.) for declared accounts
  • Keys are alias names, values are strings (target account) for aliases

parse_account_declaration(input)

@spec parse_account_declaration(String.t()) ::
  {:ok, ExLedger.Parser.Core.account_declaration()}
  | {:error, :invalid_account_declaration | :invalid_account_type}

Parses an account declaration line.

resolve_account_name(account_name, account_map)

@spec resolve_account_name(String.t(), %{required(String.t()) => atom() | String.t()}) ::
  String.t()

Resolves an account name or alias to the canonical account name.

resolve_transaction_aliases(transactions, account_map)

@spec resolve_transaction_aliases([ExLedger.Parser.Core.transaction()], %{
  required(String.t()) => atom() | String.t()
}) :: [ExLedger.Parser.Core.transaction()]

Resolves all account names in transactions from aliases to canonical names.

Note: This function is now called automatically by ExLedger.LedgerParser.parse_ledger/2, so you typically don't need to call it manually. It remains public for cases where you need to re-resolve aliases or are working with transactions from other sources.