on master help sign in
Improve error messages.
614b60dBryan O'Sullivan
Data/Text/Lazy/Read.hs+3−3
@@ -38,7 +38,7 @@ decimal :: Integral a => Reader a
38{-# SPECIALIZE decimal :: Reader Int #-}
38{-# SPECIALIZE decimal :: Reader Int #-}
39{-# SPECIALIZE decimal :: Reader Integer #-}
39{-# SPECIALIZE decimal :: Reader Integer #-}
40decimal txt
40decimal txt
41− | T.null h = Left "no digits in input"
41+ | T.null h = Left "input does not start with a digit"
42 | otherwise = Right (T.foldl' go 0 h, t)
42 | otherwise = Right (T.foldl' go 0 h, t)
43 where (h,t) = T.spanBy isDigit txt
43 where (h,t) = T.spanBy isDigit txt
44 go n d = (n * 10 + fromIntegral (digitToInt d))
44 go n d = (n * 10 + fromIntegral (digitToInt d))
@@ -91,7 +91,7 @@ hex :: Integral a => Reader a
91{-# SPECIALIZE hex :: Reader Int #-}
91{-# SPECIALIZE hex :: Reader Int #-}
92{-# SPECIALIZE hex :: Reader Integer #-}
92{-# SPECIALIZE hex :: Reader Integer #-}
93hex txt
93hex txt
94− | T.null h = Left "no digits in input"
94+ | T.null h = Left "input does not start with a hexadecimal digit"
95 | otherwise = Right (T.foldl' go 0 h, t)
95 | otherwise = Right (T.foldl' go 0 h, t)
96 where (h,t) = T.spanBy isHexDigit txt
96 where (h,t) = T.spanBy isHexDigit txt
97 go n d = (n * 16 + fromIntegral (hexDigitToInt d))
97 go n d = (n * 16 + fromIntegral (hexDigitToInt d))
@@ -131,7 +131,7 @@ perhaps def m = P $ \t -> case runP m t of
131char :: (Char -> Bool) -> Parser Char
131char :: (Char -> Bool) -> Parser Char
132char p = P $ \t -> case T.uncons t of
132char p = P $ \t -> case T.uncons t of
133 Just (c,t') | p c -> Right (c,t')
133 Just (c,t') | p c -> Right (c,t')
134− _ -> Left "char"
134+ _ -> Left "character does not match"
135
135
136data T = T !Integer !Int
136data T = T !Integer !Int
137
137