parsing: allow numbers in commodities if double-quoted, like ledger
This commit is contained in:
parent
f92270dfa8
commit
6977a0eecb
@ -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
|
||||
|
||||
22
tests/commodities.test
Normal file
22
tests/commodities.test
Normal file
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user