aeson-qq 0.7.4 → 0.8.0
raw patch · 3 files changed
+34/−33 lines, 3 filesdep +attoparsecdep +scientificPVP ok
version bump matches the API change (PVP)
Dependencies added: attoparsec, scientific
API changes (from Hackage documentation)
Files
- aeson-qq.cabal +5/−1
- src/Data/Aeson/QQ.hs +1/−1
- src/Data/JSON/QQ.hs +28/−31
aeson-qq.cabal view
@@ -1,5 +1,5 @@ name: aeson-qq-version: 0.7.4+version: 0.8.0 synopsis: JSON quasiquoter for Haskell description: @aeson-qq@ provides a JSON quasiquoter for Haskell. .@@ -37,6 +37,8 @@ build-depends: base >= 4.5 && < 5 , text+ , attoparsec+ , scientific , vector , aeson >= 0.6 , parsec@@ -58,6 +60,8 @@ build-depends: base >= 4.5 && < 5 , text+ , attoparsec+ , scientific , vector , aeson , parsec
src/Data/Aeson/QQ.hs view
@@ -47,6 +47,6 @@ HashStringKey k -> [|(T.pack k, $(toExp value))|] HashVarKey k -> [|(T.pack $(dyn k), $(toExp value))|] toExp (JsonArray arr) = [|Array $ V.fromList $(ListE <$> mapM toExp arr)|]-toExp (JsonNumber _ rat) = [|Number (fromRational $(return $ LitE $ RationalL rat))|]+toExp (JsonNumber n) = [|Number (fromRational $(return $ LitE $ RationalL (toRational n)))|] toExp (JsonBool b) = [|Bool b|] toExp (JsonCode e) = [|toJSON $(return e)|]
src/Data/JSON/QQ.hs view
@@ -1,12 +1,12 @@ module Data.JSON.QQ (JsonValue (..), HashKey (..), parsedJson) where -import Control.Applicative--import Language.Haskell.TH--import Text.ParserCombinators.Parsec hiding (many, (<|>))--import Language.Haskell.Meta.Parse+import Control.Applicative+import Language.Haskell.TH+import Text.ParserCombinators.Parsec hiding (many, (<|>))+import Language.Haskell.Meta.Parse+import qualified Data.Attoparsec.Text as A+import Data.Scientific (Scientific)+import qualified Data.Text as T parsedJson :: String -> Either ParseError JsonValue parsedJson = parse (jpValue <* eof) "txt"@@ -17,7 +17,7 @@ data JsonValue = JsonNull | JsonString String- | JsonNumber Bool Rational+ | JsonNumber Scientific | JsonObject [(HashKey,JsonValue)] | JsonArray [JsonValue] | JsonBool Bool@@ -57,10 +57,27 @@ jpString = between (char '"') (char '"') (option [""] $ many chars) >>= return . JsonString . concat -- do jpNumber :: JsonParser-jpNumber = do- val <- float- return $ JsonNumber False (toRational val)+jpNumber = JsonNumber <$> do+ isMinus <- option "" (string "-")+ d <- many1 digit+ o <- option "" withDot+ e <- option "" withE+ convert (isMinus ++ d ++ o ++ e)+ where+ withE = do+ e <- char 'e' <|> char 'E'+ plusMinus <- option "" (string "+" <|> string "-")+ d <- many digit+ return $ e : plusMinus ++ d + withDot = do+ o <- char '.'+ d <- many digit+ return $ o:d++ convert :: Monad m => String -> m Scientific+ convert = either fail return . A.parseOnly (A.scientific <* A.endOfInput) . T.pack+ jpObject :: JsonParser jpObject = do list <- between (char '{') (char '}') (commaSep jpHash)@@ -91,26 +108,6 @@ ------- -- helpers for parser/grammar--float :: CharParser st Double-float = do- isMinus <- option ' ' (char '-')- d <- many1 digit- o <- option "" withDot- e <- option "" withE- return $ (read $ isMinus : d ++ o ++ e :: Double)- where- withE = do- e <- char 'e' <|> char 'E'- plusMinus <- option "" (string "+" <|> string "-")- d <- many digit- return $ e : plusMinus ++ d-- withDot = do- o <- char '.'- d <- many digit- return $ o:d- quotedString :: CharParser () String quotedString = concat <$> between (char '"') (char '"') (option [""] $ many chars)