From fedde7fab15bf1d1711066216de30ba47c0fe82a Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 8 Apr 2020 19:18:39 -0700 Subject: [PATCH] journal: also support the total lot price variants ({{}}, {{=}}) --- hledger-lib/Hledger/Read/Common.hs | 2 ++ hledger-lib/Hledger/Read/JournalReader.hs | 4 ++++ hledger/CHANGES.md | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 46185f623..e4d5fa7e8 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -767,11 +767,13 @@ balanceassertionp = do lotpricep :: JournalParser m (Either Amount Amount) lotpricep = (do char '{' + doublebrace <- option False $ char '{' >> pure True fixed <- fmap isJust $ optional $ lift (skipMany spacenonewline) >> char '=' lift (skipMany spacenonewline) a <- amountwithoutpricep lift (skipMany spacenonewline) char '}' + when (doublebrace) $ void $ char '}' return $ (if fixed then Left else Right) a ) "ledger-style lot price or fixed lot price" diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 03c6c7e64..ca0b3113d 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -855,6 +855,10 @@ tests_JournalReader = tests "JournalReader" [ ,test "quoted commodity symbol with digits" $ assertParse (postingp Nothing) " a 1 \"DE123\"\n" + ,test "only lot price" $ assertParse (postingp Nothing) " a 1A {1B}\n" + ,test "fixed lot price" $ assertParse (postingp Nothing) " a 1A {=1B}\n" + ,test "total lot price" $ assertParse (postingp Nothing) " a 1A {{1B}}\n" + ,test "fixed total lot price, and spaces" $ assertParse (postingp Nothing) " a 1A {{ = 1B }}\n" ,test "lot price before transaction price" $ assertParse (postingp Nothing) " a 1A {1B} @ 1B\n" ,test "lot price after transaction price" $ assertParse (postingp Nothing) " a 1A @ 1B {1B}\n" ,test "lot price after balance assertion not allowed" $ assertParseError (postingp Nothing) " a 1A @ 1B = 1A {1B}\n" "unexpected '{'" diff --git a/hledger/CHANGES.md b/hledger/CHANGES.md index c1205178a..66de6ac57 100644 --- a/hledger/CHANGES.md +++ b/hledger/CHANGES.md @@ -6,7 +6,8 @@ User-visible changes in the hledger command line tool and library. - Improved parse compatibility for Ledger lot prices: hledger up to 1.17.1 did not accept Ledger's lot price syntax except in vary limited circumstances (`{= }` at the end of the posting line). - hledger now accepts all three lot price syntaxes (`{ }`, `{{ }}`, `{= }`), + hledger now accepts all four of Ledger's lot price syntaxes + (`{PRICE}`, `{{PRICE}}`, `{=PRICE}`, `{{=PRICE}}`), anywhere after the posting amount but before any balance assertion. All of these lot prices are ignored.