imp: allow declaring the empty payee name with "" (#2119)

This commit is contained in:
Simon Michael 2023-12-07 08:29:07 -10:00
parent 6a41ed9e64
commit 6ae64c8f3e
3 changed files with 12 additions and 2 deletions

View File

@ -105,6 +105,7 @@ module Hledger.Read.Common (
bracketeddatetagsp,
-- ** misc
doublequotedtextp,
noncommenttextp,
noncommenttext1p,
singlespacedtext1p,
@ -658,6 +659,11 @@ modifiedaccountnamep = do
accountnamep :: TextParser m AccountName
accountnamep = singlespacedtext1p
-- | Parse a single line of possibly empty text enclosed in double quotes.
doublequotedtextp :: TextParser m Text
doublequotedtextp = between (char '"') (char '"') $
takeWhileP Nothing $ \c -> not $ isNewline c || c == '"'
-- | Parse possibly empty text, including whitespace,
-- until a comment start (semicolon) or newline.
noncommenttextp :: TextParser m T.Text

View File

@ -629,7 +629,7 @@ payeedirectivep :: JournalParser m ()
payeedirectivep = do
string "payee" <?> "payee directive"
lift skipNonNewlineSpaces1
payee <- lift $ T.strip <$> noncommenttext1p
payee <- lift $ T.strip <$> (try doublequotedtextp <|> noncommenttext1p)
(comment, tags) <- lift transactioncommentp
skipMany indentedlinep
addPayeeDeclaration (payee, comment, tags)
@ -1134,8 +1134,10 @@ tests_JournalReader = testGroup "JournalReader" [
}
,testGroup "payeedirectivep" [
testCase "simple" $ assertParse payeedirectivep "payee foo\n"
testCase "simple" $ assertParse payeedirectivep "payee foo\n"
,testCase "with-comment" $ assertParse payeedirectivep "payee foo ; comment\n"
,testCase "double-quoted" $ assertParse payeedirectivep "payee \"a b\"\n"
,testCase "empty " $ assertParse payeedirectivep "payee \"\"\n"
]
,testCase "tagdirectivep" $ do

View File

@ -2257,10 +2257,12 @@ in another commodity. See [Value reporting](#value-reporting).
This directive can be used to declare a limited set of payees which may appear in [transaction descriptions](#descriptions).
The ["payees" check](#check) will report an error if any transaction refers to a payee that has not been declared.
To declare the empty payee name, use `""`.
Eg:
```journal
payee Whole Foods
payee ""
```
Any indented subdirectives are currently ignored.