jcornaz / beancount-parser

A beancount file parser library for rust
The Unlicense
21 stars 7 forks source link

Support balance assertion tolerance syntax (`~`) #70

Closed blais closed 9 months ago

blais commented 9 months ago

Thanks for addressing all the other issues Jonathan. Updating and continuing on, I see the precision syntax fail:

2013-09-10 balance Assets:US:Vanguard                                   305.205 ~ 0.002 RGAGX
jcornaz commented 9 months ago

Thanks for the report, I didn't know that syntax.

I usually refer to this document: https://beancount.github.io/docs/beancount_language_syntax.html and it looks like doesn't mention it.

But of course, I'd like this parser to accept any valid beancount syntax, so the ~ precision syntax should be supported.

blais commented 9 months ago

Great! Id like to build something and learn some Rust in the process using your parser.

blais commented 9 months ago

Local tolerance parsing looks like this in bison:

amount_tolerance:
  number_expr currency
    {
        BUILDY(DECREF($1, $2),
               $$.pyobj1, "amount", "OO", $1, $2);
        $$.pyobj2 = Py_None;
        Py_INCREF(Py_None);
    }
  | number_expr TILDE number_expr currency
    {
        BUILDY(DECREF($1, $4),
               $$.pyobj1, "amount", "OO", $1, $4);
        $$.pyobj2 = $3;
    }
blais commented 9 months ago

I added some text int he docs: https://docs.google.com/document/d/1wAMVrKIA2qtRGmoVDSUBJGmYZSygUaR0uOMW1GV3YE0/edit#heading=h.5jx4fqseqk64

jcornaz commented 9 months ago

Thank you very much. I'll look at this soon. It should be fairly easy to implement. If you want to give it a go yourself you can open a PR too. But don't feel like you have to, I can probably find the time for that this week or the next.

jcornaz commented 9 months ago

This is fixed in version 2.1.0

blais commented 9 months ago

Thank you! :-) I now confirm this parser is able to grok my entire gnarly personal Beancount file.