lib: refactor the account name parser
This commit is contained in:
parent
b245ec7b3d
commit
558c11596f
@ -463,21 +463,15 @@ modifiedaccountnamep = do
|
||||
-- (This parser will also consume one following space, if present.)
|
||||
accountnamep :: TextParser m AccountName
|
||||
accountnamep = do
|
||||
astr <- do
|
||||
c <- nonspace
|
||||
cs <- striptrailingspace <$> many (nonspace <|> singlespace)
|
||||
return $ c:cs
|
||||
let a = T.pack astr
|
||||
when (accountNameFromComponents (accountNameComponents a) /= a)
|
||||
(fail $ "account name seems ill-formed: "++astr)
|
||||
return a
|
||||
firstPart <- part
|
||||
otherParts <- many $ try $ singleSpace *> part
|
||||
let account = T.unwords $ firstPart : otherParts
|
||||
when (accountNameFromComponents (accountNameComponents account) /= account)
|
||||
(fail $ "account name seems ill-formed: " ++ T.unpack account)
|
||||
pure account
|
||||
where
|
||||
singlespace = try (do {spacenonewline; do {notFollowedBy spacenonewline; return ' '}})
|
||||
striptrailingspace "" = ""
|
||||
striptrailingspace s = if last s == ' ' then init s else s
|
||||
|
||||
-- accountnamechar = notFollowedBy (oneOf "()[]") >> nonspace
|
||||
-- <?> "account name character (non-bracket, non-parenthesis, non-whitespace)"
|
||||
part = takeWhile1P Nothing (not . isSpace)
|
||||
singleSpace = void spacenonewline *> notFollowedBy spacenonewline
|
||||
|
||||
--- ** amounts
|
||||
|
||||
|
||||
@ -75,8 +75,11 @@ showDateParseError e = printf "date parse error (%s)" (intercalate ", " $ tail $
|
||||
nonspace :: TextParser m Char
|
||||
nonspace = satisfy (not . isSpace)
|
||||
|
||||
isNonNewlineSpace :: Char -> Bool
|
||||
isNonNewlineSpace c = c /= '\n' && isSpace c
|
||||
|
||||
spacenonewline :: (Stream s, Char ~ Token s) => ParsecT Void s m Char
|
||||
spacenonewline = satisfy (`elem` " \v\f\t")
|
||||
spacenonewline = satisfy isNonNewlineSpace
|
||||
|
||||
restofline :: TextParser m String
|
||||
restofline = anyChar `manyTill` newline
|
||||
|
||||
Loading…
Reference in New Issue
Block a user