lib: simple dates must start with non-space; docs

This commit is contained in:
Simon Michael 2015-04-28 13:50:58 -07:00
parent 4d4a6b1660
commit fb37e99bc8

View File

@ -440,8 +440,10 @@ test_transaction = do
assertEqual 2 (let Right t = p in length $ tpostings t) assertEqual 2 (let Right t = p in length $ tpostings t)
#endif #endif
-- | Parse a date in YYYY/MM/DD format. Fewer digits are allowed. The year -- | Parse a date in YYYY/MM/DD format.
-- may be omitted if a default year has already been set. -- Hyphen (-) and period (.) are also allowed as separators.
-- The year may be omitted if a default year has been set.
-- Leading zeroes may be omitted.
datep :: Stream [Char] m t => ParsecT [Char] JournalContext m Day datep :: Stream [Char] m t => ParsecT [Char] JournalContext m Day
datep = do datep = do
-- hacky: try to ensure precise errors for invalid dates -- hacky: try to ensure precise errors for invalid dates
@ -463,10 +465,12 @@ datep = do
Just date -> return date Just date -> return date
<?> "full or partial date" <?> "full or partial date"
-- | Parse a date and time in YYYY/MM/DD HH:MM[:SS][+-ZZZZ] format. Any -- | Parse a date and time in YYYY/MM/DD HH:MM[:SS][+-ZZZZ] format.
-- timezone will be ignored; the time is treated as local time. Fewer -- Hyphen (-) and period (.) are also allowed as date separators.
-- digits are allowed, except in the timezone. The year may be omitted if -- The year may be omitted if a default year has been set.
-- a default year has already been set. -- Seconds are optional.
-- The timezone is optional and ignored (the time is always interpreted as a local time).
-- Leading zeroes may be omitted (except in a timezone).
datetimep :: Stream [Char] m Char => ParsecT [Char] JournalContext m LocalTime datetimep :: Stream [Char] m Char => ParsecT [Char] JournalContext m LocalTime
datetimep = do datetimep = do
day <- datep day <- datep
@ -618,21 +622,24 @@ modifiedaccountname = do
aliases <- getAccountAliases aliases <- getAccountAliases
return $ accountNameApplyAliases aliases prefixed return $ accountNameApplyAliases aliases prefixed
-- | Parse an account name. Account names may have single spaces inside -- | Parse an account name. Account names start with a non-space, may
-- them, and are terminated by two or more spaces. They should have one or -- have single spaces inside them, and are terminated by two or more
-- more components of at least one character, separated by the account -- spaces (or end of input). Also they have one or more components of
-- separator char. -- at least one character, separated by the account separator char.
-- (This parser will also consume one following space, if present.)
accountnamep :: Stream [Char] m Char => ParsecT [Char] st m AccountName accountnamep :: Stream [Char] m Char => ParsecT [Char] st m AccountName
accountnamep = do accountnamep = do
a <- many1 (nonspace <|> singlespace) a <- do
let a' = striptrailingspace a c <- nonspace
when (accountNameFromComponents (accountNameComponents a') /= a') cs <- striptrailingspace <$> many (nonspace <|> singlespace)
(fail $ "account name seems ill-formed: "++a') return $ c:cs
return a' when (accountNameFromComponents (accountNameComponents a) /= a)
(fail $ "account name seems ill-formed: "++a)
return a
where where
singlespace = try (do {spacenonewline; do {notFollowedBy spacenonewline; return ' '}}) singlespace = try (do {spacenonewline; do {notFollowedBy spacenonewline; return ' '}})
-- couldn't avoid consuming a final space sometimes, harmless striptrailingspace "" = ""
striptrailingspace s = if last s == ' ' then init s else s striptrailingspace s = if last s == ' ' then init s else s
-- accountnamechar = notFollowedBy (oneOf "()[]") >> nonspace -- accountnamechar = notFollowedBy (oneOf "()[]") >> nonspace
-- <?> "account name character (non-bracket, non-parenthesis, non-whitespace)" -- <?> "account name character (non-bracket, non-parenthesis, non-whitespace)"