on master help sign in
Inline commaSeparated
commit674bd71bbdc02644f63219fe44341937f934f509 authorBryan O'Sullivan <bos@serpentine.com> dateFri 10 Jul 2015, 15:05 (11 years ago) parent96d070d
1 file changed+9−14
Data/Aeson/Parser/Internal.hs+9−14
Data/Aeson/Parser/Internal.hs+9−14
@@ -40,7 +40,7 @@ import Data.Text (Text)
4040import Data.Text.Encoding (decodeUtf8')
4141import Data.Text.Internal.Encoding.Utf8 (ord2, ord3, ord4)
4242import Data.Text.Internal.Unsafe.Char (ord)
43−import Data.Vector as Vector (Vector, fromList)
43+import Data.Vector as Vector (Vector, empty, fromList)
4444import Data.Word (Word8)
4545import Foreign.ForeignPtr (withForeignPtr)
4646import Foreign.Ptr (minusPtr)
@@ -136,25 +136,20 @@ array_' = {-# SCC "array_'" #-} do
136136 !vals <- arrayValues value'
137137 return (Array vals)
138138
139−commaSeparated :: Parser a -> Word8 -> Parser [a]
140−commaSeparated item endByte = do
139+arrayValues :: Parser Value -> Parser (Vector Value)
140+arrayValues val = do
141+ skipSpace
141142 w <- A.peekWord8'
142− if w == endByte
143− then A.anyWord8 >> return []
144− else loop
143+ if w == CLOSE_SQUARE
144+ then A.anyWord8 >> return Vector.empty
145+ else Vector.fromList <$> loop
145146 where
146147 loop = do
147− v <- item <* skipSpace
148− ch <- A.satisfy $ \w -> w == COMMA || w == endByte
148+ v <- val <* skipSpace
149+ ch <- A.satisfy $ \w -> w == COMMA || w == CLOSE_SQUARE
149150 if ch == COMMA
150151 then skipSpace >> (v:) <$> loop
151152 else return [v]
152−{-# INLINE commaSeparated #-}
153−
154−arrayValues :: Parser Value -> Parser (Vector Value)
155−arrayValues val = do
156− skipSpace
157− Vector.fromList <$> commaSeparated val CLOSE_SQUARE
158153{-# INLINE arrayValues #-}
159154
160155-- | Parse any JSON value. You should usually 'json' in preference to