;dev: journal: test all h/ledger syntax by status: main, other, unsupported

This commit is contained in:
Simon Michael 2022-12-21 17:12:33 -10:00
parent 03d0799f2f
commit befded96d2
4 changed files with 294 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Test all journal syntax features:
main hledger syntax
other/legacy hledger syntax,
and ledger syntax not yet supported.

View File

@ -0,0 +1,153 @@
# Ledger syntax currently not supported by hledger. -*- ledger -*-
# Reading these is expected to fail.
# `;` `#` `%` `*` `|` comment lines
<
%
|
$ hledger -f- check
>2//
>=1
# `!` or `@` as a directive prefix
<
@comment
$ hledger -f- check
>2//
>=1
# `account` subdirectives
<
account Expenses:Food
note This account is all about the chicken!
alias food
payee ^(KFC|Popeyes)$
check commodity == "$"
assert commodity == "$"
eval print("Hello!")
default
2022-01-01
(food) 1
$ hledger -f- accounts # -> both account names printed, alias did not work
Expenses:Food
food
# `apply fixed` set fixated prices
<
apply fixed CAD $0.90
$ hledger -f- check
>2//
>=1
# `assert` test a value expression
<
assert 1
$ hledger -f- check
>2//
>=1
# `bucket`/`A` set a default balancing account
<
bucket Assets:Checking
A Assets:Checking
$ hledger -f- check
>2//
>=1
# `capture` replace accounts matched by regex with another
<
capture Expenses:Deductible:Medical Medical
$ hledger -f- check
>2//
>=1
# `check` test a value expression
<
check 1
$ hledger -f- check
>2//
>=1
# `commodity` subdirectives
<
commodity $
note American Dollars
format $1,000.00
nomarket
alias USD
default
$ hledger -f- check
>2//
>=1
# `define` define value expressions for future use
<
define var_name=$100
$ hledger -f- check
>2//
>=1
# `end` close block commands like `apply` or `comment` (ignores any words after "end")
<
comment
1111-01-01
end
2222-02-02
$ hledger -f- print # -> nothing printed, comment did not end
# `expr` ?
<
expr 1
$ hledger -f- check
>2//
>=1
# `payee` subdirectives
<
payee KFC
alias KENTUCKY FRIED CHICKEN
uuid 1234
$ hledger -f- check
>2//
>=1
# `apply tag` assign a tag to transactions
<
apply tag tag1:val1
$ hledger -f- check
>2//
>=1
# `tag` pre-declare tag names
<
tag tag1
$ hledger -f- tags # -> nothing printed, tag not declared
# `test`, a synonym for `comment`
<
test
$ hledger -f- check
>2//
>=1
# `year`/`Y` set the year for year-less dates
<
year 2022
$ hledger -f- check
>2//
>=1
# `C AMT1 = AMT2` declare a commodity equivalency
<
C $ 1 USD
$ hledger -f- check
>2//
>=1
# `I, i, O, o, b, h` embedded timeclock entries
<
i 2013/04/05 12:00:00 Personal:Lunch
o 2013/04/05 13:30:00
$ hledger -f- check
>2//
>=1

View File

@ -0,0 +1,102 @@
# hledger journal main syntax -*- ledger -*-
# keep synced with hledger.m4.md
# Here is the main syntax of hledger's journal format
# (omitting extra Ledger compatibility syntax).
# hledger journals contain comments, directives, and transactions, in any order:
###############################################################################
# 1. Comment lines are for notes or temporarily disabling things.
# They begin with #, ;, or a line containing the word "comment".
# hash comment line
; semicolon comment line
comment
These lines
are commented.
end comment
# Some but not all hledger entries can have same-line comments attached to them,
# from ; (semicolon) to end of line.
###############################################################################
# 2. Directives modify parsing or reports in some way.
# They begin with a word or letter (or symbol).
account actifs ; type:A, declare an account that is an Asset. 2+ spaces before ;.
account passifs ; type:L, declare an account that is a Liability, and so on.. (ALERX)
alias chkg = assets:checking
commodity $0.00
decimal-mark .
include /dev/null
payee Whole Foods
P 2022-01-01 AAAA $1.40
~ monthly budget goals ; <- 2+ spaces between period expression and description
expenses:food $400
expenses:home $1000
budgeted
###############################################################################
# 3. Transactions are what it's all about; they are dated events,
# usually describing movements of money.
# They begin with a date.
# DATE DESCRIPTION ; This is a transaction comment.
# ACCOUNT NAME 1 AMOUNT1 ; <- posting 1. This is a posting comment.
# ACCOUNT NAME 2 AMOUNT2 ; <- posting 2. Postings must be indented.
# ; ^^ At least 2 spaces between account and amount.
# ... ; Any number of postings is allowed. The amounts must balance (sum to 0).
2022-01-01 opening balances are declared this way
assets:checking $1000 ; Account names can be anything. lower case is easy to type.
assets:savings $1000 ; assets, liabilities, equity, revenues, expenses are common.
assets:cash:wallet $100 ; : indicates subaccounts.
liabilities:credit card $-200 ; liabilities, equity, revenues balances are usually negative.
equity ; One amount can be left blank; $-1900 is inferred here.
2022-04-15 * (#12345) pay taxes
; There can be a ! or * after the date meaning "pending" or "cleared".
; There can be a transaction code (text in parentheses) after the date/status.
; Amounts' sign represents direction of flow, or credit/debit:
assets:checking $-500 ; minus means removed from this account (credit)
expenses:tax:us:2021 $500 ; plus means added to this account (debit)
; revenue/expense categories are also "accounts"
2022-01-01 Whole Foods | payee name and description can be separated by a pipe char
; Transaction or posting comments can contain searchable tags,
; written NAME: or NAME:VALUE (value ends at comma or end of line).
; Here's tag1:with a value, and an empty tag2:
; A few tags have special meaning. A "date:" tag on a posting adjusts its date.
assets:checking $-50 ; date:2022-01-03, checking cleared two days later
expenses:food
2022-01-01 ; The description is optional.
; Any currency/commodity symbols are allowed, on either side.
assets:cash:wallet GBP -10
expenses:clothing GBP 10
assets:gringotts -10 gold
assets:pouch 10 gold
revenues:gifts -2 "Liquorice Wands" ; Complex symbols
assets:bag 2 "Liquorice Wands" ; must be double-quoted.
2022-01-01 Cost in another commodity can be noted with @ or @@
assets:investments 2.0 AAAA @ $1.50 ; @ means per-unit cost
assets:investments 3.0 AAAA @@ $4 ; @@ means total cost
assets:checking $-7.00
2022-01-02 assert balances
; Balances can be asserted for extra error checking, in any transaction.
assets:investments 0 AAAA = 5.0 AAAA
assets:pouch 0 gold = 10 gold
assets:savings $0 = $1000
1999-12-31 Ordering transactions by date is recommended but not required.
; Postings are not required.
2022.01.01 These date
2022/1/1 formats are
12/31 also allowed (but consistent YYYY-MM-DD is recommended).
comment
$ hledger -f- check

View File

@ -0,0 +1,35 @@
# hledger journal "other"/legacy syntax -*- ledger -*-
# keep synced with hledger.m4.md
# `apply account` set a default parent account
<
apply account per
2022-01-01
expenses:food 1 ; parsed as per:expenses:food
assets:cash ; parsed as per:assets:cash
end apply account
$ hledger -f- check
# `D AMT` set a default commodity and its format
<
D $0.0
$ hledger -f- check
# `N COMM` ignore pricing information for a commodity (ignored)
<
N USD
$ hledger -f- check
# star comment line
<
*
$ hledger -f- check
# `=` An automated transaction
<
= expenses:food
(budget:food) *-1
$ hledger -f- check