journal: Account directives reject account names with brackets

Previously, the accounts passed to account directives would be stripped
of their surrounding brackets, but the required behaviour is to have
account directives plain reject bracketed accounts. This change ensures
that accounts in account directives may not start with a bracket
character.
This commit is contained in:
Chris Lemaire 2023-01-24 21:04:48 +01:00 committed by Simon Michael
parent ce87a89ef2
commit 43c9f018dc
3 changed files with 32 additions and 22 deletions

View File

@ -381,7 +381,8 @@ accountdirectivep = do
lift skipNonNewlineSpaces1 lift skipNonNewlineSpaces1
-- the account name, possibly modified by preceding alias or apply account directives -- the account name, possibly modified by preceding alias or apply account directives
acct <- modifiedaccountnamep acct <- (notFollowedBy (char '(' <|> char '[') <?> "account name without brackets") >>
modifiedaccountnamep
-- maybe a comment, on this and/or following lines -- maybe a comment, on this and/or following lines
(cmt, tags) <- lift transactioncommentp (cmt, tags) <- lift transactioncommentp
@ -433,7 +434,7 @@ addAccountDeclaration (a,cmt,tags,pos) = do
modify' (\j -> modify' (\j ->
let let
decls = jdeclaredaccounts j decls = jdeclaredaccounts j
d = (textUnbracket a, nullaccountdeclarationinfo{ d = (a, nullaccountdeclarationinfo{
adicomment = cmt adicomment = cmt
,aditags = tags ,aditags = tags
,adideclarationorder = length decls + 1 -- gets renumbered when Journals are finalised or merged ,adideclarationorder = length decls + 1 -- gets renumbered when Journals are finalised or merged

View File

@ -1801,8 +1801,10 @@ They are written as the word `account` followed by a hledger-style [account name
account assets:bank:checking account assets:bank:checking
``` ```
Note, however, that account names declared in the account directive are stripped of surrounding brackets and parentheses. Note, however, that accounts declared in account directives are not allowed to have surrounding
The above directive is thus equivalent to this: brackets and parentheses, unlike accounts used in postings.
So the following journal will not parse:
```journal ```journal
account (assets:bank:checking) account (assets:bank:checking)
``` ```

View File

@ -68,28 +68,35 @@ account Expenses:Food
$ hledger -f- accounts $ hledger -f- accounts
Expenses:Food Expenses:Food
# 5. It unbrackets account names. # 5. It does not allow parentheses in names.
< <
account (a) account (a)
account (a:aa)
account (a:(aaa))
account [b]
account [b:bb]
account [b:[bbb]]
account [([c])]
account [([c:cc])]
account [([c:[ccc]])]
$ hledger -f- accounts $ hledger -f- accounts
a >2
a:aa hledger: Error: -:1:9:
a:(aaa) |
b 1 | account (a)
b:bb | ^
b:[bbb] unexpected '('
c expecting account name without brackets
c:cc
c:[ccc] >=1
# 6. It does not allow brackets in names.
<
account [a]
$ hledger -f- accounts
>2
hledger: Error: -:1:9:
|
1 | account [a]
| ^
unexpected '['
expecting account name without brackets
>=1
# TODO # TODO
# a trailing : should give a clear error # a trailing : should give a clear error