@@ -18,23 +18,22 @@ import Control.Applicative (Applicative(..), Alternative(..), (<$>))
1818import Data.ByteString.Char8 (ByteString, snoc, cons, copy)
1919import Data.Monoid
2020import Data.Attoparsec.Char8
21−import Database.PostgreSQL.Simple.FromField
2221
2322
2423-- | Parse one of three primitive field formats: array, quoted and plain.
2524arrayFormat :: Char -> Parser ArrayFormat
26−arrayFormat delim = Array <$> bracketed delim
25+arrayFormat delim = Array <$> array delim
2726 <|> Bytes <$> plain delim
2827 <|> Bytes <$> quoted
2928
3029data ArrayFormat = Array [ArrayFormat] | Bytes ByteString
3130 deriving (Eq, Show, Ord)
3231
33−bracketed :: Char -> Parser [ArrayFormat]
34−bracketed delim = char '{' *> option [] (arrays <|> strings) <* char '}'
32+array :: Char -> Parser [ArrayFormat]
33+array delim = char '{' *> option [] (arrays <|> strings) <* char '}'
3534 where
3635 strings = sepBy1 (Bytes <$> (quoted <|> plain delim)) (char delim)
37− arrays = sepBy1 (Array <$> bracketed delim) (char ',')
36+ arrays = sepBy1 (Array <$> array delim) (char ',')
3837 -- NB: Arrays seem to always be delimited by commas.
3938
4039-- | Recognizes a quoted string. Doesn't parse it in the sense that no
@@ -59,10 +58,9 @@ plain delim = copy <$> takeWhile1 (notInClass (delim:"\"{}"))
5958-- | Format an array format item, using the delimiter character if the item is
6059-- itself an array.
6160fmt :: Char -> ArrayFormat -> ByteString
62−fmt c x =
63− case x of
64− Array items -> '{' `cons` delimit c items `snoc` '}'
65− Bytes bytes -> bytes
61+fmt c x = case x of
62+ Array items -> '{' `cons` delimit c items `snoc` '}'
63+ Bytes bytes -> bytes
6664
6765-- | Format a list of array format items, inserting the appropriate delimiter
6866-- between them. When the items are arrays, they will be delimited with