Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow newer versions of template-haskell #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Routes/Routes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ module Routes.Routes

-- * Template Haskell methods
, mkRoute
, mkRouteData
, mkRouteDispatch
, mkRouteSub
, mkRouteSubDispatch

-- * Dispatch
, routeDispatch
Expand Down
18 changes: 17 additions & 1 deletion src/Routes/TH/Dispatch.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE RecordWildCards, TemplateHaskell, ViewPatterns #-}
{-# LANGUAGE RecordWildCards, TemplateHaskell, ViewPatterns, CPP #-}
module Routes.TH.Dispatch
( MkDispatchSettings (..)
, mkDispatchClause
Expand Down Expand Up @@ -73,7 +73,11 @@ mkDispatchClause MkDispatchSettings {..} resources = do
handlePiece (Static str) = return (LitP $ StringL str, Nothing)
handlePiece (Dynamic _) = do
x <- newName "dyn"
#if MIN_VERSION_template_haskell(2,18,0)
let pat = ViewP (VarE 'fromPathPiece) (ConP 'Just [] [VarP x])
#else
let pat = ViewP (VarE 'fromPathPiece) (ConP 'Just [VarP x])
#endif
return (pat, Just $ VarE x)

handlePieces :: [Piece a] -> Q ([Pat], [Exp])
Expand All @@ -86,7 +90,11 @@ mkDispatchClause MkDispatchSettings {..} resources = do
mkPathPat final =
foldr addPat final
where
#if MIN_VERSION_template_haskell(2,18,0)
addPat x y = ConP '(:) [] [x, y]
#else
addPat x y = ConP '(:) [x, y]
#endif

go :: SDC -> ResourceTree a -> Q Clause
go sdc (ResourceParent name _check pieces children) = do
Expand Down Expand Up @@ -124,11 +132,19 @@ mkDispatchClause MkDispatchSettings {..} resources = do
Methods multi methods -> do
(finalPat, mfinalE) <-
case multi of
#if MIN_VERSION_template_haskell(2,18,0)
Nothing -> return (ConP '[] [] [], Nothing)
#else
Nothing -> return (ConP '[] [], Nothing)
#endif
Just _ -> do
multiName <- newName "multi"
let pat = ViewP (VarE 'fromPathMultiPiece)
#if MIN_VERSION_template_haskell(2,18,0)
(ConP 'Just [] [VarP multiName])
#else
(ConP 'Just [VarP multiName])
#endif
return (pat, Just $ VarE multiName)

let dynsMulti =
Expand Down
8 changes: 8 additions & 0 deletions src/Routes/TH/RenderRoute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ mkRenderRouteClauses =
let cnt = length $ filter isDynamic pieces
dyns <- replicateM cnt $ newName "dyn"
child <- newName "child"
#if MIN_VERSION_template_haskell(2,18,0)
let pat = ConP (mkName name) [] $ map VarP $ dyns ++ [child]
#else
let pat = ConP (mkName name) $ map VarP $ dyns ++ [child]
#endif

pack' <- [|pack|]
tsp <- [|toPathPiece|]
Expand Down Expand Up @@ -100,7 +104,11 @@ mkRenderRouteClauses =
case resourceDispatch res of
Subsite{} -> return <$> newName "sub"
_ -> return []
#if MIN_VERSION_template_haskell(2,18,0)
let pat = ConP (mkName $ resourceName res) [] $ map VarP $ dyns ++ sub
#else
let pat = ConP (mkName $ resourceName res) $ map VarP $ dyns ++ sub
#endif

pack' <- [|pack|]
tsp <- [|toPathPiece|]
Expand Down
5 changes: 5 additions & 0 deletions src/Routes/TH/RouteAttrs.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE CPP #-}
module Routes.TH.RouteAttrs
( mkRouteAttrsInstance
) where
Expand All @@ -26,7 +27,11 @@ goTree front (ResourceParent name _check pieces trees) =
toIgnore = length $ filter isDynamic pieces
isDynamic Dynamic{} = True
isDynamic Static{} = False
#if MIN_VERSION_template_haskell(2,18,0)
front' = front . ConP (mkName name) [] . ignored
#else
front' = front . ConP (mkName name) . ignored
#endif

goRes :: (Pat -> Pat) -> Resource a -> Q Clause
goRes front Resource {..} =
Expand Down
3 changes: 3 additions & 0 deletions src/Wai/Routes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ module Wai.Routes
, parseRoutesFileNoCheck -- | Same as parseRoutesFile, but performs no overlap checking.

, mkRoute
, mkRouteData
, mkRouteDispatch
, mkRouteSub
, mkRouteSubDispatch

-- * Dispatch
, routeDispatch
Expand Down
9 changes: 2 additions & 7 deletions wai-routes.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name : wai-routes
version : 0.10.4
version : 0.10.5
cabal-version : 1.18
build-type : Simple
license : MIT
Expand All @@ -14,14 +14,9 @@ author : Anupam Jain
data-dir : ""
extra-source-files : README.md

source-repository head
type : git
location : http://github.com/ajnsit/wai-routes

source-repository this
type : git
location : http://github.com/ajnsit/wai-routes/tree/v0.10.4
tag : v0.10.4
location : http://github.com/ajnsit/wai-routes

library
build-depends : base
Expand Down