Skip to main content

parse_multi_file

Function parse_multi_file 

Source
pub fn parse_multi_file(
    files: JsValue,
    entry_point: &str,
) -> Result<JsValue, JsError>
Expand description

Parse multiple Beancount files with include resolution.

This function accepts a map of file paths to file contents and an entry point, resolving include directives across the files. This enables multi-file ledgers in WASM environments where filesystem access is not available.

§Arguments

  • files - A JavaScript object mapping file paths to their contents. Example: { "main.beancount": "include \"accounts.beancount\"", "accounts.beancount": "..." }
  • entry_point - The main file to start loading from (must exist in files).

§Returns

A ParseResult with the parsed ledger from all files and any errors.

§Example (JavaScript)

const result = parseMultiFile({
  "main.beancount": `
    include "accounts.beancount"
    2024-01-15 * "Coffee"
      Expenses:Food  5.00 USD
      Assets:Bank
  `,
  "accounts.beancount": `
    2024-01-01 open Assets:Bank USD
    2024-01-01 open Expenses:Food USD
  `
}, "main.beancount");