Java-based library with CLI that can (really) sort transactions, merge/combine, and format files

92 views
Skip to first unread message

Jordie B

unread,
Jul 26, 2022, 6:56:01 PM7/26/22
to Beancount
Hey everyone,

I wanted to sort my transactions, and at the same time I really wanted to be able to access my Journal from the JVM.

Within the past 2? week(s?) I created JBeancount (https://github.com/jord1e/jbeancount). The README has a lot of information.

It contains a parser implementation based on ANTLRv4 that is 99% compatible with normal Beancount (working on full support). Currently it errors on pushtag/poptag and emacs mode sections.

It has the ability to stably sort all transactions in a file based on the date (I don't think this existed in the ecosystem at all? - it generally works with comments, still improving on that front in coming iterations)

It also contains a formatter kind of similar to bean-format. Both will be expanded in the future to offer opinionated formatting.

The library architecture is based on the battle-tested GraphQL Java library way of transforming the AST into an immutable data structure. With Java 17 sealed classes it is fully typesafe.

It also contains a feature to merge multiple journals together into one (or your root journal with include pragmas into one!).

It also uses GraalVM, this makes startup time a non-issue.
       Measure-Command {.\jbeancount.exe merge -r -o merged.beancount all.beancount; .\jbeancount.exe format --experimental-sort-transactions merged.beancount -o merged.beancount}
Merges my ~15 files into a 14.000 line file and sorts+formats the transactions in ~270 milliseconds (it currently sorts a bit jangly when transaction directives are intermixed with other directives or pragmas - this will be fixed)

I'll accept feature requests for the sorting and formatting, or general library requests in the GitHub issue tracker. Test coverage will also improve (currently only manual testing on my big transaction-only-by-year files)

Thank you Martin for the amazing work on Beancount.

Regards,
Jordie

Matt Payne

unread,
Jul 26, 2022, 8:17:33 PM7/26/22
to bean...@googlegroups.com
Jordie - Thank you!  This is awesome, inspirational, and useful.  BRAVO! --Matt Payne

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/72ee8adb-a376-4e30-b6d4-ea8749f5f666n%40googlegroups.com.


--
"Good night, Westley. Good work. Sleep well. I'll most likely kill you in the morning." -- The Dread Pirate Roberts

Martin Blais

unread,
Jul 27, 2022, 9:22:52 AM7/27/22
to Beancount
Very cool!
Thanks for sharing.
I'll add a link from the contrib page.

Makes me think I should review the parser to see if I can use Antlr, in which case a common syntax generator could be used for multiple languages.



--
Reply all
Reply to author
Forward
0 new messages