@@ -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