Giter Site home page Giter Site logo

rust-ledger-parser's Introduction

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

    • Posting comments with dates, effective dates, and metadata tags are supported

      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:

    P DATE SYMBOL PRICE
    
  • Command directives: include

Example

Parsing:

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:

use ledger_parser::{ Serializer, SerializerSettings };

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.

rust-ledger-parser's People

Contributors

claytonrcarter avatar ebcrowder avatar emm avatar huin avatar marek-g avatar rumpuslabs avatar tarkah avatar zoranzaric avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rust-ledger-parser's Issues

Interested in collaboration?

Hi, Marek!

Not sure if you've already noticed, I've recently raised a question in the plain-text accounting channel on Reddit, which got some interest in developing (a) Ledger(-like) in Rust. Obviously you're doing a lot in that regard already so I was wondering if you were interesting in pooling-in with others.
I've (very recently!) created an organization to collect those interested in idea and try to focus the time and effort in a common goal. Please chip in if you're interested! Your parser is often mentioned in the discussions so far.
Cheers!

Thanks!

Just wanted to let you know that I appreciated being able to find this package! Though basic, it seems sufficient for use in scripts, and I plan on using it. Writing data shouldn't be too hard, so I just need to find a package that can do that, or write my own function.

I hope to be able to submit pull requests for some improvement items or documentation, so thanks again for maintaining it!

Balance assertion support

Would it be reasonable to add balance verifications to Postings and the parser? A downside would be that this would likely require a major version bump due to the new (optional) field in Posting.

This is probably something that I can attempt to implement myself with a pull request if it seems like a reasonable feature to add.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.