on develop help sign in
Renaming
4e0ee3cBrendan Hay
gen/src/Gen/Syntax.hs+22−9
@@ -15,7 +15,7 @@ module Gen.Syntax where
15
15
16import Control.Lens hiding (iso, mapping, op, pre,
16import Control.Lens hiding (iso, mapping, op, pre,
17 strict)
17 strict)
18−import Data.Foldable (foldr')
18+import Data.Foldable (foldl', foldr')
19import Data.Hashable
19import Data.Hashable
20import qualified Data.HashMap.Strict as Map
20import qualified Data.HashMap.Strict as Map
21import Data.Maybe
21import Data.Maybe
@@ -44,28 +44,41 @@ apiAlias n ls = TypeDecl noLoc n [] alias
44verbDecl :: Service s r -> Local -> Local -> Method -> Decl
44verbDecl :: Service s r -> Local -> Local -> Method -> Decl
45verbDecl s p l m = TypeDecl noLoc (vname p l) [] alias
45verbDecl s p l m = TypeDecl noLoc (vname p l) [] alias
46 where
46 where
47− alias = case path ++ prms of
47+ alias = case path ++ qry of
48 [] -> unit_tycon
48 [] -> 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?
50
52
51 path :: [Type]
53 path :: [Type]
52− path = map sing
54+ path = map match
53 . filter (not . Text.null)
55 . filter (not . Text.null)
54 $ Text.split (== '/') (_svcServicePath s)
56 $ Text.split (== '/') (_svcServicePath s)
55 <> Text.split (== '/') (_mPath m)
57 <> 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
56
68
57 -- FIXME: order by _mParameterOrder
69 -- FIXME: order by _mParameterOrder
58− prms :: [Type]
70+ qry :: [Type]
59− prms = map f (Map.toList (_svcParameters s))
71+ qry = mapMaybe f (Map.toList params)
60− ++ map f (Map.toList (_mParameters m))
61 where
72 where
62 f (k, p) =
73 f (k, p) =
63 -- FIXME: types, many/repeated
74 -- FIXME: types, many/repeated
64 let t = literal (_prmLiteral p)
75 let t = literal (_prmLiteral p)
65 n = sing (local k)
76 n = sing (local k)
66 in case _prmLocation p of
77 in case _prmLocation p of
67− Path -> TyApp (TyApp (tycon "Capture") n) t
78+ Query -> Just $ TyApp (TyApp (tycon "QueryParam") n) t
68− Query -> TyApp (TyApp (tycon "QueryParam") n) t
79+ Path -> Nothing
80+
81+ params = _svcParameters s <> _mParameters m
69
82
70 verb :: Type
83 verb :: Type
71 verb = TyApp (TyApp meth typ) res
84 verb = TyApp (TyApp meth typ) res
gen/src/Gen/Text.hs+4−4
@@ -52,7 +52,7 @@ renameTitle =
52
52
53renameAbbrev :: Text -> Text
53renameAbbrev :: Text -> Text
54renameAbbrev = mconcat
54renameAbbrev = mconcat
55− . Text.split isSpace
55+ . Text.split separator
56 . stripPrefix "Google "
56 . stripPrefix "Google "
57 . stripSuffix " API"
57 . stripSuffix " API"
58
58
@@ -66,7 +66,7 @@ renameBranch = renameReserved . go
66 | otherwise = upperAcronym . cat $ split x
66 | otherwise = upperAcronym . cat $ split x
67
67
68 cat = Fold.foldMap (Text.intercalate "_" . map component . Text.split dot)
68 cat = Fold.foldMap (Text.intercalate "_" . map component . Text.split dot)
69− split = Text.split seperator
69+ split = Text.split separator
70
70
71 dot x = x == '.'
71 dot x = x == '.'
72
72
@@ -76,8 +76,8 @@ renameBranch = renameReserved . go
76 | Text.all isUpper x = toPascal (Text.toLower x)
76 | Text.all isUpper x = toPascal (Text.toLower x)
77 | otherwise = toPascal x
77 | otherwise = toPascal x
78
78
79−seperator :: Char -> Bool
79+separator :: Char -> Bool
80−seperator x =
80+separator x =
81 x == '\\'
81 x == '\\'
82 || x == '/'
82 || x == '/'
83 || x == '+'
83 || 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+
1{% include "_include/license.ede" %}
7{% include "_include/license.ede" %}
2--
8--
3-- {{ description }}
9-- {{ description }}