Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marek-g/rust-ledger-parser
Rust library for parsing ledger cli (https://www.ledger-cli.org/) input files.
https://github.com/marek-g/rust-ledger-parser
ledger ledger-cli parser rust
Last synced: 2 months ago
JSON representation
Rust library for parsing ledger cli (https://www.ledger-cli.org/) input files.
- Host: GitHub
- URL: https://github.com/marek-g/rust-ledger-parser
- Owner: marek-g
- License: unlicense
- Created: 2018-09-29T17:15:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-06T16:15:28.000Z (8 months ago)
- Last Synced: 2024-09-20T09:11:33.655Z (4 months ago)
- Topics: ledger, ledger-cli, parser, rust
- Language: Rust
- Homepage:
- Size: 103 KB
- Stars: 32
- Watchers: 4
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# ledger-parser
[![Crates.io Version](https://img.shields.io/crates/v/ledger-parser.svg)](https://crates.io/crates/ledger-parser)
[![Docs.rs Version](https://docs.rs/ledger-parser/badge.svg)](https://docs.rs/ledger-parser)
[![License Unlicense](https://img.shields.io/crates/l/ledger-parser.svg)](http://unlicense.org/UNLICENSE)Rust library for parsing [Ledger-cli](https://www.ledger-cli.org/) 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`):
```ledger-cli
DATE[=EDATE] [*|!] [(CODE)] DESC [; NOTE]
```- Transaction postings with format (minimum two spaces or one tab between `ACCOUNT` and `AMOUNT`):
```ledger-cli
ACCOUNT [AMOUNT] [= BALANCE] [; NOTE]
```- Virtual accounts are supported
- Posting comments with dates, effective dates, and metadata tags are supported
```ledger-cli
ACCOUNT [AMOUNT] [= BALANCE] ; [YYYY-MM-DD]
ACCOUNT [AMOUNT] [= BALANCE] ; [=YYYY-MM-DD]
ACCOUNT [AMOUNT] [= BALANCE] ; :TAG1:TAG2:
ACCOUNT [AMOUNT] [= BALANCE] ; Tag: String Value
ACCOUNT [AMOUNT] [= BALANCE] ; Tag:: -1
ACCOUNT [AMOUNT] [= BALANCE] ; Tag:: 1.0
ACCOUNT [AMOUNT] [= BALANCE] ; Tag:: [YYYY-MM-DD]
```- `AMOUNT` can be combined with lot and commodity prices ({}, {{}}, @, @@)
- Commodity prices with format:
```ledger-cli
P DATE SYMBOL PRICE
```- Command directives: `include`
## Example
Parsing:
```rust
let ledger: ledger_parser::Ledger = 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"#
.parse()?;
```Serializing:
```rust
use ledger_parser::{ Serializer, SerializerSettings };println!("{}", ledger);
println!("{}", ledger.to_string_pretty(&SerializerSettings::default().with_indent("\t")));
```## See also
- [ledger-utils](https://crates.io/crates/ledger-utils) - ledger-cli file processing Rust library, useful for calculating balances, creating reports etc.