From 6d7482319e70aa7a11dbdea4c73cd2aa0d507a92 Mon Sep 17 00:00:00 2001 From: Tom Lokhorst Date: Sat, 9 Jul 2011 00:09:12 +0200 Subject: [PATCH 1/6] Don't parse slashes in strings --- Web/Zwaluw.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Web/Zwaluw.hs b/Web/Zwaluw.hs index 6276983..85817c8 100644 --- a/Web/Zwaluw.hs +++ b/Web/Zwaluw.hs @@ -108,9 +108,14 @@ int = readshow integer :: Router r (Integer :- r) integer = readshow --- | Routes any string. +-- | Routes any string, upto a slash ("/"). string :: Router r (String :- r) -string = val (\s -> [(s, "")]) (return . (++)) +string = val parse' serialize + where + parse' s = [( takeWhile (/= '/') s + , dropWhile (/= '/') s + )] + serialize = return . (++) -- | Routes one character satisfying the given predicate. satisfy :: (Char -> Bool) -> Router r (Char :- r) @@ -175,4 +180,4 @@ rMaybe r = rJust . r <> rNothing $(deriveRouters ''Bool) rTrue :: Router r (Bool :- r) -rFalse :: Router r (Bool :- r) \ No newline at end of file +rFalse :: Router r (Bool :- r) From f322bf9d0013b4d6730b3e73bad0ddeb4e07b0da Mon Sep 17 00:00:00 2001 From: Tom Lokhorst Date: Sat, 9 Jul 2011 00:16:42 +0200 Subject: [PATCH 2/6] Added a 'text' Router for Data.Text values. --- Web/Zwaluw.hs | 12 +++++++++++- Zwaluw.cabal | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Web/Zwaluw.hs b/Web/Zwaluw.hs index 85817c8..cfeae42 100644 --- a/Web/Zwaluw.hs +++ b/Web/Zwaluw.hs @@ -19,7 +19,7 @@ module Web.Zwaluw ( , manyl, somel, chainl, chainl1 -- * Built-in routers - , int, integer, string, char, digit, hexDigit + , int, integer, string, text, char, digit, hexDigit , (/), part , rNil, rCons, rList, rListSep @@ -34,6 +34,7 @@ import Control.Monad (guard) import Control.Category import Data.Monoid import Data.Char (isDigit, isHexDigit, intToDigit, digitToInt) +import qualified Data.Text as T import Web.Zwaluw.Core import Web.Zwaluw.TH @@ -117,6 +118,15 @@ string = val parse' serialize )] serialize = return . (++) +-- | Routes any text, upto a slash ("/"). +text :: Router r (T.Text :- r) +text = val parse' serialize + where + parse' s = [( T.pack . takeWhile (/= '/') $ s + , dropWhile (/= '/') s + )] + serialize = return . (++) . T.unpack + -- | Routes one character satisfying the given predicate. satisfy :: (Char -> Bool) -> Router r (Char :- r) satisfy p = val diff --git a/Zwaluw.cabal b/Zwaluw.cabal index d3a3047..d066c39 100644 --- a/Zwaluw.cabal +++ b/Zwaluw.cabal @@ -24,4 +24,4 @@ Library Web.Zwaluw.Core, Web.Zwaluw.TH, Web.Zwaluw.Regular - Build-Depends: base >= 4 && < 5, template-haskell >= 2.4 && < 2.6, regular >= 0.3 && < 0.4 + Build-Depends: base >= 4 && < 5, template-haskell >= 2.4 && < 2.6, regular >= 0.3 && < 0.4, text >= 0.11 && < 0.12 From eacc4d46cab794cda88b66b6775f54d598154132 Mon Sep 17 00:00:00 2001 From: Tom Lokhorst Date: Sat, 9 Jul 2011 20:31:17 +0200 Subject: [PATCH 3/6] Don't match empty strings or texts, as this is rarely expected behaviour --- Web/Zwaluw.hs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Web/Zwaluw.hs b/Web/Zwaluw.hs index cfeae42..b3b3fe7 100644 --- a/Web/Zwaluw.hs +++ b/Web/Zwaluw.hs @@ -109,22 +109,24 @@ int = readshow integer :: Router r (Integer :- r) integer = readshow --- | Routes any string, upto a slash ("/"). +-- | Routes any non-empty string, upto a slash ("/"). string :: Router r (String :- r) string = val parse' serialize where - parse' s = [( takeWhile (/= '/') s - , dropWhile (/= '/') s - )] + parse' "" = [] + parse' s = [( takeWhile (/= '/') s + , dropWhile (/= '/') s + )] serialize = return . (++) --- | Routes any text, upto a slash ("/"). +-- | Routes any non-empty text, upto a slash ("/"). text :: Router r (T.Text :- r) text = val parse' serialize where - parse' s = [( T.pack . takeWhile (/= '/') $ s - , dropWhile (/= '/') s - )] + parse' "" = [] + parse' s = [( T.pack . takeWhile (/= '/') $ s + , dropWhile (/= '/') s + )] serialize = return . (++) . T.unpack -- | Routes one character satisfying the given predicate. From 0cc9e65cba5ca4b6af05c1eb53ca27819a91de78 Mon Sep 17 00:00:00 2001 From: Tom Lokhorst Date: Sun, 10 Jul 2011 21:55:31 +0200 Subject: [PATCH 4/6] Added FilePath newtype to represent texts with slashes in them --- Web/Zwaluw.hs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Web/Zwaluw.hs b/Web/Zwaluw.hs index b3b3fe7..8d6722e 100644 --- a/Web/Zwaluw.hs +++ b/Web/Zwaluw.hs @@ -27,9 +27,12 @@ module Web.Zwaluw ( , rLeft, rRight, rEither , rNothing, rJust, rMaybe , rTrue, rFalse + + -- * FilePath data type and router + , FilePath, filePath ) where -import Prelude hiding ((.), id, (/)) +import Prelude hiding ((.), id, (/), FilePath) import Control.Monad (guard) import Control.Category import Data.Monoid @@ -193,3 +196,17 @@ rMaybe r = rJust . r <> rNothing $(deriveRouters ''Bool) rTrue :: Router r (Bool :- r) rFalse :: Router r (Bool :- r) + +-- | Represents a file path, including slashes +newtype FilePath = FilePath { unFilePath :: T.Text } + +instance Show FilePath where + showsPrec p (FilePath t) r = showsPrec p t r + +filePath :: Router r (FilePath :- r) +filePath = val parse' serialize + where + parse' "" = [] + parse' s = [(FilePath . T.pack $ s, "")] + serialize = return . (++) . T.unpack . unFilePath + From 0c3d23efad5defb8b6386c80ab21e7b73ad574ab Mon Sep 17 00:00:00 2001 From: Tom Lokhorst Date: Sun, 10 Jul 2011 21:57:35 +0200 Subject: [PATCH 5/6] Bumped version number, so as not to have conflict --- Zwaluw.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zwaluw.cabal b/Zwaluw.cabal index d066c39..62cf644 100644 --- a/Zwaluw.cabal +++ b/Zwaluw.cabal @@ -1,5 +1,5 @@ Name: Zwaluw -Version: 0.2 +Version: 0.2.1 Synopsis: Combinators for bidirectional URL routing Description: Combinators for bidirectional URL routing From 5dc77f9a8d54dd0acebf81b46c92415e7b253396 Mon Sep 17 00:00:00 2001 From: Tom Lokhorst Date: Sun, 8 Jun 2014 10:54:49 +0200 Subject: [PATCH 6/6] Added kind signature, removed mappend alias. Zwaluw now builds with GHC 7.6 --- Web/Zwaluw.hs | 9 +-------- Web/Zwaluw/Regular.hs | 2 +- Zwaluw.cabal | 7 +++++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Web/Zwaluw.hs b/Web/Zwaluw.hs index 8d6722e..8bf95d9 100644 --- a/Web/Zwaluw.hs +++ b/Web/Zwaluw.hs @@ -5,7 +5,7 @@ module Web.Zwaluw ( -- * Types - Router, (:-)(..), (<>), (.~) + Router, (:-)(..), (.~) -- * Running routers , parse, unparse @@ -43,13 +43,6 @@ import Web.Zwaluw.Core import Web.Zwaluw.TH -infixr 8 <> - --- | Infix operator for 'mappend'. -(<>) :: Monoid m => m -> m -> m -(<>) = mappend - - -- | Make a router optional. opt :: Router r r -> Router r r opt = (id <>) diff --git a/Web/Zwaluw/Regular.hs b/Web/Zwaluw/Regular.hs index a6bb5e4..e3d0247 100644 --- a/Web/Zwaluw/Regular.hs +++ b/Web/Zwaluw/Regular.hs @@ -29,7 +29,7 @@ type Routers r = RouterList (PF r) r mkRouters :: (MkRouters (PF r), Regular r) => Routers r mkRouters = mkRouters' to (Just . from) -data family RouterList f r +data family RouterList (f :: * -> *) r class MkRouters (f :: * -> *) where mkRouters' :: (f r -> r) -> (r -> Maybe (f r)) -> RouterList f r diff --git a/Zwaluw.cabal b/Zwaluw.cabal index 62cf644..9b7a898 100644 --- a/Zwaluw.cabal +++ b/Zwaluw.cabal @@ -1,5 +1,5 @@ Name: Zwaluw -Version: 0.2.1 +Version: 0.2.2 Synopsis: Combinators for bidirectional URL routing Description: Combinators for bidirectional URL routing @@ -24,4 +24,7 @@ Library Web.Zwaluw.Core, Web.Zwaluw.TH, Web.Zwaluw.Regular - Build-Depends: base >= 4 && < 5, template-haskell >= 2.4 && < 2.6, regular >= 0.3 && < 0.4, text >= 0.11 && < 0.12 + Build-Depends: base >= 4.5 && < 5, + template-haskell >= 2.4 && < 2.9, + regular >= 0.3 && < 0.4, + text >= 0.11 && < 0.12