mirror of
https://github.com/ChrisPenner/json-to-haskell.git
synced 2024-09-11 20:38:48 +03:00
some package cleanup
This commit is contained in:
parent
b0523174b0
commit
0ad0230d19
@ -7,8 +7,6 @@ import Lib
|
||||
import Data.Aeson hiding (defaultOptions)
|
||||
import Text.RawString.QQ (r)
|
||||
import Data.Text.IO as T
|
||||
import qualified Data.Text as T
|
||||
import Data.Maybe
|
||||
|
||||
value :: Either String Value
|
||||
value = eitherDecode ([r|
|
||||
|
@ -4,7 +4,7 @@ cabal-version: 1.12
|
||||
--
|
||||
-- see: https://github.com/sol/hpack
|
||||
--
|
||||
-- hash: 135f22ba221b2ed4f8af0f29eca903bdb6af10a7baf28da58f27cd1e2ec7e244
|
||||
-- hash: e053adad71ecec8bce550314e66eea9ce8febba4bed55931d2649776b8e405de
|
||||
|
||||
name: json-to-haskell
|
||||
version: 0.1.0.0
|
||||
@ -28,7 +28,6 @@ source-repository head
|
||||
library
|
||||
exposed-modules:
|
||||
Lib
|
||||
Test
|
||||
other-modules:
|
||||
Paths_json_to_haskell
|
||||
hs-source-dirs:
|
||||
@ -39,7 +38,6 @@ library
|
||||
, aeson-extra
|
||||
, base >=4.7 && <5
|
||||
, bimap
|
||||
, bytestring
|
||||
, casing
|
||||
, containers
|
||||
, microlens-platform
|
||||
@ -63,7 +61,6 @@ executable json-to-haskell-exe
|
||||
, aeson-extra
|
||||
, base >=4.7 && <5
|
||||
, bimap
|
||||
, bytestring
|
||||
, casing
|
||||
, containers
|
||||
, json-to-haskell
|
||||
@ -90,7 +87,6 @@ test-suite json-to-haskell-test
|
||||
, aeson-extra
|
||||
, base >=4.7 && <5
|
||||
, bimap
|
||||
, bytestring
|
||||
, casing
|
||||
, containers
|
||||
, hspec
|
||||
|
@ -26,14 +26,13 @@ dependencies:
|
||||
- aeson-extra
|
||||
- containers
|
||||
- unordered-containers
|
||||
- vector
|
||||
- text
|
||||
- mtl
|
||||
- bytestring
|
||||
- casing
|
||||
- microlens-platform
|
||||
- nonempty-containers
|
||||
- bimap
|
||||
- microlens-platform
|
||||
- vector
|
||||
|
||||
ghc-options:
|
||||
- -Wall
|
||||
|
62
src/Lib.hs
62
src/Lib.hs
@ -11,26 +11,26 @@
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
module Lib where
|
||||
|
||||
import Data.Aeson hiding (Options)
|
||||
import Data.Aeson.Extra.Recursive
|
||||
import Data.Functor.Foldable hiding (fold)
|
||||
import Control.Monad.Reader
|
||||
import Control.Monad.State
|
||||
import Control.Monad.Writer
|
||||
import Data.Aeson (Value)
|
||||
import Data.Aeson.Extra.Recursive (ValueF(..))
|
||||
import Data.Char (isAlpha, isAlphaNum)
|
||||
import Data.Foldable (for_, fold)
|
||||
import Data.Functor.Foldable (cata)
|
||||
import Data.Maybe (catMaybes)
|
||||
import Data.Either (fromRight)
|
||||
import Lens.Micro.Platform (makeLenses, (<&>), (+~), view)
|
||||
import Text.Casing (toPascal, toCamel, fromAny)
|
||||
import qualified Data.Bimap as BM
|
||||
import qualified Data.HashMap.Strict as HM
|
||||
import qualified Data.List as L
|
||||
import qualified Data.List.NonEmpty as NE
|
||||
import qualified Data.Map as M
|
||||
import qualified Data.Set.NonEmpty as NES
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Vector as V
|
||||
import qualified Data.HashMap.Strict as HM
|
||||
import Control.Monad.Reader
|
||||
import Control.Monad.Writer
|
||||
import Control.Monad.State
|
||||
import Data.Foldable
|
||||
import Text.Casing
|
||||
import Lens.Micro.Platform
|
||||
import qualified Data.Map as M
|
||||
import Data.Maybe
|
||||
import Data.Either
|
||||
import Data.Char
|
||||
import qualified Data.List.NonEmpty as NE
|
||||
import Data.Set.NonEmpty as NES
|
||||
import qualified Data.List as L
|
||||
import qualified Data.Bimap as BM
|
||||
|
||||
data NumberPreference =
|
||||
SmartFloats
|
||||
@ -56,9 +56,6 @@ data ListType =
|
||||
| UseVector
|
||||
deriving (Show, Eq)
|
||||
|
||||
|
||||
|
||||
|
||||
data Options = Options
|
||||
{ _tabStop :: Int
|
||||
, _numberPreference :: NumberPreference
|
||||
@ -120,9 +117,6 @@ data Struct (r :: RecordType) where
|
||||
SNull :: Struct r
|
||||
SString :: Struct r
|
||||
SValue :: Struct r
|
||||
-- It's possible it's a sum of multiple possible types
|
||||
-- | SSum [Struct]
|
||||
-- SOptional :: Struct
|
||||
deriving instance Show (Struct r)
|
||||
deriving instance Eq (Struct r)
|
||||
deriving instance Ord (Struct r)
|
||||
@ -328,19 +322,6 @@ buildType =
|
||||
UseString -> "String"
|
||||
UseByteString -> "ByteString"
|
||||
UseText -> "Text"
|
||||
-- SOptional s -> tell "Maybe " >> parens (builder s)
|
||||
|
||||
-- Normalize records to ensure only one name for each (structural) record as well no duplicate
|
||||
-- names
|
||||
-- normalizeStructRefs :: HM.HashMap T.Text (S.Set (RecordRep 'Ref)) -> HM.HashMap T.Text (RecordRep 'Ref)
|
||||
-- normalizeStructRefs hm = _
|
||||
-- let listOfAll = M.fromList . expand . HM.toList $ hm
|
||||
-- in _
|
||||
-- where
|
||||
-- expand xs = flip evalStateT mempty $ do
|
||||
-- (name, records) <- lift $ xs
|
||||
-- record <- lift $ S.toList records
|
||||
-- return [(name, record)]
|
||||
|
||||
buildAllStructs :: Options -> BM.Bimap T.Text (RecordRep 'Ref) -> T.Text
|
||||
buildAllStructs opts (BM.toMap -> m) = execWriter . flip runReaderT (Env opts 0) $ do
|
||||
@ -356,16 +337,15 @@ buildAllStructs opts (BM.toMap -> m) = execWriter . flip runReaderT (Env opts 0)
|
||||
, "import Data.Vector (Vector)"
|
||||
]
|
||||
newline
|
||||
flip M.traverseWithKey m $ \k v -> do
|
||||
void . flip M.traverseWithKey m $ \k v -> do
|
||||
buildRecordDef k v
|
||||
newline
|
||||
flip M.traverseWithKey m $ \k v -> do
|
||||
void . flip M.traverseWithKey m $ \k v -> do
|
||||
buildToJSONInstance k v
|
||||
newline
|
||||
flip M.traverseWithKey m $ \k v -> do
|
||||
void . flip M.traverseWithKey m $ \k v -> do
|
||||
buildFromJSONInstance k v
|
||||
newline
|
||||
|
||||
|
||||
escapeQuotes :: T.Text -> T.Text
|
||||
escapeQuotes = T.replace "\"" "\\\""
|
||||
|
Loading…
Reference in New Issue
Block a user