packages feed

hpath 0.10.0 → 0.10.1

raw patch · 4 files changed

+80/−2 lines, 4 filesdep +template-haskelldep +utf8-stringPVP ok

version bump matches the API change (PVP)

Dependencies added: template-haskell, utf8-string

API changes (from Hackage documentation)

+ HPath: abs :: QuasiQuoter
+ HPath: fn :: QuasiQuoter
+ HPath: instance Language.Haskell.TH.Syntax.Lift (HPath.Internal.Path a)
+ HPath: rel :: QuasiQuoter

Files

CHANGELOG view
@@ -1,3 +1,7 @@+0.10.1+	* Add quasi quoters for hpath+0.10.0+	* split packages, this one now just contains the type-safe Path wrappers 0.9.2 	* fix build with ghc-7.6 	* raise required bytestring version
README.md view
@@ -4,6 +4,8 @@  Support for well-typed paths in Haskell. +This package is part of the HPath suite, also check out [hpath-filepath](https://hackage.haskell.org/package/hpath-filepath) and [hpath-io](https://hackage.haskell.org/package/hpath-io).+ ## Motivation  The motivation came during development of@@ -34,4 +36,3 @@ * allows pattern matching via unidirectional PatternSynonym * uses simple doctest for testing * allows `~/` as relative path, because on posix level `~` is just a regular filename that does _NOT_ point to `$HOME`-* remove TH, it sucks
hpath.cabal view
@@ -1,5 +1,5 @@ name:                hpath-version:             0.10.0+version:             0.10.1 synopsis:            Support for well-typed paths description:         Support for well-typed paths, utilizing ByteString under the hood. license:             BSD3@@ -36,6 +36,8 @@                    , deepseq                    , exceptions                    , hpath-filepath >= 0.10 && < 0.11+                   , template-haskell+                   , utf8-string                    , word8  source-repository head
src/HPath.hs view
@@ -16,6 +16,8 @@ #if __GLASGOW_HASKELL__ >= 708 {-# LANGUAGE PatternSynonyms #-} #endif+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}  module HPath   (@@ -50,6 +52,10 @@   ,withAbsPath   ,withRelPath   ,withFnPath+  -- * Quasiquoters+  ,abs+  ,rel+  ,fn   )   where @@ -62,10 +68,15 @@ import qualified Data.List as L #endif import qualified Data.ByteString as BS+import           Data.ByteString.UTF8 import           Data.Data import           Data.Maybe import           Data.Word8 import           HPath.Internal+import           Language.Haskell.TH+import           Language.Haskell.TH.Syntax (Exp(..), Lift(..), lift)+import           Language.Haskell.TH.Quote (QuasiQuoter(..))+import           Prelude hiding (abs) import           System.Posix.FilePath hiding ((</>))  @@ -374,3 +385,63 @@ stripPrefix :: ByteString -> ByteString -> Maybe ByteString stripPrefix a b = BS.pack `fmap` L.stripPrefix (BS.unpack a) (BS.unpack b) #endif+++------------------------+-- QuasiQuoters++instance Lift (Path a) where+  lift (MkPath bs) = AppE <$> [| MkPath . BS.pack |] <*> lift (BS.unpack bs)+++qq :: (ByteString -> Q Exp) -> QuasiQuoter+qq quoteExp' =+  QuasiQuoter+  { quoteExp  = (\s -> quoteExp' . fromString $ s)+  , quotePat  = \_ ->+      fail "illegal QuasiQuote (allowed as expression only, used as a pattern)"+  , quoteType = \_ ->+      fail "illegal QuasiQuote (allowed as expression only, used as a type)"+  , quoteDec  = \_ ->+      fail "illegal QuasiQuote (allowed as expression only, used as a declaration)"+  }++mkAbs :: ByteString -> Q Exp+mkAbs = either (error . show) lift . parseAbs++mkRel :: ByteString -> Q Exp+mkRel = either (error . show) lift . parseRel++mkFN :: ByteString -> Q Exp+mkFN = either (error . show) lift . parseFn++-- | Quasiquote an absolute Path. This accepts Unicode Chars and will encode as UTF-8.+--+-- >>> [abs|/etc/profile|] :: Path Abs+-- "/etc/profile"+-- >>> [abs|/|] :: Path Abs+-- "/"+-- >>> [abs|/|] :: Path Abs+-- "/\239\131\144"+abs :: QuasiQuoter+abs = qq mkAbs++-- | Quasiquote a relative Path. This accepts Unicode Chars and will encode as UTF-8.+--+-- >>> [rel|etc|] :: Path Rel+-- "etc"+-- >>> [rel|bar/baz|] :: Path Rel+-- "bar/baz"+-- >>> [rel||] :: Path Rel+-- "\239\131\144"+rel :: QuasiQuoter+rel = qq mkRel++-- | Quasiquote a file name. This accepts Unicode Chars and will encode as UTF-8.+--+-- >>> [fn|etc|] :: Path Fn+-- "etc"+-- >>> [fn||] :: Path Fn+-- "\239\131\144"+fn :: QuasiQuoter+fn = qq mkFN