on develop help sign in
Merge pull request #123 from korayal/upgrade-gen
765a478Michael Xavier
gen/gogol-gen.cabal+3−3
@@ -55,12 +55,12 @@ executable gogol-gen
55 , errors >= 2.1.2
55 , errors >= 2.1.2
56 , formatting
56 , formatting
57 , hashable
57 , hashable
58− , haskell-src-exts == 1.17.1
58+ , haskell-src-exts == 1.20.3
59− , hindent == 4.6.4
59+ , hindent == 5.2.7
60 , lens
60 , lens
61 , mtl
61 , mtl
62 , optparse-applicative
62 , optparse-applicative
63− , pandoc < 2.0
63+ , pandoc
64 , parsec
64 , parsec
65 , semigroups
65 , semigroups
66 , system-fileio
66 , system-fileio
gen/src/Gen/AST/Flatten.hs+1−5
@@ -1,14 +1,10 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
5−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6−{-# LANGUAGE KindSignatures #-}
7{-# LANGUAGE LambdaCase #-}
4{-# LANGUAGE LambdaCase #-}
8{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
9{-# LANGUAGE RankNTypes #-}
6{-# LANGUAGE RankNTypes #-}
10{-# LANGUAGE RecordWildCards #-}
7{-# LANGUAGE RecordWildCards #-}
11−{-# LANGUAGE TemplateHaskell #-}
12{-# LANGUAGE TupleSections #-}
8{-# LANGUAGE TupleSections #-}
13
9
14-- Module : Gen.AST.Flatten
10-- Module : Gen.AST.Flatten
@@ -136,7 +132,7 @@ resource :: Map Local (Param Global)
136 -> Resource (Fix Schema)
132 -> Resource (Fix Schema)
137 -> AST (Resource Global)
133 -> AST (Resource Global)
138resource qs suf g r@Resource {..} = do
134resource qs suf g r@Resource {..} = do
139− rs <- Map.traverseWithKey (\l -> resource qs suf (reference g l)) _rResources
135+ rs <- Map.traverseWithKey (resource qs suf . reference g) _rResources
140 ms <- traverse (method qs suf) _rMethods
136 ms <- traverse (method qs suf) _rMethods
141 pure $! r
137 pure $! r
142 { _rResources = rs
138 { _rResources = rs
gen/src/Gen/AST/Render.hs+32−28
@@ -1,15 +1,11 @@
1−{-# LANGUAGE DataKinds #-}
1+{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE DeriveGeneric #-}
3−{-# LANGUAGE FlexibleContexts #-}
2+{-# LANGUAGE FlexibleContexts #-}
4−{-# LANGUAGE FlexibleInstances #-}
3+{-# LANGUAGE FlexibleInstances #-}
5−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6−{-# LANGUAGE KindSignatures #-}
7−{-# LANGUAGE LambdaCase #-}
4+{-# LANGUAGE LambdaCase #-}
8−{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE OverloadedStrings #-}
9−{-# LANGUAGE RankNTypes #-}
6+{-# LANGUAGE RankNTypes #-}
10−{-# LANGUAGE RecordWildCards #-}
7+{-# LANGUAGE RecordWildCards #-}
11−{-# LANGUAGE TemplateHaskell #-}
12−{-# LANGUAGE ViewPatterns #-}
8+{-# LANGUAGE ViewPatterns #-}
13
9
14-- Module : Gen.AST.Render
10-- Module : Gen.AST.Render
15-- Copyright : (c) 2015-2016 Brendan Hay
11-- Copyright : (c) 2015-2016 Brendan Hay
@@ -25,18 +21,21 @@ module Gen.AST.Render
25import Control.Applicative
21import Control.Applicative
26import Control.Error
22import Control.Error
27import Control.Lens hiding (enum, lens)
23import Control.Lens hiding (enum, lens)
24+import qualified Data.ByteString.Char8 as C8
25+import qualified Data.ByteString.Lazy.Builder as LBB
26+import qualified Data.ByteString.Lazy.Char8 as LBS
28import Data.Char (isSpace)
27import Data.Char (isSpace)
29import qualified Data.HashMap.Strict as Map
28import qualified Data.HashMap.Strict as Map
30import Data.Maybe
29import Data.Maybe
31import Data.Semigroup ((<>))
30import Data.Semigroup ((<>))
32import Data.String
31import Data.String
33import qualified Data.Text.Lazy as LText
32import qualified Data.Text.Lazy as LText
34−import qualified Data.Text.Lazy.Builder as Build
35import Gen.AST.Solve (getSolved)
33import Gen.AST.Solve (getSolved)
36import Gen.Formatting
34import Gen.Formatting
37import Gen.Syntax
35import Gen.Syntax
38import Gen.Types
36import Gen.Types
39import HIndent
37import HIndent
38+import HIndent.Types
40import Language.Haskell.Exts.Build (name)
39import Language.Haskell.Exts.Build (name)
41import Language.Haskell.Exts.Pretty as PP
40import Language.Haskell.Exts.Pretty as PP
42import Prelude hiding (sum)
41import Prelude hiding (sum)
@@ -131,7 +130,10 @@ renderMethod s root suf m@Method {..} = do
131 typ <- reserveType typ'
130 typ <- reserveType typ'
132
131
133 x@Solved {..} <- getSolved typ
132 x@Solved {..} <- getSolved typ
134− Just d <- renderSchema x
133+ d' <- renderSchema x
134+ d <- case d' of
135+ Nothing -> error "failed to render the schema"
136+ Just d'' -> pure d''
135
137
136 i <- pp Print $ requestDecl _unique _prefix alias url (props _schema) m
138 i <- pp Print $ requestDecl _unique _prefix alias url (props _schema) m
137 dl <- pp Print $ downloadDecl _unique _prefix alias url (props _schema) m
139 dl <- pp Print $ downloadDecl _unique _prefix alias url (props _schema) m
@@ -170,17 +172,22 @@ data PP
170
172
171pp :: (Pretty a, Show a) => PP -> a -> AST Rendered
173pp :: (Pretty a, Show a) => PP -> a -> AST Rendered
172pp i x
174pp i x
173− | i == Indent = result (reformat johanTibell Nothing p)
175+ | i == Indent = result (reformat hindentConfig Nothing Nothing p)
174− | otherwise = pure p
176+ | otherwise = pure (LText.pack (C8.unpack p))
175 where
177 where
176− result = hoistEither . bimap e Build.toLazyText
178+ result = hoistEither . bimap (e . LText.pack) (LText.pack . LBS.unpack . LBB.toLazyByteString)
177
179
178− e = flip mappend ("\nSyntax:\n" <> p <> "\nAST:\n" <> LText.pack (show x)) . LText.pack
180+ e = flip mappend ("\nSyntax:\n" <> LText.pack (C8.unpack p) <> "\nAST:\n" <> LText.pack (show x))
179
181
180− p = LText.dropWhile isSpace
182+ p = C8.dropWhile isSpace
181− . LText.pack
183+ . C8.pack
182 $ prettyPrintStyleMode s m x
184 $ prettyPrintStyleMode s m x
183
185
186+ hindentConfig = defaultConfig
187+ { configTrailingNewline = False
188+ , configSortImports = False
189+ }
190+
184 s = style
191 s = style
185 { mode = PageMode
192 { mode = PageMode
186 , lineLength = 80
193 , lineLength = 80
@@ -197,15 +204,12 @@ pp i x
197-- FIXME: dirty hack to render smart ctor parameter comments.
204-- FIXME: dirty hack to render smart ctor parameter comments.
198comments :: Prefix -> Map Local Solved -> Rendered -> Rendered
205comments :: Prefix -> Map Local Solved -> Rendered -> Rendered
199comments p (Map.toList -> rs) =
206comments p (Map.toList -> rs) =
200− LText.replace " :: " "\n :: "
207+ LText.replace " :: " "\n :: " .
201− . LText.intercalate "\n -> "
208+ LText.intercalate "\n -> " .
202− . zipWith rel ps
203− . map LText.strip
209+ zipWith rel ps . map LText.strip . LText.splitOn "->"
204− . LText.splitOn "->"
205 where
210 where
206 ks = filter (parameter . _schema . snd) rs
211 ks = filter (parameter . _schema . snd) rs
207 ps = map (Just . fst) ks ++ repeat Nothing
212 ps = map (Just . fst) ks ++ repeat Nothing
208−
209− rel Nothing t = t
213+ rel Nothing t = t
210 rel (Just l) t =
214 rel (Just l) t =
211− t <> " -- ^ '" <> fromString (PP.prettyPrint (lname p l)) <> "'"
215+ t <> " -- ^ '" <> fromString (PP.prettyPrint (lname p l)) <> "'"
gen/src/Gen/AST/Solve.hs+2−7
@@ -1,14 +1,9 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
5−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6−{-# LANGUAGE KindSignatures #-}
7{-# LANGUAGE LambdaCase #-}
4{-# LANGUAGE LambdaCase #-}
8{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
9{-# LANGUAGE RankNTypes #-}
6{-# LANGUAGE RankNTypes #-}
10−{-# LANGUAGE RecordWildCards #-}
11−{-# LANGUAGE TemplateHaskell #-}
12{-# LANGUAGE ViewPatterns #-}
7{-# LANGUAGE ViewPatterns #-}
13
8
14-- Module : Gen.AST.Solve
9-- Module : Gen.AST.Solve
@@ -94,7 +89,7 @@ getType g = loc "getType" g $ memo typed g go
94 --- FIXME: add natural/numeric manipulations
89 --- FIXME: add natural/numeric manipulations
95 SLit _ l -> res (TLit l)
90 SLit _ l -> res (TLit l)
96 SEnm {} -> res (TType g)
91 SEnm {} -> res (TType g)
97− SArr _ (Arr e) -> (TList <$> (getType e)) >>= pure . may
92+ SArr _ (Arr e) -> may <$> (TList <$> getType e)
98 SObj {} -> res (TType g)
93 SObj {} -> res (TType g)
99 SRef _ r
94 SRef _ r
100 | ref r /= g -> req <$> getType (ref r)
95 | ref r /= g -> req <$> getType (ref r)
@@ -195,7 +190,7 @@ overlap :: (Eq a, Hashable a) => Set a -> Set a -> Bool
195overlap xs ys = not . Set.null $ Set.intersection xs ys
190overlap xs ys = not . Set.null $ Set.intersection xs ys
196
191
197acronymPrefixes :: Global -> [CI Text]
192acronymPrefixes :: Global -> [CI Text]
198−acronymPrefixes (global -> renameSpecial -> g) =
193+acronymPrefixes (global -> (renameSpecial -> g)) =
199 filter (/= full) $ map CI.mk (xs ++ map suffix ys ++ zs)
194 filter (/= full) $ map CI.mk (xs ++ map suffix ys ++ zs)
200 where
195 where
201 -- Take the next char
196 -- Take the next char
gen/src/Gen/Formatting.hs−2
@@ -1,5 +1,3 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−
3-- Module : Gen.Formatting
1-- Module : Gen.Formatting
4-- Copyright : (c) 2015-2016 Brendan Hay
2-- Copyright : (c) 2015-2016 Brendan Hay
5-- License : Mozilla Public License, v. 2.0.
3-- License : Mozilla Public License, v. 2.0.
gen/src/Gen/IO.hs+2−2
@@ -1,6 +1,5 @@
1{-# LANGUAGE FlexibleContexts #-}
1{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE TupleSections #-}
4
3
5-- Module : Gen.IO
4-- Module : Gen.IO
6-- Copyright : (c) 2015-2016 Brendan Hay
5-- Copyright : (c) 2015-2016 Brendan Hay
@@ -27,13 +26,14 @@ import System.IO
27
26
28import UnexceptionalIO (fromIO, runUIO)
27import UnexceptionalIO (fromIO, runUIO)
29
28
29+import qualified Data.Text as Text
30import qualified Data.Text.Lazy as LText
30import qualified Data.Text.Lazy as LText
31import qualified Data.Text.Lazy.IO as LText
31import qualified Data.Text.Lazy.IO as LText
32import qualified Filesystem as FS
32import qualified Filesystem as FS
33import qualified Text.EDE as EDE
33import qualified Text.EDE as EDE
34
34
35run :: ExceptT Error IO a -> IO a
35run :: ExceptT Error IO a -> IO a
36−run = runScript . fmapLT LText.unpack
36+run = runScript . fmapLT (Text.pack . LText.unpack)
37
37
38io :: MonadIO m => IO a -> ExceptT Error m a
38io :: MonadIO m => IO a -> ExceptT Error m a
39io = ExceptT . fmap (first (LText.pack . show)) . liftIO . runUIO . fromIO
39io = ExceptT . fmap (first (LText.pack . show)) . liftIO . runUIO . fromIO
gen/src/Gen/Orphans.hs+4−4
@@ -16,8 +16,8 @@ import Data.String
16import Language.Haskell.Exts.Build
16import Language.Haskell.Exts.Build
17import Language.Haskell.Exts.Syntax
17import Language.Haskell.Exts.Syntax
18
18
19−instance Hashable Name
19+instance Hashable l => Hashable (Name l)
20
20
21−instance IsString Name where fromString = name
21+instance IsString (Name ()) where fromString = name
22−instance IsString QName where fromString = UnQual . name
22+instance IsString (QName ()) where fromString = UnQual () . name
23−instance IsString QOp where fromString = op . sym
23+instance IsString (QOp ()) where fromString = op . sym
gen/src/Gen/Syntax.hs+263−239
@@ -1,6 +1,5 @@
1{-# LANGUAGE LambdaCase #-}
1{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE TupleSections #-}
4{-# LANGUAGE ViewPatterns #-}
3{-# LANGUAGE ViewPatterns #-}
5
4
6-- Module : Gen.Syntax
5-- Module : Gen.Syntax
@@ -26,39 +25,38 @@ import Gen.Text
26import Gen.Types
25import Gen.Types
27import Language.Haskell.Exts.Build (app, appFun, infixApp, lamE, listE, name, noBinds, paren, patBind, pvar, sfun, strE, sym,
26import Language.Haskell.Exts.Build (app, appFun, infixApp, lamE, listE, name, noBinds, paren, patBind, pvar, sfun, strE, sym,
28 var)
27 var)
29−import Language.Haskell.Exts.SrcLoc
30import Language.Haskell.Exts.Syntax hiding (Alt, Int, Lit)
28import Language.Haskell.Exts.Syntax hiding (Alt, Int, Lit)
31
29
32−serviceSig :: Name -> Decl
30+serviceSig :: Name () -> Decl ()
33−serviceSig n = TypeSig noLoc [n] (TyCon "ServiceConfig")
31+serviceSig n = TypeSig () [n] (TyCon () "ServiceConfig")
34
32
35−serviceDecl :: Service a -> Name -> Decl
33+serviceDecl :: Service a -> Name () -> Decl ()
36−serviceDecl s n = sfun noLoc n [] (UnGuardedRhs rhs) noBinds
34+serviceDecl s n = sfun n [] (UnGuardedRhs () rhs) noBinds
37 where
35 where
38 rhs = appFun (var "defaultService")
36 rhs = appFun (var "defaultService")
39 [ app (var "ServiceId") (str (s ^. dId))
37 [ app (var "ServiceId") (str (s ^. dId))
40 , str . stripSuffix "/" $ stripPrefix "https://" (s ^. dRootUrl)
38 , str . stripSuffix "/" $ stripPrefix "https://" (s ^. dRootUrl)
41 ]
39 ]
42
40
43−scopeSig :: Name -> Text -> Decl
41+scopeSig :: Name () -> Text -> Decl ()
44−scopeSig n v = TypeSig noLoc [n] $
42+scopeSig n v = TypeSig () [n] $
45− TyApp (TyCon "Proxy") $
43+ TyApp () (TyCon () "Proxy") $
46− TyPromoted $ PromotedList True
44+ TyPromoted () $ PromotedList () True
47− [ TyPromoted $ PromotedString (Text.unpack v)
45+ [ TyPromoted () $ PromotedString () (Text.unpack v) (Text.unpack v)
48 ]
46 ]
49
47
50−scopeDecl :: Name -> Decl
48+scopeDecl :: Name () -> Decl ()
51−scopeDecl n = sfun noLoc n [] (UnGuardedRhs (var "Proxy")) noBinds
49+scopeDecl n = sfun n [] (UnGuardedRhs () (var "Proxy")) noBinds
52
50
53−apiAlias :: Name -> [Name] -> Decl
51+apiAlias :: Name () -> [Name ()] -> Decl ()
54−apiAlias n ls = TypeDecl noLoc n [] alias
52+apiAlias n ls = TypeDecl () (DHead () n) alias
55 where
53 where
56− alias = case map (TyCon . UnQual) ls of
54+ alias = case map (TyCon () . UnQual ()) ls of
57− [] -> unit_tycon
55+ [] -> unit_tycon ()
58− x:xs -> foldl' (\l r -> TyInfix l (UnQual (sym ":<|>")) r) x xs
56+ x:xs -> foldl' (\l r -> TyInfix () l ((UnpromotedName () . UnQual ()) (sym ":<|>")) r) x xs
59
57
60−verbAlias :: HasDescription a s => a -> Name -> Method Solved -> Decl
58+verbAlias :: HasDescription a s => a -> Name () -> Method Solved -> Decl ()
61−verbAlias d n m = TypeDecl noLoc n [] $ servantOr meta (catMaybes [down, up])
59+verbAlias d n m = TypeDecl () (DHead () n) $ servantOr meta (catMaybes [down, up])
62 where
60 where
63 meta = path $ metadataAlias m
61 meta = path $ metadataAlias m
64 down = path <$> downloadAlias m
62 down = path <$> downloadAlias m
@@ -68,18 +66,18 @@ verbAlias d n m = TypeDecl noLoc n [] $ servantOr meta (catMaybes [down, up])
68
66
69 root = subPaths (d ^. dServicePath) ++ requestPath m (_mPath m)
67 root = subPaths (d ^. dServicePath) ++ requestPath m (_mPath m)
70
68
71−metadataAlias :: Method Solved -> Type
69+metadataAlias :: Method Solved -> Type ()
72metadataAlias m = servantSub (jsonVerb m) (params ++ media)
70metadataAlias m = servantSub (jsonVerb m) (params ++ media)
73 where
71 where
74 params = requestQuery m (requestQueryParams m)
72 params = requestQuery m (requestQueryParams m)
75 media = case _mRequest m of
73 media = case _mRequest m of
76 Nothing -> []
74 Nothing -> []
77 Just b ->
75 Just b ->
78− [ TyApp (TyApp (TyCon "ReqBody") jsonMedia)
76+ [ TyApp () (TyApp () (TyCon () "ReqBody") jsonMedia)
79 (tycon (ref b))
77 (tycon (ref b))
80 ]
78 ]
81
79
82−downloadAlias :: Method Solved -> Maybe Type
80+downloadAlias :: Method Solved -> Maybe (Type ())
83downloadAlias m
81downloadAlias m
84 | _mSupportsMediaDownload m = Just download
82 | _mSupportsMediaDownload m = Just download
85 | otherwise = Nothing
83 | otherwise = Nothing
@@ -88,7 +86,7 @@ downloadAlias m
88
86
89 params = requestQuery m . Map.delete "alt" $ requestQueryParams m
87 params = requestQuery m . Map.delete "alt" $ requestQueryParams m
90
88
91−uploadAlias :: [Type] -> Method Solved -> Maybe Type
89+uploadAlias :: [Type ()] -> Method Solved -> Maybe (Type ())
92uploadAlias sub m
90uploadAlias sub m
93 | _mSupportsMediaUpload m = Just upload
91 | _mSupportsMediaUpload m = Just upload
94 | otherwise = Nothing
92 | otherwise = Nothing
@@ -104,16 +102,16 @@ uploadAlias sub m
104 media = case _mRequest m of
102 media = case _mRequest m of
105 Just b ->
103 Just b ->
106 [ multipartParam
104 [ multipartParam
107− , TyApp (TyApp (TyCon "MultipartRelated") jsonMedia)
105+ , TyApp () (TyApp () (TyCon () "MultipartRelated") jsonMedia)
108 (tycon (ref b))
106 (tycon (ref b))
109 ]
107 ]
110
108
111 Nothing ->
109 Nothing ->
112 [ mediaParam
110 [ mediaParam
113− , TyCon "AltMedia"
111+ , TyCon () "AltMedia"
114 ]
112 ]
115
113
116−requestPath :: Method Solved -> Text -> [Type]
114+requestPath :: Method Solved -> Text -> [Type ()]
117requestPath m = map go . extractPath
115requestPath m = map go . extractPath
118 where
116 where
119 go (Left t) = sing t
117 go (Left t) = sing t
@@ -121,29 +119,29 @@ requestPath m = map go . extractPath
121 Nothing -> error $ "Unable to find path parameter " ++ show l
119 Nothing -> error $ "Unable to find path parameter " ++ show l
122 Just x -> case c of
120 Just x -> case c of
123 Nothing | x ^. iRepeated ->
121 Nothing | x ^. iRepeated ->
124− TyApp (TyApp (TyCon "Captures")
122+ TyApp () (TyApp () (TyCon () "Captures")
125 (sing (local l)))
123 (sing (local l)))
126 (terminalType (_type (_pParam x)))
124 (terminalType (_type (_pParam x)))
127
125
128 Nothing ->
126 Nothing ->
129− TyApp (TyApp (TyCon "Capture")
127+ TyApp () (TyApp () (TyCon () "Capture")
130 (sing (local l)))
128 (sing (local l)))
131 (terminalType (_type (_pParam x)))
129 (terminalType (_type (_pParam x)))
132
130
133 Just y ->
131 Just y ->
134− TyApp (TyApp (TyApp (TyCon "CaptureMode")
132+ TyApp () (TyApp () (TyApp () (TyCon () "CaptureMode")
135 (sing (local l)))
133 (sing (local l)))
136 (sing y))
134 (sing y))
137 (terminalType (_type (_pParam x)))
135 (terminalType (_type (_pParam x)))
138
136
139−requestQuery :: Method Solved -> Map Local (Param Solved) -> [Type]
137+requestQuery :: Method Solved -> Map Local (Param Solved) -> [Type ()]
140requestQuery m xs = mapMaybe go $
138requestQuery m xs = mapMaybe go $
141 orderParams fst (Map.toList xs) (_mParameterOrder m)
139 orderParams fst (Map.toList xs) (_mParameterOrder m)
142 where
140 where
143 go (k, x) = case _pLocation x of
141 go (k, x) = case _pLocation x of
144 Query | x ^. iRepeated
142 Query | x ^. iRepeated
145− -> Just $ TyApp (TyApp (TyCon "QueryParams") n) t
143+ -> Just $ TyApp () (TyApp () (TyCon () "QueryParams") n) t
146− Query -> Just $ TyApp (TyApp (TyCon "QueryParam") n) t
144+ Query -> Just $ TyApp () (TyApp () (TyCon () "QueryParam") n) t
147 Path -> Nothing
145 Path -> Nothing
148 where
146 where
149 t = terminalType (_type (_pParam x))
147 t = terminalType (_type (_pParam x))
@@ -152,52 +150,47 @@ requestQuery m xs = mapMaybe go $
152requestQueryParams :: Method a -> Map Local (Param a)
150requestQueryParams :: Method a -> Map Local (Param a)
153requestQueryParams = Map.filter ((/= Path) . _pLocation) . _mParameters
151requestQueryParams = Map.filter ((/= Path) . _pLocation) . _mParameters
154
152
155−servantOr, servantSub :: Type -> [Type] -> Type
153+servantOr, servantSub :: Type () -> [Type ()] -> Type ()
156−servantOr = foldl' (\l r -> TyInfix l (UnQual (sym ":<|>")) r)
154+servantOr = foldl' (\l r -> TyInfix () l ((UnpromotedName () . UnQual ()) (sym ":<|>")) r)
157−servantSub = foldr' (\l r -> TyInfix l (UnQual (sym ":>")) r)
155+servantSub = foldr' (\l r -> TyInfix () l ((UnpromotedName () . UnQual ()) (sym ":>")) r)
158
156
159−jsonVerb :: Method a -> Type
157+jsonVerb :: Method a -> Type ()
160jsonVerb m =
158jsonVerb m =
161− TyApp (TyApp (httpMethod m) jsonMedia)
159+ TyApp () (TyApp () (httpMethod m) jsonMedia)
162− $ maybe (TyCon "()") (tycon . ref) (_mResponse m)
160+ $ maybe (TyCon () "()") (tycon . ref) (_mResponse m)
163
161
164−downloadVerb :: Method a -> Type
162+downloadVerb :: Method a -> Type ()
165downloadVerb m =
163downloadVerb m =
166− TyApp (TyApp (httpMethod m) streamMedia)
164+ TyApp () (TyApp () (httpMethod m) streamMedia)
167− (TyCon "Stream")
165+ (TyCon () "Stream")
168
166
169−httpMethod :: Method a -> Type
167+httpMethod :: Method a -> Type ()
170−httpMethod = TyCon . unqual . Text.unpack . Text.toTitle . _mHttpMethod
168+httpMethod = TyCon () . unqual . Text.unpack . Text.toTitle . _mHttpMethod
171
169
172−subPaths :: Text -> [Type]
170+subPaths :: Text -> [Type ()]
173subPaths = map sing . filter (not . Text.null) . Text.split (== '/')
171subPaths = map sing . filter (not . Text.null) . Text.split (== '/')
174
172
175−jsonMedia, streamMedia :: Type
173+jsonMedia, streamMedia :: Type ()
176jsonMedia = tylist ["JSON"]
174jsonMedia = tylist ["JSON"]
177streamMedia = tylist ["OctetStream"]
175streamMedia = tylist ["OctetStream"]
178
176
179−downloadParam :: Type
177+downloadParam :: Type ()
180downloadParam =
178downloadParam =
181− TyApp (TyApp (TyCon "QueryParam") (sing "alt"))
179+ TyApp () (TyApp () (TyCon () "QueryParam") (sing "alt"))
182− (TyCon "AltMedia")
180+ (TyCon () "AltMedia")
183
181
184−mediaParam :: Type
182+mediaParam :: Type ()
185mediaParam =
183mediaParam =
186− TyApp (TyApp (TyCon "QueryParam") (sing "uploadType"))
184+ TyApp () (TyApp () (TyCon () "QueryParam") (sing "uploadType"))
187− (TyCon "AltMedia")
185+ (TyCon () "AltMedia")
188
186
189−multipartParam :: Type
187+multipartParam :: Type ()
190multipartParam =
188multipartParam =
191− TyApp (TyApp (TyCon "QueryParam") (sing "uploadType"))
189+ TyApp () (TyApp () (TyCon () "QueryParam") (sing "uploadType"))
192− (TyCon "Multipart")
190+ (TyCon () "Multipart")
193
191
194−metadataPat, downloadPat, uploadPat :: Method a -> Pat
195−metadataPat = pattern 1
196−downloadPat = pattern 2
197−uploadPat = pattern 3
198−
199−pattern :: Integer -> Method a -> Pat
192+pattern' :: Integer -> Method a -> Pat ()
200−pattern n m = case (n, down, up) of
193+pattern' n m = case (n, down, up) of
201 (1, True, True) -> infixOr go (infixOr wild wild)
194 (1, True, True) -> infixOr go (infixOr wild wild)
202 (2, True, True) -> infixOr wild (infixOr go wild)
195 (2, True, True) -> infixOr wild (infixOr go wild)
203 (_, True, True) -> infixOr wild (infixOr wild go)
196 (_, True, True) -> infixOr wild (infixOr wild go)
@@ -214,51 +207,57 @@ pattern n m = case (n, down, up) of
214 up = _mSupportsMediaUpload m
207 up = _mSupportsMediaUpload m
215
208
216 go = pvar "go"
209 go = pvar "go"
217− wild = PWildCard
210+ wild = PWildCard ()
211+
212+ infixOr l = PInfixApp () l (UnQual () (sym ":<|>"))
213+
214+metadataPat, downloadPat, uploadPat :: Method a -> Pat ()
215+metadataPat = pattern' 1
216+downloadPat = pattern' 2
217+uploadPat = pattern' 3
218
218
219− infixOr l r = PInfixApp l (UnQual (sym ":<|>")) r
220
219
221downloadDecl :: Global
220downloadDecl :: Global
222 -> Prefix
221 -> Prefix
223− -> Name
222+ -> Name ()
224− -> Name
223+ -> Name ()
225 -> [Local]
224 -> [Local]
226 -> Method Solved
225 -> Method Solved
227− -> Decl
226+ -> Decl ()
228downloadDecl n pre api url fs m =
227downloadDecl n pre api url fs m =
229− googleRequestDecl ty [rs, ss] [alt] pre api url m pat prec
228+ googleRequestDecl (TyParen () ty) [rs, ss] [alt] pre api url m pat prec
230 where
229 where
231− ty = TyApp (TyCon "MediaDownload") (tycon n)
230+ ty = TyApp () (TyCon () "MediaDownload") (tycon n)
232
231
233− rs = InsType noLoc (TyApp (TyCon "Rs") ty) (TyCon "Stream")
232+ rs = InsType () (TyApp () (TyCon () "Rs") ty) (TyCon () "Stream")
234
233
235− ss = InsType noLoc (TyApp (TyCon "Scopes") ty) $
234+ ss = InsType () (TyApp () (TyCon () "Scopes") ty) $
236− TyApp (TyCon "Scopes") (tycon n)
235+ TyApp () (TyCon () "Scopes") (tycon n)
237
236
238 alt = app (var "Just") (var "AltMedia")
237 alt = app (var "Just") (var "AltMedia")
239 pat = downloadPat m
238 pat = downloadPat m
240
239
241− prec = PApp (UnQual "MediaDownload")
240+ prec = PApp () (UnQual () "MediaDownload")
242− [ PRec (UnQual (dname' n)) [PFieldWildcard | not (null fs)]
241+ [ PRec () (UnQual () (dname' n)) [PFieldWildcard () | not (null fs)]
243 ]
242 ]
244
243
245uploadDecl :: Global
244uploadDecl :: Global
246 -> Prefix
245 -> Prefix
247− -> Name
246+ -> Name ()
248− -> Name
247+ -> Name ()
249 -> [Local]
248 -> [Local]
250 -> Method Solved
249 -> Method Solved
251− -> Decl
250+ -> Decl ()
252uploadDecl n pre api url fs m =
251uploadDecl n pre api url fs m =
253− googleRequestDecl ty [rs, ss] extras pre api url m pat prec
252+ googleRequestDecl (TyParen () ty) [rs, ss] extras pre api url m pat prec
254 where
253 where
255− ty = TyApp (TyCon "MediaUpload") (tycon n)
254+ ty = TyApp () (TyCon () "MediaUpload") (tycon n)
256
255
257− rs = InsType noLoc (TyApp (TyCon "Rs") ty) $
256+ rs = InsType () (TyApp () (TyCon () "Rs") ty) $
258− maybe unit_tycon (tycon . ref) (_mResponse m)
257+ maybe (unit_tycon ()) (tycon . ref) (_mResponse m)
259
258
260− ss = InsType noLoc (TyApp (TyCon "Scopes") ty) $
259+ ss = InsType () (TyApp () (TyCon () "Scopes") ty) $
261− TyApp (TyCon "Scopes") (tycon n)
260+ TyApp () (TyCon () "Scopes") (tycon n)
262
261
263 extras = maybeToList alt ++ [upl] ++ payload ++ [var media]
262 extras = maybeToList alt ++ [upl] ++ payload ++ [var media]
264 where
263 where
@@ -276,30 +275,32 @@ uploadDecl n pre api url fs m =
276
275
277 pat = uploadPat m
276 pat = uploadPat m
278
277
279− prec = PApp (UnQual "MediaUpload")
278+ prec = PApp () (UnQual () "MediaUpload")
280− [ PRec (UnQual (dname' n)) [PFieldWildcard | not (null fs)]
279+ [ PRec () (UnQual () (dname' n)) [PFieldWildcard () | not (null fs)]
281− , PVar media
280+ , PVar () media
282 ]
281 ]
283
282
284 media = name "body"
283 media = name "body"
285
284
286requestDecl :: Global
285requestDecl :: Global
287 -> Prefix
286 -> Prefix
288− -> Name
287+ -> Name ()
289− -> Name
288+ -> Name ()
290 -> [Local]
289 -> [Local]
291 -> Method Solved
290 -> Method Solved
292− -> Decl
291+ -> Decl ()
293requestDecl n pre api url fs m =
292requestDecl n pre api url fs m =
294 googleRequestDecl (tycon n) [rs, ss] extras pre api url m pat prec
293 googleRequestDecl (tycon n) [rs, ss] extras pre api url m pat prec
295 where
294 where
295+ rs :: InstDecl ()
296− rs = InsType noLoc (TyApp (TyCon "Rs") (tycon n)) $
296+ rs = InsType () (TyApp () (TyCon () "Rs") (tycon n)) $
297− maybe unit_tycon (tycon . ref) (_mResponse m)
297+ maybe (unit_tycon ()) (tycon . ref) (_mResponse m)
298
298
299+ ss :: InstDecl ()
299− ss = InsType noLoc (TyApp (TyCon "Scopes") (tycon n)) $
300+ ss = InsType () (TyApp () (TyCon () "Scopes") (tycon n)) $
300− TyPromoted $
301+ TyPromoted () $
301− PromotedList True $
302+ PromotedList () True $
302− map (TyPromoted . PromotedString . Text.unpack) (_mScopes m)
303+ map (\m' -> TyPromoted () (PromotedString () (Text.unpack m') "Scopes")) (_mScopes m)
303
304
304 extras = catMaybes [alt, payload]
305 extras = catMaybes [alt, payload]
305 where
306 where
@@ -312,35 +313,35 @@ requestDecl n pre api url fs m =
312
313
313 pat = metadataPat m
314 pat = metadataPat m
314
315
315− prec = PRec (UnQual (dname' n)) [PFieldWildcard | not (null fs)]
316+ prec = PRec () (UnQual () (dname' n)) [PFieldWildcard () | not (null fs)]
316
317
317−googleRequestDecl :: Type
318+googleRequestDecl :: Type ()
318− -> [InstDecl]
319+ -> [InstDecl ()]
319− -> [Exp]
320+ -> [Exp ()]
320 -> Prefix
321 -> Prefix
321− -> Name
322+ -> Name ()
322− -> Name
323+ -> Name ()
323 -> Method Solved
324 -> Method Solved
324− -> Pat
325+ -> Pat ()
325− -> Pat
326+ -> Pat ()
326− -> Decl
327+ -> Decl ()
327googleRequestDecl n assoc extras pre api url m pat prec =
328googleRequestDecl n assoc extras pre api url m pat prec =
328− InstDecl noLoc Nothing [] [] (unqual "GoogleRequest") [n] (assoc ++ [request])
329+ InstDecl () Nothing (instrule "GoogleRequest" n) (Just (assoc ++ [request]))
329 where
330 where
330− request = InsDecl (FunBind [match])
331+ request = InsDecl () (FunBind () [match])
331
332
332− match = Match noLoc (name "requestClient") [prec] Nothing rhs (Just decls)
333+ match = Match () (name "requestClient") [prec] rhs (Just decls)
333
334
334− decls = BDecls
335+ decls = BDecls ()
335− [ patBind noLoc pat $
336+ [ patBind pat $
336− appFun (var "buildClient") $
337+ appFun (var "buildClient")
337− [ ExpTypeSig noLoc (var "Proxy") $
338+ [ ExpTypeSig () (var "Proxy") $
338− TyApp (TyCon "Proxy") (TyCon (UnQual api))
339+ TyApp () (TyCon () "Proxy") (TyCon () (UnQual () api))
339 , var "mempty"
340 , var "mempty"
340 ]
341 ]
341 ]
342 ]
342
343
343− rhs = UnGuardedRhs . appFun (var "go") $ map go fs ++ extras ++ [var url]
344+ rhs = UnGuardedRhs () . appFun (var "go") $ map go fs ++ extras ++ [var url]
344 where
345 where
345 go l = case Map.lookup l ps of
346 go l = case Map.lookup l ps of
346 Just p | _pLocation p == Query
347 Just p | _pLocation p == Query
@@ -365,16 +366,15 @@ googleRequestDecl n assoc extras pre api url m pat prec =
365 . nub
366 . nub
366 $ map fst (rights (extractPath (_mPath m))) ++ _mParameterOrder m
367 $ map fst (rights (extractPath (_mPath m))) ++ _mParameterOrder m
367
368
368−jsonDecls :: Global -> Prefix -> Map Local Solved -> [Decl]
369+jsonDecls :: Global -> Prefix -> Map Local Solved -> [Decl ()]
369jsonDecls g p (Map.toList -> rs) = [from', to']
370jsonDecls g p (Map.toList -> rs) = [from', to']
370 where
371 where
371− from' = InstDecl noLoc Nothing [] [] (unqual "FromJSON") [tycon g]
372+ from' = InstDecl () Nothing (instrule "FromJSON" (tycon g)) (Just
372 [ funD "parseJSON" $
373 [ funD "parseJSON" $
373 app (app (var "withObject") (dstr g)) $
374 app (app (var "withObject") (dstr g)) $
374− lamE noLoc [pvar "o"] $
375+ lamE [pvar "o"] $
375 ctorE g (map decode rs)
376 ctorE g (map decode rs)
376− ]
377+ ])
377−
378 decode (l, s)
378 decode (l, s)
379 | _additional s = app (var "parseJSONObject") (var "o")
379 | _additional s = app (var "parseJSONObject") (var "o")
380 | Just x <- def s = defJS l x
380 | Just x <- def s = defJS l x
@@ -384,15 +384,15 @@ jsonDecls g p (Map.toList -> rs) = [from', to']
384
384
385 to' = case rs of
385 to' = case rs of
386 [(k, v)] | _additional v ->
386 [(k, v)] | _additional v ->
387− InstDecl noLoc Nothing [] [] (unqual "ToJSON") [tycon g]
387+ InstDecl () Nothing (instrule "ToJSON" (tycon g)) (Just
388 [ funD "toJSON" $
388 [ funD "toJSON" $
389 infixApp (var "toJSON") "." (var (fname p k))
389 infixApp (var "toJSON") "." (var (fname p k))
390− ]
390+ ])
391
391
392 _ ->
392 _ ->
393− InstDecl noLoc Nothing [] [] (unqual "ToJSON") [tycon g]
393+ InstDecl () Nothing (instrule "ToJSON" (tycon g)) (Just
394 [ wildcardD "toJSON" g omit emptyObj (map encode rs)
394 [ wildcardD "toJSON" g omit emptyObj (map encode rs)
395− ]
395+ ])
396
396
397 omit = app (var "object")
397 omit = app (var "object")
398 . app (var "catMaybes")
398 . app (var "catMaybes")
@@ -410,81 +410,99 @@ jsonDecls g p (Map.toList -> rs) = [from', to']
410
410
411wildcardD :: String
411wildcardD :: String
412 -> Global
412 -> Global
413− -> ([Exp] -> Exp)
413+ -> ([Exp ()] -> Exp ())
414− -> Exp
414+ -> Exp ()
415− -> [Exp]
415+ -> [Exp ()]
416− -> InstDecl
416+ -> InstDecl ()
417wildcardD f n enc x = \case
417wildcardD f n enc x = \case
418 [] -> constD f x
418 [] -> constD f x
419− xs -> InsDecl (FunBind [match prec xs])
419+ xs -> InsDecl () (FunBind () [match prec xs])
420 where
420 where
421 match p es =
421 match p es =
422− Match noLoc (name f) [p] Nothing (UnGuardedRhs (enc es)) noBinds
422+ Match () (name f) [p] (UnGuardedRhs () (enc es)) noBinds
423
423
424− prec = PRec (UnQual (dname' n)) [PFieldWildcard]
424+ prec = PRec () (UnQual () (dname' n)) [PFieldWildcard ()]
425
425
426−defJS :: Local -> Exp -> Exp
426+defJS :: Local -> Exp () -> Exp ()
427−defJS n x = infixApp (infixApp (var "o") ".:?" (fstr n)) ".!=" x
427+defJS n = infixApp (infixApp (var "o") ".:?" (fstr n)) ".!="
428
428
429−reqJS :: Local -> Exp
429+reqJS :: Local -> Exp ()
430reqJS = infixApp (var "o") ".:" . fstr
430reqJS = infixApp (var "o") ".:" . fstr
431
431
432−optJS :: Local -> Exp
432+optJS :: Local -> Exp ()
433optJS = infixApp (var "o") ".:?" . fstr
433optJS = infixApp (var "o") ".:?" . fstr
434
434
435−funD :: String -> Exp -> InstDecl
435+funD :: String -> Exp () -> InstDecl ()
436−funD f = InsDecl . patBind noLoc (pvar (name f))
436+funD f = InsDecl () . patBind (pvar (name f))
437
437
438−constD :: String -> Exp -> InstDecl
438+constD :: String -> Exp () -> InstDecl ()
439−constD f x = InsDecl $
439+constD f x = InsDecl () $
440− sfun noLoc (name f) [] (UnGuardedRhs (app (var "const") x)) noBinds
440+ sfun (name f) [] (UnGuardedRhs () (app (var "const") x)) noBinds
441
441
442−ctorE :: Global -> [Exp] -> Exp
442+ctorE :: Global -> [Exp ()] -> Exp ()
443ctorE n = seqE (var (dname' n)) . map paren
443ctorE n = seqE (var (dname' n)) . map paren
444
444
445−seqE :: Exp -> [Exp] -> Exp
445+seqE :: Exp () -> [Exp ()] -> Exp ()
446seqE l [] = app (var "pure") l
446seqE l [] = app (var "pure") l
447seqE l (r:rs) = infixApp l "<$>" (infixE r "<*>" rs)
447seqE l (r:rs) = infixApp l "<$>" (infixE r "<*>" rs)
448
448
449−objDecl :: Global -> Prefix -> [Derive] -> Map Local Solved -> Decl
449+objDecl :: Global -> Prefix -> [Derive] -> Map Local Solved -> Decl ()
450objDecl n p ds rs =
450objDecl n p ds rs =
451− DataDecl noLoc arity [] (dname n) [] [conDecl (dname' n) p rs] (der ds)
451+ DataDecl () arity Nothing (DHead () (dname n)) [conDecl (dname' n) p rs] [der ds]
452 where
452 where
453− arity | Map.size rs == 1 = NewType
453+ arity | Map.size rs == 1 = NewType ()
454− | otherwise = DataType
454+ | otherwise = DataType ()
455−
455+
456− der = map ((,[]) . unqual . drop 1 . show)
456+ der = Deriving () Nothing . map (unqualrule . drop 1 . show)
457−
457+
458+-- decl =
459+-- DataDecl
460+-- ()
461+-- (DataType ())
462+-- Nothing
463+-- (DHead () (Ident () "AboutGet"))
464+-- [QualConDecl () Nothing Nothing (ConDecl () (Ident () "AboutGet'") [])]
465+-- [ Deriving
466+-- ()
467+-- Nothing
468+-- [ IRule () Nothing Nothing (IHCon () (UnQual () (Ident () "Eq")))
469+-- , IRule () Nothing Nothing (IHCon () (UnQual () (Ident () "Show")))
470+-- , IRule () Nothing Nothing (IHCon () (UnQual () (Ident () "Data")))
471+-- , IRule () Nothing Nothing (IHCon () (UnQual () (Ident () "Typeable")))
472+-- , IRule () Nothing Nothing (IHCon () (UnQual () (Ident () "Generic")))
473+-- ]
474+-- ]
475+
458−conDecl :: Name -> Prefix -> Map Local Solved -> QualConDecl
476+conDecl :: Name () -> Prefix -> Map Local Solved -> QualConDecl ()
459−conDecl n p rs = QualConDecl noLoc [] [] body
477+conDecl n p rs = QualConDecl () Nothing Nothing body
460 where
478 where
461 body = case Map.toList rs of
479 body = case Map.toList rs of
462− [] -> ConDecl n []
480+ [] -> ConDecl () n []
463− [x] -> RecDecl n [field internalType x]
481+ [x] -> RecDecl () n [field internalType x]
464− xs -> RecDecl n (map (field (strict . internalType)) xs)
482+ xs -> RecDecl () n (map (field (strict . internalType)) xs)
465
483
466− field f (l, v) = ([fname p l], f (_type v))
484+ field f (l, v) = FieldDecl () [fname p l] (f (_type v))
467
485
468−ctorSig :: Global -> Map Local Solved -> Decl
486+ctorSig :: Global -> Map Local Solved -> Decl ()
469−ctorSig n rs = TypeSig noLoc [cname n] ts
487+ctorSig n rs = TypeSig () [cname n] ts
470 where
488 where
471− ts = foldr' TyFun (TyCon (UnQual (dname n))) ps
489+ ts = foldr' (TyFun ()) (TyCon () (UnQual () (dname n))) ps
472 ps = parameters (Map.elems rs)
490 ps = parameters (Map.elems rs)
473
491
474−ctorDecl :: Global -> Prefix -> Map Local Solved -> Decl
492+ctorDecl :: Global -> Prefix -> Map Local Solved -> Decl ()
475−ctorDecl n p rs = sfun noLoc c ps (UnGuardedRhs rhs) noBinds
493+ctorDecl n p rs = sfun c ps (UnGuardedRhs () rhs) noBinds
476 where
494 where
477 c = cname n
495 c = cname n
478 d = dname' n
496 d = dname' n
479
497
480 rhs | Map.null rs = var d
498 rhs | Map.null rs = var d
481− | otherwise = RecConstr (UnQual d) $
499+ | otherwise = RecConstr () (UnQual () d) $
482 map (uncurry (fieldUpdate p)) (Map.toList rs)
500 map (uncurry (fieldUpdate p)) (Map.toList rs)
483
501
484 ps = map (pname p) . Map.keys $ Map.filter parameter rs
502 ps = map (pname p) . Map.keys $ Map.filter parameter rs
485
503
486−fieldUpdate :: Prefix -> Local -> Solved -> FieldUpdate
504+fieldUpdate :: Prefix -> Local -> Solved -> FieldUpdate ()
487−fieldUpdate p l s = FieldUpdate (UnQual (fname p l)) rhs
505+fieldUpdate p l s = FieldUpdate () (UnQual () (fname p l)) rhs
488 where
506 where
489 rhs | Just x <- def s, s ^. iRepeated = listE [x]
507 rhs | Just x <- def s, s ^. iRepeated = listE [x]
490 | Just x <- def s = x
508 | Just x <- def s = x
@@ -494,26 +512,26 @@ fieldUpdate p l s = FieldUpdate (UnQual (fname p l)) rhs
494
512
495 v = var (pname p l)
513 v = var (pname p l)
496
514
497−lensSig :: Global -> Prefix -> Local -> Solved -> Decl
515+lensSig :: Global -> Prefix -> Local -> Solved -> Decl ()
498−lensSig n p l s = TypeSig noLoc [lname p l] $
516+lensSig n p l s = TypeSig () [lname p l] $
499− TyApp (TyApp (TyCon "Lens'") (tycon n))
517+ TyApp () (TyApp () (TyCon () "Lens'") (tycon n))
500 (externalType (_type s))
518 (externalType (_type s))
501
519
502−lensDecl :: Prefix -> Local -> Solved -> Decl
520+lensDecl :: Prefix -> Local -> Solved -> Decl ()
503−lensDecl p l s = sfun noLoc (lname p l) [] (UnGuardedRhs rhs) noBinds
521+lensDecl p l s = sfun (lname p l) [] (UnGuardedRhs () rhs) noBinds
504 where
522 where
505 f = fname p l
523 f = fname p l
506 t = _type s
524 t = _type s
507
525
508 rhs = mapping t $
526 rhs = mapping t $
509 app (app (var "lens") (var f))
527 app (app (var "lens") (var f))
510− (paren (lamE noLoc [pvar "s", pvar "a"]
528+ (paren (lamE [pvar "s", pvar "a"]
511− (RecUpdate (var "s") [FieldUpdate (UnQual f) (var "a")])))
529+ (RecUpdate () (var "s") [FieldUpdate () (UnQual () f) (var "a")])))
512
530
513−parameters :: [Solved] -> [Type]
531+parameters :: [Solved] -> [Type ()]
514parameters = map (externalType . _type) . filter parameter
532parameters = map (externalType . _type) . filter parameter
515
533
516−def :: Solved -> Maybe Exp
534+def :: Solved -> Maybe (Exp ())
517def s
535def s
518 | Just x <- s ^. iDefault = Just (go x (_prefix s) (_schema s))
536 | Just x <- s ^. iDefault = Just (go x (_prefix s) (_schema s))
519 | otherwise = Nothing
537 | otherwise = Nothing
@@ -527,88 +545,88 @@ def s
527
545
528 lit = var . name . Text.unpack
546 lit = var . name . Text.unpack
529
547
530−terminalType :: TType -> Type
548+terminalType :: TType -> Type ()
531terminalType = internalType . go
549terminalType = internalType . go
532 where
550 where
533 go (TMaybe x) = go x
551 go (TMaybe x) = go x
534 go (TList x) = go x
552 go (TList x) = go x
535 go x = x
553 go x = x
536
554
537−externalType :: TType -> Type
555+externalType :: TType -> Type ()
538externalType = \case
556externalType = \case
539 TType r -> tycon r
557 TType r -> tycon r
540 TMaybe t@TList {} -> externalType t
558 TMaybe t@TList {} -> externalType t
541− TMaybe t -> TyApp (TyCon "Maybe") (externalType t)
559+ TMaybe t -> TyApp () (TyCon () "Maybe") (externalType t)
542− TList t -> TyList (externalType t)
560+ TList t -> TyList () (externalType t)
543 TLit l -> externalLit l
561 TLit l -> externalLit l
544 TMap k v ->
562 TMap k v ->
545− TyApp (TyApp (TyCon "HashMap") (externalType k)) (externalType (require v))
563+ TyApp () (TyApp () (TyCon () "HashMap") (externalType k)) (externalType (require v))
546
564
547−internalType :: TType -> Type
565+internalType :: TType -> Type ()
548internalType = \case
566internalType = \case
549 TType r -> tycon r
567 TType r -> tycon r
550− TMaybe t -> TyApp (TyCon "Maybe") (internalType t)
568+ TMaybe t -> TyApp () (TyCon () "Maybe") (internalType t)
551− TList t -> TyList (internalType t)
569+ TList t -> TyList () (internalType t)
552 TLit l -> internalLit l
570 TLit l -> internalLit l
553 TMap k v ->
571 TMap k v ->
554− TyApp (TyApp (TyCon "HashMap") (internalType k)) (internalType (require v))
572+ TyApp () (TyApp () (TyCon () "HashMap") (internalType k)) (internalType (require v))
555
573
556−externalLit :: Lit -> Type
574+externalLit :: Lit -> Type ()
557externalLit = \case
575externalLit = \case
558− Text -> TyCon "Text"
576+ Text -> TyCon () "Text"
559− Bool -> TyCon "Bool"
577+ Bool -> TyCon () "Bool"
560− Time -> TyCon "TimeOfDay"
578+ Time -> TyCon () "TimeOfDay"
561− Date -> TyCon "Day"
579+ Date -> TyCon () "Day"
562− DateTime -> TyCon "UTCTime"
580+ DateTime -> TyCon () "UTCTime"
563− Nat -> TyCon "Natural"
581+ Nat -> TyCon () "Natural"
564− Float -> TyCon "Double"
582+ Float -> TyCon () "Double"
565− Double -> TyCon "Double"
583+ Double -> TyCon () "Double"
566− Byte -> TyCon "ByteString"
584+ Byte -> TyCon () "ByteString"
567− UInt32 -> TyCon "Word32"
585+ UInt32 -> TyCon () "Word32"
568− UInt64 -> TyCon "Word64"
586+ UInt64 -> TyCon () "Word64"
569− Int32 -> TyCon "Int32"
587+ Int32 -> TyCon () "Int32"
570− Int64 -> TyCon "Int64"
588+ Int64 -> TyCon () "Int64"
571− Alt t -> TyCon (unqual (Text.unpack t))
589+ Alt t -> TyCon () (unqual (Text.unpack t))
572− RqBody -> TyCon "RequestBody"
590+ RqBody -> TyCon () "RequestBody"
573− RsBody -> TyCon "Stream"
591+ RsBody -> TyCon () "Stream"
574− JSONValue -> TyCon "JSONValue"
592+ JSONValue -> TyCon () "JSONValue"
575− GFieldMask -> TyCon "GFieldMask"
593+ GFieldMask -> TyCon () "GFieldMask"
576− GDuration -> TyCon "Scientific"
594+ GDuration -> TyCon () "Scientific"
577−
595+
578−internalLit :: Lit -> Type
596+internalLit :: Lit -> Type ()
579internalLit = \case
597internalLit = \case
580− Text -> TyCon "Text"
598+ Text -> TyCon () "Text"
581− Bool -> TyCon "Bool"
599+ Bool -> TyCon () "Bool"
582− Time -> TyCon "Time'"
600+ Time -> TyCon () "Time'"
583− Date -> TyCon "Date'"
601+ Date -> TyCon () "Date'"
584− DateTime -> TyCon "DateTime'"
602+ DateTime -> TyCon () "DateTime'"
585− Nat -> TyApp (TyCon "Textual") (TyCon "Nat")
603+ Nat -> TyApp () (TyCon () "Textual") (TyCon () "Nat")
586− Float -> TyApp (TyCon "Textual") (TyCon "Double")
604+ Float -> TyApp () (TyCon () "Textual") (TyCon () "Double")
587− Double -> TyApp (TyCon "Textual") (TyCon "Double")
605+ Double -> TyApp () (TyCon () "Textual") (TyCon () "Double")
588− Byte -> TyCon "Bytes"
606+ Byte -> TyCon () "Bytes"
589− UInt32 -> TyApp (TyCon "Textual") (TyCon "Word32")
607+ UInt32 -> TyApp () (TyCon () "Textual") (TyCon () "Word32")
590− UInt64 -> TyApp (TyCon "Textual") (TyCon "Word64")
608+ UInt64 -> TyApp () (TyCon () "Textual") (TyCon () "Word64")
591− Int32 -> TyApp (TyCon "Textual") (TyCon "Int32")
609+ Int32 -> TyApp () (TyCon () "Textual") (TyCon () "Int32")
592− Int64 -> TyApp (TyCon "Textual") (TyCon "Int64")
610+ Int64 -> TyApp () (TyCon () "Textual") (TyCon () "Int64")
593− Alt t -> TyCon (unqual (Text.unpack t))
611+ Alt t -> TyCon () (unqual (Text.unpack t))
594− RqBody -> TyCon "RequestBody"
612+ RqBody -> TyCon () "RequestBody"
595− RsBody -> TyCon "Stream"
613+ RsBody -> TyCon () "Stream"
596− JSONValue -> TyCon "JSONValue"
614+ JSONValue -> TyCon () "JSONValue"
597− GFieldMask -> TyCon "GFieldMask"
615+ GFieldMask -> TyCon () "GFieldMask"
598− GDuration -> TyCon "GDuration"
616+ GDuration -> TyCon () "GDuration"
599−
617+
600−mapping :: TType -> Exp -> Exp
618+mapping :: TType -> Exp () -> Exp ()
601mapping t e = infixE e "." (go t)
619mapping t e = infixE e "." (go t)
602 where
620 where
603 go = \case
621 go = \case
604− TMaybe x@(TList {}) -> var "_Default" : go x
622+ TMaybe x@TList {} -> var "_Default" : go x
605− TMaybe x -> nest (go x)
623+ TMaybe x -> nest (go x)
606− x -> maybeToList (iso x)
624+ x -> maybeToList (iso x)
607
625
608 nest [] = []
626 nest [] = []
609 nest (x:xs) = [app (var "mapping") (infixE x "." xs)]
627 nest (x:xs) = [app (var "mapping") (infixE x "." xs)]
610
628
611−iso :: TType -> Maybe Exp
629+iso :: TType -> Maybe (Exp ())
612iso = \case
630iso = \case
613 TList {} -> Just (var "_Coerce")
631 TList {} -> Just (var "_Coerce")
614 TMap {} -> Just (var "_Coerce")
632 TMap {} -> Just (var "_Coerce")
@@ -630,27 +648,33 @@ require :: TType -> TType
630require (TMaybe t) = t
648require (TMaybe t) = t
631require t = t
649require t = t
632
650
633−strict :: Type -> Type
651+strict :: Type () -> Type ()
634−strict = TyBang BangedTy . \case
652+strict = TyBang () (BangedTy ()) (NoUnpackPragma ()) . \case
635− t@TyApp{} -> TyParen t
653+ t@TyApp{} -> TyParen () t
636 t -> t
654 t -> t
637
655
638−sing :: Text -> Type
656+sing :: Text -> Type ()
639−sing = TyCon . unqual . Text.unpack . flip mappend "\"" . mappend "\""
657+sing = TyCon () . unqual . Text.unpack . flip mappend "\"" . mappend "\""
640
658
641−tylist :: [Text] -> Type
659+tylist :: [Text] -> Type ()
642−tylist xs = TyCon . UnQual . name . Text.unpack $
660+tylist xs = TyCon () . UnQual () . name . Text.unpack $
643 "'[" <> Text.intercalate ", " xs <> "]"
661 "'[" <> Text.intercalate ", " xs <> "]"
644
662
645−tycon :: Global -> Type
663+tycon :: Global -> Type ()
646−tycon = TyCon . UnQual . dname
664+tycon = TyCon () . UnQual () . dname
665+
666+unqual :: String -> QName ()
667+unqual = UnQual () . name
668+
669+unqualrule :: String -> InstRule ()
670+unqualrule = IRule () Nothing Nothing . IHCon () . unqual
647
671
648−unqual :: String -> QName
672+instrule :: String -> Type () -> InstRule ()
649−unqual = UnQual . name
673+instrule n t = IRule () Nothing Nothing (IHApp () (IHCon () (unqual n)) t)
650
674
651−infixE :: Exp -> QOp -> [Exp] -> Exp
675+infixE :: Exp () -> QOp () -> [Exp ()] -> Exp ()
652infixE l _ [] = l
676infixE l _ [] = l
653infixE l o (r:rs) = infixE (infixApp l o r) o rs
677infixE l o (r:rs) = infixE (infixApp l o r) o rs
654
678
655−str :: Text -> Exp
679+str :: Text -> Exp ()
656str = strE . Text.unpack
680str = strE . Text.unpack
gen/src/Gen/Text.hs−2
@@ -1,5 +1,4 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE TupleSections #-}
3
2
4-- Module : Gen.Text
3-- Module : Gen.Text
5-- Copyright : (c) 2013-2015 Brendan Hay
4-- Copyright : (c) 2013-2015 Brendan Hay
@@ -19,7 +18,6 @@ import Data.Char
19import qualified Data.Foldable as Fold
18import qualified Data.Foldable as Fold
20import qualified Data.HashMap.Strict as Map
19import qualified Data.HashMap.Strict as Map
21import qualified Data.HashSet as Set
20import qualified Data.HashSet as Set
22−import Data.Monoid
23import Data.String
21import Data.String
24import Data.Text (Text)
22import Data.Text (Text)
25import qualified Data.Text as Text
23import qualified Data.Text as Text
gen/src/Gen/Tree.hs−1
@@ -5,7 +5,6 @@
5{-# LANGUAGE MultiParamTypeClasses #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE RecordWildCards #-}
7{-# LANGUAGE RecordWildCards #-}
8−{-# LANGUAGE TupleSections #-}
9{-# LANGUAGE ViewPatterns #-}
8{-# LANGUAGE ViewPatterns #-}
10
9
11-- Module : Gen.Tree
10-- Module : Gen.Tree
gen/src/Gen/Types/Data.hs+15−22
@@ -1,17 +1,10 @@
1−{-# LANGUAGE DataKinds #-}
1+{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE DeriveFoldable #-}
3−{-# LANGUAGE DeriveFunctor #-}
4−{-# LANGUAGE DeriveGeneric #-}
5−{-# LANGUAGE DeriveTraversable #-}
6−{-# LANGUAGE ExtendedDefaultRules #-}
2+{-# LANGUAGE ExtendedDefaultRules #-}
7−{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE FlexibleContexts #-}
8−{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE FlexibleInstances #-}
9−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
10−{-# LANGUAGE KindSignatures #-}
11−{-# LANGUAGE LambdaCase #-}
5+{-# LANGUAGE LambdaCase #-}
12−{-# LANGUAGE OverloadedStrings #-}
6+{-# LANGUAGE OverloadedStrings #-}
13−{-# LANGUAGE RecordWildCards #-}
7+{-# LANGUAGE RecordWildCards #-}
14−{-# LANGUAGE TemplateHaskell #-}
15
8
16{-# OPTIONS_GHC -fno-warn-type-defaults #-}
9{-# OPTIONS_GHC -fno-warn-type-defaults #-}
17
10
@@ -42,12 +35,12 @@ default (Text)
42
35
43type Rendered = LText.Text
36type Rendered = LText.Text
44
37
45−data Syn a = Syn { syntax :: a }
38+newtype Syn a = Syn { syntax :: a }
46
39
47instance Pretty a => ToJSON (Syn a) where
40instance Pretty a => ToJSON (Syn a) where
48 toJSON = toJSON . prettyPrint . syntax
41 toJSON = toJSON . prettyPrint . syntax
49
42
50−data Fun = Fun' Name (Maybe Help) Rendered Rendered
43+data Fun = Fun' (Name ()) (Maybe Help) Rendered Rendered
51
44
52instance ToJSON Fun where
45instance ToJSON Fun where
53 toJSON (Fun' n h s d) = object
46 toJSON (Fun' n h s d) = object
@@ -57,7 +50,7 @@ instance ToJSON Fun where
57 , "decl" .= d
50 , "decl" .= d
58 ]
51 ]
59
52
60−data Branch = Branch Name Text Help
53+data Branch = Branch (Name ()) Text Help
61
54
62instance ToJSON Branch where
55instance ToJSON Branch where
63 toJSON (Branch n v h) = object
56 toJSON (Branch n v h) = object
@@ -67,8 +60,8 @@ instance ToJSON Branch where
67 ]
60 ]
68
61
69data Data
62data Data
70− = Sum Name (Maybe Help) [Branch]
63+ = Sum (Name ()) (Maybe Help) [Branch]
71− | Prod Name (Maybe Help) Rendered Fun [Fun] [Rendered]
64+ | Prod (Name ()) (Maybe Help) Rendered Fun [Fun] [Rendered]
72
65
73instance ToJSON Data where
66instance ToJSON Data where
74 toJSON = \case
67 toJSON = \case
@@ -89,7 +82,7 @@ instance ToJSON Data where
89 , "instances" .= is
82 , "instances" .= is
90 ]
83 ]
91
84
92−dataName :: Data -> Name
85+dataName :: Data -> Name ()
93dataName = \case
86dataName = \case
94 Sum n _ _ -> n
87 Sum n _ _ -> n
95 Prod n _ _ _ _ _ -> n
88 Prod n _ _ _ _ _ -> n
@@ -99,7 +92,7 @@ data Action = Action
99 , _actType :: Global
92 , _actType :: Global
100 , _actNamespace :: NS
93 , _actNamespace :: NS
101 , _actHelp :: Maybe Help
94 , _actHelp :: Maybe Help
102− , _actAliasName :: Name
95+ , _actAliasName :: Name ()
103 , _actAlias :: Rendered
96 , _actAlias :: Rendered
104 , _actData :: Data
97 , _actData :: Data
105 }
98 }
@@ -115,7 +108,7 @@ instance ToJSON Action where
115 ]
108 ]
116
109
117data API = API
110data API = API
118− { _apiAliasName :: Name
111+ { _apiAliasName :: Name ()
119 , _apiAlias :: Rendered
112 , _apiAlias :: Rendered
120 , _apiResources :: [Action]
113 , _apiResources :: [Action]
121 , _apiMethods :: [Action]
114 , _apiMethods :: [Action]
gen/src/Gen/Types/Help.hs+15−13
@@ -15,16 +15,16 @@ module Gen.Types.Help
15 , rawHelpText
15 , rawHelpText
16 ) where
16 ) where
17
17
18−import Data.Aeson
18+import Data.Aeson
19−import Data.Char (isSpace)
19+import Data.Char (isSpace)
20−import Data.String
20+import Data.String
21−import Data.Text (Text)
21+import Data.Text (Text)
22−import qualified Data.Text as T
22+import qualified System.IO.Unsafe as Unsafe
23
23
24−import Text.Pandoc as Pandoc
24+import Text.Pandoc as Pandoc
25−import Text.Pandoc.Pretty
25+import Text.Pandoc.Pretty
26
26
27−import qualified Data.Text as Text
27+import qualified Data.Text as Text
28
28
29data Help
29data Help
30 = Help ![Help]
30 = Help ![Help]
@@ -32,9 +32,8 @@ data Help
32 | Raw !Text
32 | Raw !Text
33 deriving (Eq)
33 deriving (Eq)
34
34
35−instance Monoid Help where
35+instance Semigroup Help where
36− mempty = Help []
36+ (<>) x y =
37− mappend x y =
38 case (x, y) of
37 case (x, y) of
39 (Help a, Help b) -> Help (a <> b)
38 (Help a, Help b) -> Help (a <> b)
40 (Pan a a', Pan b b') -> Pan (a <> b) (a' <> b')
39 (Pan a a', Pan b b') -> Pan (a <> b) (a' <> b')
@@ -43,6 +42,9 @@ instance Monoid Help where
43 (a, Help b) -> Help (a : b)
42 (a, Help b) -> Help (a : b)
44 (a, b) -> Help [a, b]
43 (a, b) -> Help [a, b]
45
44
45+instance Monoid Help where
46+ mempty = Help []
47+
46-- | Empty Show instance to avoid verbose debugging output.
48-- | Empty Show instance to avoid verbose debugging output.
47instance Show Help where
49instance Show Help where
48 show = const mempty
50 show = const mempty
@@ -55,7 +57,7 @@ rawHelpText = Raw
55
57
56instance FromJSON Help where
58instance FromJSON Help where
57 parseJSON = withText "help" $ \t ->
59 parseJSON = withText "help" $ \t ->
58− case Pandoc.readHtml def (T.unpack t) of
60+ case (Unsafe.unsafePerformIO . Pandoc.runIO) (Pandoc.readHtml def t) of
59 Left e -> fail (show e)
61 Left e -> fail (show e)
60 Right x -> pure $! Pan x t
62 Right x -> pure $! Pan x t
61
63
@@ -84,7 +86,7 @@ flatten :: Help -> String
84flatten = \case
86flatten = \case
85 Help xs -> foldMap flatten xs
87 Help xs -> foldMap flatten xs
86 Raw t -> Text.unpack t
88 Raw t -> Text.unpack t
87− Pan d _t -> Pandoc.writeHaddock def d
89+ Pan d _t -> Text.unpack ((Unsafe.unsafePerformIO . Pandoc.runIOorExplode) (Pandoc.writeHaddock def d))
88
90
89wrap :: String -> String -> Text
91wrap :: String -> String -> Text
90wrap sep =
92wrap sep =
gen/src/Gen/Types/Id.hs+16−16
@@ -1,7 +1,6 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4−{-# LANGUAGE LambdaCase #-}
5{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE ScopedTypeVariables #-}
5{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE TupleSections #-}
6{-# LANGUAGE TupleSections #-}
@@ -62,9 +61,7 @@ import qualified Data.CaseInsensitive as CI
62import Data.Foldable (foldl')
61import Data.Foldable (foldl')
63import Data.Function (on)
62import Data.Function (on)
64import Data.Hashable
63import Data.Hashable
65−import Data.List (intersperse)
64+import Data.List (elemIndex, intersperse, nub, sortOn)
66−import Data.List (elemIndex, nub, sortOn)
67−import Data.Semigroup hiding (Sum)
68import Data.String
65import Data.String
69import Data.Text (Text)
66import Data.Text (Text)
70import qualified Data.Text as Text
67import qualified Data.Text as Text
@@ -76,10 +73,10 @@ import GHC.Generics (Generic)
76import Language.Haskell.Exts.Build
73import Language.Haskell.Exts.Build
77import Language.Haskell.Exts.Syntax (Exp, Name (..))
74import Language.Haskell.Exts.Syntax (Exp, Name (..))
78
75
79−aname :: Text -> Name
76+aname :: Text -> Name ()
80aname = name . Text.unpack . (<> "API") . upperHead . Text.replace "." ""
77aname = name . Text.unpack . (<> "API") . upperHead . Text.replace "." ""
81
78
82−mname :: Text -> Suffix -> Global -> (Name, Global, Text)
79+mname :: Text -> Suffix -> Global -> (Name (), Global, Text)
83mname abrv (Suffix suf) (Global g) =
80mname abrv (Suffix suf) (Global g) =
84 ( name . Text.unpack $ mconcat n <> suf -- Action service type alias.
81 ( name . Text.unpack $ mconcat n <> suf -- Action service type alias.
85 , Global n -- Action data type.
82 , Global n -- Action data type.
@@ -94,13 +91,13 @@ mname abrv (Suffix suf) (Global g) =
94 e = Text.replace "." "" abrv
91 e = Text.replace "." "" abrv
95 x:xs = map (upperAcronym . toPascal) g
92 x:xs = map (upperAcronym . toPascal) g
96
93
97−dname' :: Global -> Name
94+dname' :: Global -> Name ()
98dname' g =
95dname' g =
99 case dname g of
96 case dname g of
100− Ident s -> Ident (s <> "'")
97+ Ident () s -> Ident () (s <> "'")
101− Symbol s -> Symbol (s <> "'")
98+ Symbol () s -> Symbol () (s <> "'")
102
99
103−dname :: Global -> Name
100+dname :: Global -> Name ()
104dname = name
101dname = name
105 . Text.unpack
102 . Text.unpack
106 . renameReserved
103 . renameReserved
@@ -108,7 +105,7 @@ dname = name
108 . Text.dropWhile separator
105 . Text.dropWhile separator
109 . global
106 . global
110
107
111−cname :: Global -> Name
108+cname :: Global -> Name ()
112cname = name
109cname = name
113 . Text.unpack
110 . Text.unpack
114 . renameReserved
111 . renameReserved
@@ -117,24 +114,24 @@ cname = name
117 . lowerFirstAcronym
114 . lowerFirstAcronym
118 . global
115 . global
119
116
120−bname :: Prefix -> Text -> Name
117+bname :: Prefix -> Text -> Name ()
121bname (Prefix p) = name
118bname (Prefix p) = name
122 . Text.unpack
119 . Text.unpack
123 . mappend (Text.toUpper p)
120 . mappend (Text.toUpper p)
124 . renameBranch
121 . renameBranch
125
122
126−fname, lname, pname :: Prefix -> Local -> Name
123+fname, lname, pname :: Prefix -> Local -> Name ()
127fname = pre (Text.cons '_' . renameField)
124fname = pre (Text.cons '_' . renameField)
128lname = pre renameField
125lname = pre renameField
129pname = pre (flip Text.snoc '_' . Text.cons 'p' . upperHead . renameField)
126pname = pre (flip Text.snoc '_' . Text.cons 'p' . upperHead . renameField)
130
127
131−dstr :: Global -> Exp
128+dstr :: Global -> Exp ()
132dstr = strE . Text.unpack . toPascal . global
129dstr = strE . Text.unpack . toPascal . global
133
130
134−fstr :: Local -> Exp
131+fstr :: Local -> Exp ()
135fstr = strE . Text.unpack . local
132fstr = strE . Text.unpack . local
136
133
137−pre :: (Text -> Text) -> Prefix -> Local -> Name
134+pre :: (Text -> Text) -> Prefix -> Local -> Name ()
138pre f (Prefix p) = name . Text.unpack . f . mappend p . upperHead . local
135pre f (Prefix p) = name . Text.unpack . f . mappend p . upperHead . local
139
136
140newtype Suffix = Suffix Text
137newtype Suffix = Suffix Text
@@ -143,6 +140,9 @@ newtype Suffix = Suffix Text
143newtype Prefix = Prefix Text
140newtype Prefix = Prefix Text
144 deriving (Show, Monoid)
141 deriving (Show, Monoid)
145
142
143+instance Semigroup Prefix where
144+ Prefix a <> Prefix b = Prefix (a <> b)
145+
146newtype Global = Global { unsafeGlobal :: [Text] }
146newtype Global = Global { unsafeGlobal :: [Text] }
147 deriving (Ord, Show, Generic)
147 deriving (Ord, Show, Generic)
148
148
gen/src/Gen/Types/NS.hs−1
@@ -14,7 +14,6 @@ module Gen.Types.NS
14 ) where
14 ) where
15
15
16import Data.Aeson
16import Data.Aeson
17−import Data.Semigroup
18import Data.String
17import Data.String
19import Data.Text (Text)
18import Data.Text (Text)
20import qualified Data.Text as Text
19import qualified Data.Text as Text
gen/src/Gen/Types/Schema.hs+6−3
@@ -60,6 +60,9 @@ deriveJSON options ''Location
60newtype Ann = Ann { annRequired :: [Local] }
60newtype Ann = Ann { annRequired :: [Local] }
61 deriving (Eq, Show, Monoid)
61 deriving (Eq, Show, Monoid)
62
62
63+instance Semigroup Ann where
64+ a <> b = Ann (annRequired a <> annRequired b)
65+
63deriveJSON options ''Ann
66deriveJSON options ''Ann
64
67
65data Info = Info
68data Info = Info
@@ -422,7 +425,7 @@ data Service a = Service
422 , _sOwnerName :: Text
425 , _sOwnerName :: Text
423 , _sOwnerDomain :: Text
426 , _sOwnerDomain :: Text
424 , _sPackagePath :: Maybe Text
427 , _sPackagePath :: Maybe Text
425− , _sDescription :: (Description a)
428+ , _sDescription :: Description a
426 } deriving (Eq, Show)
429 } deriving (Eq, Show)
427
430
428makeClassy ''Service
431makeClassy ''Service
@@ -445,8 +448,8 @@ serviceName = Text.unpack . (<> "Service") . toCamel . _sCanonicalName
445scopeName :: Service a -> Text -> String
448scopeName :: Service a -> Text -> String
446scopeName s k = Text.unpack . lowerHead . lowerFirstAcronym $
449scopeName s k = Text.unpack . lowerHead . lowerFirstAcronym $
447 case breakParts k of
450 case breakParts k of
448− [] -> _sCanonicalName s <> "AllScope"
451+ [] -> _sCanonicalName s <> "AllScope"
449− xs -> foldMap named xs <> "Scope"
452+ xs -> foldMap named xs <> "Scope"
450 where
453 where
451 breakParts =
454 breakParts =
452 concatMap (Text.split split)
455 concatMap (Text.split split)
gen/stack.yaml+9−5
@@ -1,11 +1,15 @@
1−resolver: lts-8.18
1+resolver: lts-13.7
2
2
3flags: {}
3flags: {}
4
4
5extra-deps:
5extra-deps:
6− - text-regex-replace-0.1.1.1
6+ - text-regex-replace-0.1.1.3
7− - haskell-src-exts-1.17.1
7+ - ede-0.2.9
8+ - unexceptionalio-0.3.0
8− - hindent-4.6.4
9+ - github: chrisdone/hindent
10+ size: 51114
11+ commit: ad0c2a9f8755d37f09b356ab7e45a4e49bcda0b3
12+ sha256: 19954fc7dff3d008d9c7688d1c571999c1869f86e5c115aef8b28c2ae622972f
9
13
10packages:
14packages:
11− - '.'
15+ - "."
stack-8.6.3.yaml+1−1
@@ -1,4 +1,4 @@
1−resolver: lts-13.2
1+resolver: lts-13.7
2
2
3local-bin-path: bin
3local-bin-path: bin
4
4