Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

;doc: explain comments in "if tables" and order of application #2184

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions hledger/hledger.m4.md
Original file line number Diff line number Diff line change
Expand Up @@ -3482,6 +3482,7 @@ they can express many matchers and field assignments in a more compact tabular f
if,HLEDGERFIELD1,HLEDGERFIELD2,...
MATCHERA,VALUE1,VALUE2,...
MATCHERB,VALUE1,VALUE2,...
; Comment line that explains MATCHERC
MATCHERC,VALUE1,VALUE2,...
<empty line>
```
Expand All @@ -3493,13 +3494,15 @@ It should be a non-alphanumeric character like `,` or `|` that does not appear a

Each line must contain the same number of separators; empty values are allowed.
Whitespace can be used in the matcher lines for readability (but not in the if line, currently).
You can use the comment lines in the table body.
The table must be terminated by an empty line (or end of file).

An if table like the above is interpreted as follows:
try all of the matchers;
whenever a matcher succeeds, assign all of the values on that line to the corresponding hledger fields;
later lines can overrider earlier ones.
It is equivalent to this sequence of if blocks:
If multiple lines match, later lines will override fields assigned by the earlier ones - just like the sequence of `if` blocks would behave.

If table presented above is equivalent to this sequence of if blocks:

```rules
if MATCHERA
Expand All @@ -3512,6 +3515,7 @@ if MATCHERB
HLEDGERFIELD2 VALUE2
...
; Comment line which explains MATCHERC
if MATCHERC
HLEDGERFIELD1 VALUE1
HLEDGERFIELD2 VALUE2
Expand All @@ -3523,6 +3527,7 @@ Example:
if,account2,comment
atm transaction fee,expenses:business:banking,deductible? check it
%description groceries,expenses:groceries,
;; Comment line that desribes why this particular date is special
2023/01/12.*Plumbing LLC,expenses:house:upkeep,emergency plumbing call-out
```

Expand Down
Loading