on develop help sign in
Renaming
commit4e0ee3cc6b1dedc0f0c4a6197cc16e2b9e39134a authorBrendan Hay <brendan.g.hay@gmail.com> dateSat 26 Sep 2015, 16:16 (11 years ago) parent01a154d
3 files changed+32−13
gen/src/Gen/Syntax.hs+22−9 gen/src/Gen/Text.hs+4−4 gen/template/toc.ede+6
gen/src/Gen/Syntax.hs+22−9
@@ -15,7 +15,7 @@ module Gen.Syntax where
1515
1616import Control.Lens hiding (iso, mapping, op, pre,
1717 strict)
18−import Data.Foldable (foldr')
18+import Data.Foldable (foldl', foldr')
1919import Data.Hashable
2020import qualified Data.HashMap.Strict as Map
2121import Data.Maybe
@@ -44,28 +44,41 @@ apiAlias n ls = TypeDecl noLoc n [] alias
4444verbDecl :: Service s r -> Local -> Local -> Method -> Decl
4545verbDecl s p l m = TypeDecl noLoc (vname p l) [] alias
4646 where
47− alias = case path ++ prms of
47+ alias = case path ++ qry of
4848 [] -> unit_tycon
49− x:xs -> foldr' (\l r -> TyInfix l (UnQual (sym ":>")) r) x xs
49+ x:xs -> foldl' (\l r -> TyInfix l (UnQual (sym ":>")) r) x xs
50+
51+-- Need to deal with interpolation?
5052
5153 path :: [Type]
52− path = map sing
54+ path = map match
5355 . filter (not . Text.null)
5456 $ Text.split (== '/') (_svcServicePath s)
5557 <> Text.split (== '/') (_mPath m)
58+ where
59+ match x
60+ | Just (c, t) <- Text.uncons x
61+ , c == '{'
62+ , Just k <- Map.lookup (Local (Text.init t)) params
63+ , _prmLocation k == Path
64+ = TyApp (TyApp (tycon "Capture")
65+ (sing (Text.init t)))
66+ (literal (_prmLiteral k))
67+ | otherwise = sing x
5668
5769 -- FIXME: order by _mParameterOrder
58− prms :: [Type]
59− prms = map f (Map.toList (_svcParameters s))
60− ++ map f (Map.toList (_mParameters m))
70+ qry :: [Type]
71+ qry = mapMaybe f (Map.toList params)
6172 where
6273 f (k, p) =
6374 -- FIXME: types, many/repeated
6475 let t = literal (_prmLiteral p)
6576 n = sing (local k)
6677 in case _prmLocation p of
67− Path -> TyApp (TyApp (tycon "Capture") n) t
68− Query -> TyApp (TyApp (tycon "QueryParam") n) t
78+ Query -> Just $ TyApp (TyApp (tycon "QueryParam") n) t
79+ Path -> Nothing
80+
81+ params = _svcParameters s <> _mParameters m
6982
7083 verb :: Type
7184 verb = TyApp (TyApp meth typ) res
gen/src/Gen/Text.hs+4−4
@@ -52,7 +52,7 @@ renameTitle =
5252
5353renameAbbrev :: Text -> Text
5454renameAbbrev = mconcat
55− . Text.split isSpace
55+ . Text.split separator
5656 . stripPrefix "Google "
5757 . stripSuffix " API"
5858
@@ -66,7 +66,7 @@ renameBranch = renameReserved . go
6666 | otherwise = upperAcronym . cat $ split x
6767
6868 cat = Fold.foldMap (Text.intercalate "_" . map component . Text.split dot)
69− split = Text.split seperator
69+ split = Text.split separator
7070
7171 dot x = x == '.'
7272
@@ -76,8 +76,8 @@ renameBranch = renameReserved . go
7676 | Text.all isUpper x = toPascal (Text.toLower x)
7777 | otherwise = toPascal x
7878
79−seperator :: Char -> Bool
80−seperator x =
79+separator :: Char -> Bool
80+separator x =
8181 x == '\\'
8282 || x == '/'
8383 || x == '+'
gen/template/toc.ede+6
@@ -1,3 +1,9 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE TypeOperators #-}
3+
4+{-# OPTIONS_GHC -fno-warn-unused-imports #-}
5+{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}
6+
17{% include "_include/license.ede" %}
28--
39-- {{ description }}