@@ -15,7 +15,7 @@ module Gen.Syntax where
16import Control.Lens hiding (iso, mapping, op, pre,
16import Control.Lens hiding (iso, mapping, op, pre,
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
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
51+-- Need to deal with interpolation?
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)
60+ | Just (c, t) <- Text.uncons x
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))
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))
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
81+ params = _svcParameters s <> _mParameters m
70 verb :: Type
83 verb :: Type
71 verb = TyApp (TyApp meth typ) res
84 verb = TyApp (TyApp meth typ) res