hpath 0.10.1 → 0.10.2
raw patch · 3 files changed
+55/−3 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ HPath: any :: QuasiQuoter
+ HPath: parseAny :: MonadThrow m => ByteString -> m (Path a)
Files
- CHANGELOG +2/−0
- hpath.cabal +1/−1
- src/HPath.hs +52/−2
CHANGELOG view
@@ -1,3 +1,5 @@+0.10.2+ * Add `parseAny` and the related QuasiQuoter 0.10.1 * Add quasi quoters for hpath 0.10.0
hpath.cabal view
@@ -1,5 +1,5 @@ name: hpath-version: 0.10.1+version: 0.10.2 synopsis: Support for well-typed paths description: Support for well-typed paths, utilizing ByteString under the hood. license: BSD3
src/HPath.hs view
@@ -37,6 +37,7 @@ ,parseAbs ,parseFn ,parseRel+ ,parseAny -- * Path Conversion ,fromAbs ,fromRel@@ -56,6 +57,7 @@ ,abs ,rel ,fn+ ,any ) where @@ -76,7 +78,7 @@ import Language.Haskell.TH import Language.Haskell.TH.Syntax (Exp(..), Lift(..), lift) import Language.Haskell.TH.Quote (QuasiQuoter(..))-import Prelude hiding (abs)+import Prelude hiding (abs, any) import System.Posix.FilePath hiding ((</>)) @@ -227,7 +229,41 @@ else throwM (InvalidFn filepath) +-- | Parses a path, whether it's relative or absolute. Will lose+-- information on whether it's relative or absolute. If you need to know,+-- reparse it.+--+-- Filenames must not contain slashes.+-- Excludes '.' and '..'.+--+-- Throws: 'PathParseException'+--+-- >>> parseAny "/abc" :: Maybe (Path a)+-- Just "/abc"+-- >>> parseAny "..." :: Maybe (Path a)+-- Just "..."+-- >>> parseAny "abc/def" :: Maybe (Path a)+-- Just "abc/def"+-- >>> parseAny "abc/def/." :: Maybe (Path a)+-- Just "abc/def/"+-- >>> parseAny "/abc" :: Maybe (Path a)+-- Just "/abc"+-- >>> parseAny "" :: Maybe (Path a)+-- Nothing+-- >>> parseAny "abc/../foo" :: Maybe (Path a)+-- Nothing+-- >>> parseAny "." :: Maybe (Path a)+-- Nothing+-- >>> parseAny ".." :: Maybe (Path a)+-- Nothing+parseAny :: MonadThrow m => ByteString -> m (Path a)+parseAny filepath = case parseAbs filepath of+ Just (MkPath p) -> pure $ (MkPath p)+ Nothing -> case parseRel filepath of+ Just (MkPath p) -> pure $ (MkPath p)+ Nothing -> throwM (InvalidRel filepath) + -------------------------------------------------------------------------------- -- Path Conversion @@ -244,7 +280,6 @@ fromRel = toFilePath - -------------------------------------------------------------------------------- -- Path Operations @@ -415,6 +450,9 @@ mkFN :: ByteString -> Q Exp mkFN = either (error . show) lift . parseFn +mkAny :: ByteString -> Q Exp+mkAny = either (error . show) lift . parseAny+ -- | Quasiquote an absolute Path. This accepts Unicode Chars and will encode as UTF-8. -- -- >>> [abs|/etc/profile|] :: Path Abs@@ -445,3 +483,15 @@ -- "\239\131\144" fn :: QuasiQuoter fn = qq mkFN++-- | Quasiquote any path (relative or absolute).+-- This accepts Unicode Chars and will encode as UTF-8.+--+-- >>> [any|/etc/profile|] :: Path a+-- "/etc/profile"+-- >>> [any|etc|] :: Path a+-- "etc"+-- >>> [any||] :: Path a+-- "\239\131\144"+any :: QuasiQuoter+any = qq mkAny