diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 4e472a569..18e576a36 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -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 diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 585a530ef..369b6457f 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -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 diff --git a/hledger/hledger.m4.md b/hledger/hledger.m4.md index dec421179..1c1e17338 100644 --- a/hledger/hledger.m4.md +++ b/hledger/hledger.m4.md @@ -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.