mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-26 20:02:27 +03:00
imp: allow declaring the empty payee name with "" (#2119)
This commit is contained in:
parent
6a41ed9e64
commit
6ae64c8f3e
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user