diff --git a/hledger-lib/Ledger/Parse.hs b/hledger-lib/Ledger/Parse.hs index 53afdad7c..fe1240aa7 100644 --- a/hledger-lib/Ledger/Parse.hs +++ b/hledger-lib/Ledger/Parse.hs @@ -464,7 +464,16 @@ nosymbolamount = do "no-symbol amount" commoditysymbol :: GenParser Char st String -commoditysymbol = many1 (noneOf "@-.0123456789;\n ") "commodity symbol" +commoditysymbol = (quotedcommoditysymbol <|> + many1 (noneOf "0123456789-.@;\n \"") + ) "commodity symbol" + +quotedcommoditysymbol :: GenParser Char st String +quotedcommoditysymbol = do + char '"' + s <- many1 $ noneOf "-.@;\n \"" + char '"' + return s priceamount :: GenParser Char st (Maybe MixedAmount) priceamount = @@ -608,9 +617,11 @@ tests_Parse = TestList [ assertBool "ledgeraccountname rejects an empty leading component" (isLeft $ parsewith ledgeraccountname ":b:c") assertBool "ledgeraccountname rejects an empty trailing component" (isLeft $ parsewith ledgeraccountname "a:b:") - ,"ledgerposting" ~: + ,"ledgerposting" ~: do assertParseEqual (parseWithCtx emptyCtx ledgerposting " expenses:food:dining $10.00\n") (Posting False "expenses:food:dining" (Mixed [dollars 10]) "" RegularPosting Nothing) + assertBool "ledgerposting parses a quoted commodity with numbers" + (isRight $ parseWithCtx emptyCtx ledgerposting " a 1 \"DE123\"\n") ,"someamount" ~: do let -- | compare a parse result with a MixedAmount, showing the debug representation for clarity diff --git a/tests/commodities.test b/tests/commodities.test new file mode 100644 index 000000000..89eb4fbd6 --- /dev/null +++ b/tests/commodities.test @@ -0,0 +1,22 @@ +# a commodity may contain/end with numbers, if double quoted +# 1. without quotes, fail. XXX parse error should be clearer here +-f- print +<<< +2010-04-05 x + a 10 DE0002635307 + b +>>>2 /parse error.* +unexpected "0" +expecting comment or new-line/ +>>>= 1 +# 2. with quotes +-f- print +<<< +2010-04-05 x + a 10 "DE0002635307" + b +>>> +2010/04/05 x + a 10 DE0002635307 + b -10 DE0002635307 +