Skip to main content

Crate doppio

Crate doppio 

Source
Expand description

doppio – a compiler and query library for the Ledger plain-text accounting format.

§.dop binary format

The dop compile command serialises an elaborated journal to a .dop file. The file begins with an 8-byte header followed by the payload:

Offset  Length  Content
0       4       Magic: b"DOP\0"
4       2       Format version: u16 LE (currently 3)
6       1       Compression: u8  (0 = none, 1 = deflate)
7       1       Reserved (write 0, ignore on read)
8       N       Payload (protobuf, optionally deflate-compressed per byte 6)

Use write_dop / read_dop for the full header + (optional) compression + protobuf round-trip.

§Pipeline

Source text is processed through four stages:

source text
  → [parser]      ast::Journal        (PEG grammar + Pratt expressions)
  → [resolution]  resolution::HIR     (dates, aliases, metadata)
  → [elaboration] elaboration::Journal (evaluation, balancing)
  → serialisation                     (protobuf + optional deflate → .dop)

The top-level entry point is compile, which runs all three in-memory stages and returns the elaborated Journal. For CLI usage see the dop binary in src/main.rs.

§Modules

  • frontend – the Frontend trait for pluggable file-format support.
  • grammars – grammar implementations (grammars::ledger for ledger-cli, grammars::hledger for hledger).
  • resolution – alias resolution, date normalisation, metadata extraction.
  • elaboration – prost-generated Protocol Buffers types (Journal, Transaction, Posting, Amount, Decimal); this is the canonical read-side public surface and the wire shape of .dop bodies.

§Serialising transactions as Ledger text

Use write_ledger to serialise a sequence of resolution::Transaction values back to canonical Ledger source text:

let txns = vec![
    Transaction::new(NaiveDate::from_ymd_opt(2024, 1, 15).unwrap(), "Groceries")
        .with_posting(Posting::new("Expenses:Food").with_amount((
            rust_decimal::Decimal::from(50u32), "$",
        )))
        .with_posting(Posting::new("Assets:Checking")),
];
let mut out = Vec::new();
doppio::write_ledger(txns, &mut out).unwrap();

Re-exports§

pub use elaboration::Journal;
pub use frontend::Frontend;
pub use grammars::beancount::BeancountFrontend;
pub use grammars::hledger::HledgerFrontend;
pub use grammars::ledger::LedgerFrontend;

Modules§

ast
Abstract Syntax Tree (AST) for the Ledger file format.
elaboration
Prost-generated Protocol Buffers types – canonical wire shape of .dop bodies.
frontend
The Frontend trait – the extension point for pluggable file-format support.
grammars
Grammar implementations for each supported file format.
resolution
Resolution stage: convert an ast::Journal into the Higher-level Intermediate Representation (HIR).

Structs§

Amount
A multi-commodity amount: a map from commodity symbol to a Decimal value.

Enums§

Compression
Compression algorithm used in the .dop payload.
ElaborationError
Errors that can occur during the elaboration stage.
EvaluationError
Error produced when evaluating a value expression (e.g., an amount or balance assertion expression) fails.

Functions§

compile
Compile Ledger source text into a fully elaborated Journal.
elaborate
Run the elaboration stage on a resolved resolution::HIR under the given resolution::ElaborationConfig, producing a fully-balanced elaboration::Journal.
eval_transaction
Evaluate a single resolution::Transaction through the elaboration stage.
file_opener
Load and concatenate all files matching a glob pattern.
frontend_for_extension
Select a frontend by file extension.
read_dop
Deserialise a .dop file from reader into a Journal.
write_dop
Serialise journal to writer as a complete .dop file (8-byte header + optional deflate + protobuf body).
write_ledger
Write a sequence of resolution::Transaction values to writer in canonical Ledger source text format.