@@ -14,7 +14,7 @@ module Gen.Syntax where
15import Control.Lens hiding (iso, mapping, op, pre,
15import Control.Lens hiding (iso, mapping, op, pre,
17−import Data.Foldable (foldl', foldr')
17+import Data.Foldable (find, foldl', foldr')
18import Data.Hashable
18import Data.Hashable
19import qualified Data.HashMap.Strict as Map
19import qualified Data.HashMap.Strict as Map
20import Data.Maybe
20import Data.Maybe
@@ -46,34 +46,35 @@ verbAlias s n m = TypeDecl noLoc n [] alias
46 alias = foldr' (\l r -> TyInfix l (UnQual (sym ":>")) r) verb (path ++ qry)
46 alias = foldr' (\l r -> TyInfix l (UnQual (sym ":>")) r) verb (path ++ qry)
48 path :: [Type]
48 path :: [Type]
49− path = [] -- map match
49+ path = map match
50− -- . filter (not . Text.null)
50+ . filter (not . Text.null)
51− -- $ Text.split (== '/') (_svcServicePath s)
51+ $ Text.split (== '/') (_svcServicePath s)
52− -- <> Text.split (== '/') (_mPath m)
52+ <> Text.split (== '/') (_mPath m)
54+ -- FIXME: should error if '{' '}' is found and cannot find the ref.
54− -- match x
55+ match x
55− -- | Just (c, t) <- Text.uncons x
56+ | Just (c, t) <- Text.uncons x
56− -- , c == '{'
57+ , c == '{'
57− -- , Just k <- Map.lookup (Local (Text.init t)) params
58+ , Just k <- Map.lookup (Local (Text.init t)) params
58− -- , _prmLocation k == Path
59+ , _prmLocation k == Path
59− -- = TyApp (TyApp (tycon "Capture")
60+ = TyApp (TyApp (tycon "Capture")
60− -- (sing (Text.init t)))
61+ (sing (Text.init t)))
61− -- (literal (_prmLiteral k))
62+ (external (_type (_prmSchema k)))
62− -- | otherwise = sing x
63+ | otherwise = sing x
64 -- FIXME: order by _mParameterOrder
65 -- FIXME: order by _mParameterOrder
65 qry :: [Type]
66 qry :: [Type]
66− qry = [] -- mapMaybe f (Map.toList params)
67+ qry = mapMaybe f (Map.toList params)
68− -- f (k, p) =
69+ f (k, x) =
69− -- -- FIXME: types, many/repeated
70+ -- FIXME: types, many/repeated
70− -- let t = literal (_prmLiteral p)
71+ let t = external (_type (_prmSchema x))
71− -- n = sing (local k)
72+ n = sing (local k)
72− -- in case _prmLocation p of
73+ in case _prmLocation x of
73− -- Query -> Just $ TyApp (TyApp (tycon "QueryParam") n) t
74+ Query -> Just $ TyApp (TyApp (tycon "QueryParam") n) t
74− -- Path -> Nothing
75+ Path -> Nothing
76−-- params = _svcParameters s <> _mParameters m
77+ params = _mParameters m
78 verb :: Type
79 verb :: Type
79 verb = TyApp (TyApp meth typ) res
80 verb = TyApp (TyApp meth typ) res