lp
ledger-parser
cargo install ledger-parser
lp

ledger-parser

Rust library for parsing ledger cli (https://www.ledger-cli.org/) input files.

by Marek Gibek

5.1.1 (see all)License:Unlicense
cargo install ledger-parser
Readme

ledger-parser

Crates.io Version Docs.rs Version License Unlicense

Rust library for parsing Ledger-cli input files.

File format

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 (minimum two spaces or one tab between DESC and NOTE):

    DATE[=EDATE] [*|!] [(CODE)] DESC  [; NOTE]
    
  • Transaction postings with format (minimum two spaces or one tab between ACCOUNT and AMOUNT):

      ACCOUNT  [AMOUNT] [= BALANCE] [; NOTE]
    
    • Virtual accounts are supported
  • AMOUNT can be combined with lot and commodity prices ({}, {{}}, @, @@)

  • Commodity prices with format:

    P DATE SYMBOL PRICE
    
  • Command directives: include

Example

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::default().with_indent("\t")));

println!("{}", ledger); println!("{}", ledger.to_string_pretty(&SerializerSettings::default().with_indent("\t")));

See also

  • ledger-utils - ledger-cli file processing Rust library, useful for calculating balances, creating reports etc.

GitHub Stars

15

LAST COMMIT

2yrs ago

MAINTAINERS

1

CONTRIBUTORS

6

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
5.1.1
2mos ago
5.1.0
5mos ago
5.0.0
5mos ago
4.1.0
5mos ago
No alternatives found
No tutorials found
Add a tutorial