>>>>> Russell Adams <RLAdams-oD4XmFtju8vuCfmLQ01/GwC/[email protected]> 
>>>>> writes:

> Through my use of Ledger, one of the issues I've noticed is that while text
> is a powerful format, it lacks any validation. I've been plagued by a series
> of problems caused by minor typos and had to hunt them down.

> Perhaps we can add some extensions to the ledger format to allow validation?

This has been suggested many times, and in fact was one of the main reasons
that "beancount" became a fork: because I resist any and all *required*
validation.  However, having an optional feature would be nice.  I think there
are some Bugzilla feature requests about this, in fact.

> My first thoughts would be a directive allowed in any file which specifies
> allowed account names, and the ability to enumerate allowed values for
> specific TAGs. (ie: TAG X can only be X, Y or Z, or match regexp /[0-9]+/).

There is an "assert" directive, allowed within automated transactions:

= true
  assert account !~ /REGEXP/ and tag =~ /REGEXP/

You can also use "check" if you want any violations to simply be flagged as
warnings.

> Another idea would be a txn of type X, where that transaction fits a
> "template" for lack of a better term.

> I'm not sure if this would grow into the existing language, or perhaps an
> external tool. Comments?

Is the above close enough to what you need?  You could also write a validation
function in Python, and then use the same assert above:

foo.py:

  def validate(post):
       # etc., etc.

foo.dat:

  = true
    assert validate(post)

ledger --import foo.py -f foo.dat bal

John

Reply via email to