{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
module Text.URI.QQ
( uri,
scheme,
host,
username,
password,
pathPiece,
queryKey,
queryValue,
fragment,
)
where
import Control.Exception (Exception (..), SomeException)
import Data.Text (Text)
import qualified Data.Text as T
import Language.Haskell.TH.Lib (appE, viewP)
import Language.Haskell.TH.Quote (QuasiQuoter (..))
import Language.Haskell.TH.Syntax (Lift (..))
import Text.URI.Parser.Text
import Text.URI.Types
uri :: QuasiQuoter
uri :: QuasiQuoter
uri = forall a.
(Eq a, Lift a) =>
(Text -> Either SomeException a) -> QuasiQuoter
liftToQQ forall (m :: * -> *). MonadThrow m => Text -> m URI
mkURI
scheme :: QuasiQuoter
scheme :: QuasiQuoter
scheme = forall a.
(Eq a, Lift a) =>
(Text -> Either SomeException a) -> QuasiQuoter
liftToQQ forall (m :: * -> *). MonadThrow m => Text -> m (RText 'Scheme)
mkScheme
host :: QuasiQuoter
host :: QuasiQuoter
host = forall a.
(Eq a, Lift a) =>
(Text -> Either SomeException a) -> QuasiQuoter
liftToQQ forall (m :: * -> *). MonadThrow m => Text -> m (RText 'Host)
mkHost
username :: QuasiQuoter
username :: QuasiQuoter
username = forall a.
(Eq a, Lift a) =>
(Text -> Either SomeException a) -> QuasiQuoter
liftToQQ forall (m :: * -> *). MonadThrow m => Text -> m (RText 'Username)
mkUsername
password :: QuasiQuoter
password :: QuasiQuoter
password = forall a.
(Eq a, Lift a) =>
(Text -> Either SomeException a) -> QuasiQuoter
liftToQQ forall (m :: * -> *). MonadThrow m => Text -> m (RText 'Password)
mkPassword
pathPiece :: QuasiQuoter
pathPiece :: QuasiQuoter
pathPiece = forall a.
(Eq a, Lift a) =>
(Text -> Either SomeException a) -> QuasiQuoter
liftToQQ forall (m :: * -> *). MonadThrow m => Text -> m (RText 'PathPiece)
mkPathPiece
queryKey :: QuasiQuoter
queryKey :: QuasiQuoter
queryKey = forall a.
(Eq a, Lift a) =>
(Text -> Either SomeException a) -> QuasiQuoter
liftToQQ forall (m :: * -> *). MonadThrow m => Text -> m (RText 'QueryKey)
mkQueryKey
queryValue :: QuasiQuoter
queryValue :: QuasiQuoter
queryValue = forall a.
(Eq a, Lift a) =>
(Text -> Either SomeException a) -> QuasiQuoter
liftToQQ forall (m :: * -> *). MonadThrow m => Text -> m (RText 'QueryValue)
mkQueryValue
fragment :: QuasiQuoter
fragment :: QuasiQuoter
fragment = forall a.
(Eq a, Lift a) =>
(Text -> Either SomeException a) -> QuasiQuoter
liftToQQ forall (m :: * -> *). MonadThrow m => Text -> m (RText 'Fragment)
mkFragment
liftToQQ :: (Eq a, Lift a) => (Text -> Either SomeException a) -> QuasiQuoter
liftToQQ :: forall a.
(Eq a, Lift a) =>
(Text -> Either SomeException a) -> QuasiQuoter
liftToQQ Text -> Either SomeException a
f =
QuasiQuoter
{ quoteExp :: String -> Q Exp
quoteExp = \String
str ->
case Text -> Either SomeException a
f (String -> Text
T.pack String
str) of
Left SomeException
err -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail (forall e. Exception e => e -> String
displayException SomeException
err)
Right a
x -> forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
lift a
x,
quotePat :: String -> Q Pat
quotePat = \String
str ->
case Text -> Either SomeException a
f (String -> Text
T.pack String
str) of
Left SomeException
err -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail (forall e. Exception e => e -> String
displayException SomeException
err)
Right a
x -> forall (m :: * -> *). Quote m => m Exp -> m Exp -> m Exp
appE [|(==)|] (forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
lift a
x) forall (m :: * -> *). Quote m => m Exp -> m Pat -> m Pat
`viewP` [p|True|],
quoteType :: String -> Q Type
quoteType = forall a. HasCallStack => String -> a
error String
"This usage is not supported",
quoteDec :: String -> Q [Dec]
quoteDec = forall a. HasCallStack => String -> a
error String
"This usage is not supported"
}