Rust library for parsing Ledger-cli input files.
Only a subset of the ledger-cli's file format is implemented.
Supported elements:
-
Line comments (starting with:
; # % | *
) -
Inline comments (starting with
;
) -
Transaction headers with format:
DATE[=EDATE] [*|!] [(CODE)] DESC
-
Transaction postings with format (minimum two spaces or one tab between
ACCOUNT
andAMOUNT
):ACCOUNT [AMOUNT] [= BALANCE] [; NOTE]
There may be only a single posting without an amount or balance in a transaction.
-
Commodity prices with format:
P DATE SYMBOL PRICE
Parsing:
let ledger = ledger_parser::parse(r#"; Example 1
2018-10-01=2018-10-14 ! (123) Description
; Transaction comment
TEST:Account 123 $1.20
; Posting comment
TEST:Account 345 -$1.20"#);
Serializing:
use ledger_parser::{ Serializer, SerializerSettings };
println!("{}", ledger);
println!("{}", ledger.to_string_pretty(&SerializerSettings::with_indent("\t")));