Beancount txn parser/writer in Emacs Lisp

110 views
Skip to first unread message

TRS-80

unread,
Jul 25, 2024, 5:06:56 PM7/25/24
to bean...@googlegroups.com
Hi friends,

Over the past years, I have implemented some hacky bits and pieces of a
txn parser and a writer in Emacs Lisp, and I was thinking about pulling
them together into something coherent and proper and maybe even
publishing it at some point.

However I have a bad habit of re-inventing wheels, so I thought I might
ask if something like this exists already? I had a look at
https://plaintextaccounting.org, as well as searching this mailing list,
but all I found were some parsers written in Rust and some attempts at a
tree-sitter based parser for Beancount (which seemed to be so far
WIP/incomplete, near as I could tell).

It may be a wrong-headed approach, but I prefer to work on my books[0]
in Emacs, and I prefer to write my own text manipulation tools in Emacs
Lisp (generally speaking).

Any feedback would be welcomed.


[0] Actually, I do almost everything in Emacs. :D

--
Cheers,
TRS-80

Martin Blais

unread,
Jul 25, 2024, 9:43:36 PM7/25/24
to bean...@googlegroups.com
If it exists, I'm not aware of it. 
I'm all for it.


--
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/87le1pw59a.fsf%40isnotmyreal.name.

Daniele Nicolodi

unread,
Jul 26, 2024, 4:23:33 AM7/26/24
to bean...@googlegroups.com
On 25/07/24 23:06, TRS-80 wrote:
> Hi friends,
>
> Over the past years, I have implemented some hacky bits and pieces of a
> txn parser and a writer in Emacs Lisp, and I was thinking about pulling
> them together into something coherent and proper and maybe even
> publishing it at some point.
>
> However I have a bad habit of re-inventing wheels, so I thought I might
> ask if something like this exists already? I had a look at
> https://plaintextaccounting.org, as well as searching this mailing list,
> but all I found were some parsers written in Rust and some attempts at a
> tree-sitter based parser for Beancount (which seemed to be so far
> WIP/incomplete, near as I could tell).

I am not aware of any Emacs Lisp implementation of a parse and writer,
but we have beancount-mode https://github.com/beancount/beancount-mode/
which uses the usual regexp based approach to implement a Beancount
major mode. The regexps and functions in beancount.el are usually enough
for implementing the kind of ledger editing functions I need.

I have a tree-sitter Beancount parser that AFAIK is complete and
validating (contrary to other tree-sitter Beancount parsers I've seen,
it correctly uses indentation to distinguish syntactical elements) but I
haven't used it for anything other than playing around yet.

Cheers,
Dan

Stefano Merlo

unread,
Jul 26, 2024, 12:36:47 PM7/26/24
to Beancount
I built some utilities in Emacs Lisp to edit the ledger file (e.g. rename/move a document and add to a transaction) and to add transactions for specific workflow (e.g., healthcare expenses that needs to be claimed and reimbursed by different providers, tracking related documents and deadlines via metadata/custom directives).  I also fetch commodities prices using Elisp and webscraping.  I do almost all processing (plugins, scripts) and analysis (Fava, Fava Dashboard) in python: I explored org-mode and babel, however for my needs it does not beat the browser yet.

I published only some python plugins but not yet any elisp code (except a parser for the italian invoice standard XML format, not exactly a blockbuster).
Happy to reinvent the wheel together on a shared project that sounds like might be helpful for also my workflow.

TRS-80

unread,
Jul 27, 2024, 10:51:58 AM7/27/24
to bean...@googlegroups.com
Daniele Nicolodi <dan...@grinta.net> writes:

> I am not aware of any Emacs Lisp implementation of a parse and writer,
> but we have beancount-mode
> https://github.com/beancount/beancount-mode/ which uses the usual
> regexp based approach to implement a Beancount major mode. The regexps
> and functions in beancount.el are usually enough for implementing the
> kind of ledger editing functions I need.

Yes, I am of course already leaning heavily on those functions and
regexps! No need to re-invent those.

However it seems I keep re-inventing little one-off editing functions on
top of those. I imagine we all are(?). Which was why I thought it
might be generally useful to others to publish something.

> I have a tree-sitter Beancount parser that AFAIK is complete and
> validating (contrary to other tree-sitter Beancount parsers I've seen,
> it correctly uses indentation to distinguish syntactical elements) but
> I haven't used it for anything other than playing around yet.

I did come across that, nice work! I guess I had assumed because you
weren't using it for anything that it wasn't complete. At least now
there will be another breadcrumb here on the mailing list for the next
person to find later.

--
Cheers,
TRS-80

TRS-80

unread,
Jul 27, 2024, 11:04:51 AM7/27/24
to bean...@googlegroups.com
Stefano Merlo <trepr...@gmail.com> writes:

> Happy to reinvent the wheel together on a shared project that sounds
> like might be helpful for also my workflow.

I suspected I might not be the only one hacking things together on top
of what beancount.el provides. Thanks for replying, now I am glad I
made this announcement. :)

I started hacking away on it this morning (in reality, just pulling
together and better organizing things I have already had scattered all
over my own ELisp files since years).

I plan to get a minimum "something" together and share it, rather than
waiting until I have a complete implementation, then publish incremental
updates whenever I have time to work on it. As soon as I have done
that, I will make another announcement.

--
Cheers,
TRS-80

TRS-80

unread,
Jul 31, 2024, 10:04:23 AM7/31/24
to bean...@googlegroups.com
TRS-80 <lists....@isnotmyreal.name> writes:

> Hi friends,
>
> Over the past years, I have implemented some hacky bits and pieces of
> a txn parser and a writer in Emacs Lisp, and I was thinking about
> pulling them together into something coherent and proper and maybe
> even publishing it at some point.

Hello again,

After a few days (on and off) of intensive study and hacking, I am very
pleased to announce I have completed the parser and writer. I even
wrote some tests for the parser (just need to write some for the writer
now). I would just like to add a few more finishing touches before I
publish, which should happen soon.

I did have a couple questions though:

1. I understand the Language Syntax[0] to be saying that /either/ one or
the other of 'txn' directive or 'a flag' is /required/. Is my
understanding correct?

2. Further, and strictly speaking, it appears to me that those are the
only real required things to constitute 'a transaction'. Is that
correct?

I am very excited to share this soon. I want to see if anyone can break
it. :) And I myself have a lot more things I want to build (for my own
usage) on top of it.



[0] https://beancount.github.io/docs/beancount_language_syntax.html#transactions

--
Cheers,
TRS-80

Reply all
Reply to author
Forward
0 new messages