parsing: more robust double-quoted commodities - anything but a space or newline or double quote

This commit is contained in:
Simon Michael 2010-05-27 01:31:50 +00:00
parent 3305141206
commit b97d2690de
2 changed files with 8 additions and 5 deletions

View File

@ -12,6 +12,8 @@ import Hledger.Data.Utils
import Hledger.Data.Types
nonsimplecommoditychars = "0123456789-.@;\n \""
-- convenient amount and commodity constructors, for tests etc.
unknown = Commodity {symbol="", side=L,spaced=False,comma=False,precision=0}

View File

@ -157,7 +157,7 @@ import Hledger.Data.Amount
import Hledger.Data.Transaction
import Hledger.Data.Posting
import Hledger.Data.Journal
import Hledger.Data.Commodity (dollars,dollar,unknown)
import Hledger.Data.Commodity (dollars,dollar,unknown,nonsimplecommoditychars)
import System.FilePath(takeDirectory,combine)
import System.Time (getClockTime)
@ -545,17 +545,18 @@ nosymbolamount = do
<?> "no-symbol amount"
commoditysymbol :: GenParser Char st String
commoditysymbol = (quotedcommoditysymbol <|>
many1 (noneOf "0123456789-.@;\n \"")
) <?> "commodity symbol"
commoditysymbol = (quotedcommoditysymbol <|> simplecommoditysymbol) <?> "commodity symbol"
quotedcommoditysymbol :: GenParser Char st String
quotedcommoditysymbol = do
char '"'
s <- many1 $ noneOf "-.@;\n\""
s <- many1 $ noneOf ";\n\""
char '"'
return s
simplecommoditysymbol :: GenParser Char st String
simplecommoditysymbol = many1 (noneOf nonsimplecommoditychars)
priceamount :: GenParser Char st (Maybe MixedAmount)
priceamount =
try (do