{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoMonomorphismRestriction #-}

module Path.Tagged (
  -- * Types
  PathTo (..),
  ToSubpath,
  retagPath,
  Base (..),
  Untag,
  Abs,
  RelTo,
  File,
  Dir,

  -- ** Special Entity Tags
  Unknown,
  Subpath (..),
  EntryOf,
  Entry,
  Parent,
  ParentOf,
  SomeBase (..),
  untagSomeBase,

  -- * Exceptions
  PathException (..),

  -- * QuasiQuotes
  absdir,
  reldir,
  absfile,
  relfile,

  -- * Operations
  (</>),
  stripProperPrefix,
  isProperPrefixOf,
  replaceProperPrefix,
  replaceProperPrefix',
  parent,
  filename,
  dirname,
  addExtension,
  splitExtension,
  fileExtension,
  replaceExtension,
  mapSomeBase,
  prjSomeBase,

  -- * Parsing
  parseAbsDir,
  parseRelDir,
  parseAbsFile,
  parseRelFile,
  parseSomeDir,
  parseSomeFile,

  -- * Conversion
  toFilePath,
  fromAbsDir,
  fromRelDir,
  fromAbsFile,
  fromRelFile,
  fromSomeDir,
  fromSomeFile,

  -- * TemplateHaskell constructors
  mkAbsDir,
  mkRelDir,
  mkAbsFile,
  mkRelFile,

  -- ** Typed constructors
  mkAbsDirT,
  mkRelDirT,
  mkAbsFileT,
  mkRelFileT,
) where

import Control.DeepSeq (NFData)
import Control.Monad.Catch (MonadThrow)
import Data.Aeson (FromJSON, FromJSONKey, ToJSON, Value)
import qualified Data.Aeson.Types as J
import qualified Data.Bifunctor as Bi
import Data.Coerce (coerce)
import Data.Functor ((<&>))
import Data.Hashable (Hashable)
import Data.Kind (Type)
import Data.Maybe (isJust)
import GHC.Generics (Generic)
import GHC.TypeLits
import Language.Haskell.TH (ExpQ)
import Language.Haskell.TH.Quote (QuasiQuoter (..))
import Language.Haskell.TH.Syntax (Lift)
import Language.Haskell.TH.Syntax.Compat
import Path (Dir, File, PathException)
import qualified Path as P
import Type.Reflection (Typeable)

type role PathTo phantom nominal nominal

type PathTo :: forall {k}. k -> Base k -> Type -> Type
newtype PathTo entity pk t = PathTo {forall {k} (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> Path (Untag pk) t
untagPath :: P.Path (Untag pk) t}
  deriving ((forall x. PathTo entity pk t -> Rep (PathTo entity pk t) x)
-> (forall x. Rep (PathTo entity pk t) x -> PathTo entity pk t)
-> Generic (PathTo entity pk t)
forall x. Rep (PathTo entity pk t) x -> PathTo entity pk t
forall x. PathTo entity pk t -> Rep (PathTo entity pk t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k (entity :: k) (pk :: Base k) t x.
Rep (PathTo entity pk t) x -> PathTo entity pk t
forall k (entity :: k) (pk :: Base k) t x.
PathTo entity pk t -> Rep (PathTo entity pk t) x
$cfrom :: forall k (entity :: k) (pk :: Base k) t x.
PathTo entity pk t -> Rep (PathTo entity pk t) x
from :: forall x. PathTo entity pk t -> Rep (PathTo entity pk t) x
$cto :: forall k (entity :: k) (pk :: Base k) t x.
Rep (PathTo entity pk t) x -> PathTo entity pk t
to :: forall x. Rep (PathTo entity pk t) x -> PathTo entity pk t
Generic)
  deriving newtype (PathTo entity pk t -> PathTo entity pk t -> Bool
(PathTo entity pk t -> PathTo entity pk t -> Bool)
-> (PathTo entity pk t -> PathTo entity pk t -> Bool)
-> Eq (PathTo entity pk t)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> Bool
$c== :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> Bool
== :: PathTo entity pk t -> PathTo entity pk t -> Bool
$c/= :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> Bool
/= :: PathTo entity pk t -> PathTo entity pk t -> Bool
Eq, Eq (PathTo entity pk t)
Eq (PathTo entity pk t) =>
(PathTo entity pk t -> PathTo entity pk t -> Ordering)
-> (PathTo entity pk t -> PathTo entity pk t -> Bool)
-> (PathTo entity pk t -> PathTo entity pk t -> Bool)
-> (PathTo entity pk t -> PathTo entity pk t -> Bool)
-> (PathTo entity pk t -> PathTo entity pk t -> Bool)
-> (PathTo entity pk t -> PathTo entity pk t -> PathTo entity pk t)
-> (PathTo entity pk t -> PathTo entity pk t -> PathTo entity pk t)
-> Ord (PathTo entity pk t)
PathTo entity pk t -> PathTo entity pk t -> Bool
PathTo entity pk t -> PathTo entity pk t -> Ordering
PathTo entity pk t -> PathTo entity pk t -> PathTo entity pk t
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall k (entity :: k) (pk :: Base k) t. Eq (PathTo entity pk t)
forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> Bool
forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> Ordering
forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> PathTo entity pk t
$ccompare :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> Ordering
compare :: PathTo entity pk t -> PathTo entity pk t -> Ordering
$c< :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> Bool
< :: PathTo entity pk t -> PathTo entity pk t -> Bool
$c<= :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> Bool
<= :: PathTo entity pk t -> PathTo entity pk t -> Bool
$c> :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> Bool
> :: PathTo entity pk t -> PathTo entity pk t -> Bool
$c>= :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> Bool
>= :: PathTo entity pk t -> PathTo entity pk t -> Bool
$cmax :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> PathTo entity pk t
max :: PathTo entity pk t -> PathTo entity pk t -> PathTo entity pk t
$cmin :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> PathTo entity pk t -> PathTo entity pk t
min :: PathTo entity pk t -> PathTo entity pk t -> PathTo entity pk t
Ord, Int -> PathTo entity pk t -> ShowS
[PathTo entity pk t] -> ShowS
PathTo entity pk t -> String
(Int -> PathTo entity pk t -> ShowS)
-> (PathTo entity pk t -> String)
-> ([PathTo entity pk t] -> ShowS)
-> Show (PathTo entity pk t)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (entity :: k) (pk :: Base k) t.
Int -> PathTo entity pk t -> ShowS
forall k (entity :: k) (pk :: Base k) t.
[PathTo entity pk t] -> ShowS
forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> String
$cshowsPrec :: forall k (entity :: k) (pk :: Base k) t.
Int -> PathTo entity pk t -> ShowS
showsPrec :: Int -> PathTo entity pk t -> ShowS
$cshow :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> String
show :: PathTo entity pk t -> String
$cshowList :: forall k (entity :: k) (pk :: Base k) t.
[PathTo entity pk t] -> ShowS
showList :: [PathTo entity pk t] -> ShowS
Show, Eq (PathTo entity pk t)
Eq (PathTo entity pk t) =>
(Int -> PathTo entity pk t -> Int)
-> (PathTo entity pk t -> Int) -> Hashable (PathTo entity pk t)
Int -> PathTo entity pk t -> Int
PathTo entity pk t -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
forall k (entity :: k) (pk :: Base k) t. Eq (PathTo entity pk t)
forall k (entity :: k) (pk :: Base k) t.
Int -> PathTo entity pk t -> Int
forall k (entity :: k) (pk :: Base k) t. PathTo entity pk t -> Int
$chashWithSalt :: forall k (entity :: k) (pk :: Base k) t.
Int -> PathTo entity pk t -> Int
hashWithSalt :: Int -> PathTo entity pk t -> Int
$chash :: forall k (entity :: k) (pk :: Base k) t. PathTo entity pk t -> Int
hash :: PathTo entity pk t -> Int
Hashable, [PathTo entity pk t] -> Value
[PathTo entity pk t] -> Encoding
PathTo entity pk t -> Bool
PathTo entity pk t -> Value
PathTo entity pk t -> Encoding
(PathTo entity pk t -> Value)
-> (PathTo entity pk t -> Encoding)
-> ([PathTo entity pk t] -> Value)
-> ([PathTo entity pk t] -> Encoding)
-> (PathTo entity pk t -> Bool)
-> ToJSON (PathTo entity pk t)
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
forall k (entity :: k) (pk :: Base k) t.
[PathTo entity pk t] -> Value
forall k (entity :: k) (pk :: Base k) t.
[PathTo entity pk t] -> Encoding
forall k (entity :: k) (pk :: Base k) t. PathTo entity pk t -> Bool
forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> Value
forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> Encoding
$ctoJSON :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> Value
toJSON :: PathTo entity pk t -> Value
$ctoEncoding :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> Encoding
toEncoding :: PathTo entity pk t -> Encoding
$ctoJSONList :: forall k (entity :: k) (pk :: Base k) t.
[PathTo entity pk t] -> Value
toJSONList :: [PathTo entity pk t] -> Value
$ctoEncodingList :: forall k (entity :: k) (pk :: Base k) t.
[PathTo entity pk t] -> Encoding
toEncodingList :: [PathTo entity pk t] -> Encoding
$comitField :: forall k (entity :: k) (pk :: Base k) t. PathTo entity pk t -> Bool
omitField :: PathTo entity pk t -> Bool
ToJSON, PathTo entity pk t -> ()
(PathTo entity pk t -> ()) -> NFData (PathTo entity pk t)
forall a. (a -> ()) -> NFData a
forall k (entity :: k) (pk :: Base k) t. PathTo entity pk t -> ()
$crnf :: forall k (entity :: k) (pk :: Base k) t. PathTo entity pk t -> ()
rnf :: PathTo entity pk t -> ()
NFData)

deriving instance (Typeable t, Typeable (Untag b)) => Lift (PathTo e b t)

-- | Unknown base directory
type Unknown :: k
type family Unknown where

type EntryOf :: forall {k}. Subpath k -> k
type family EntryOf k where
  EntryOf ('Entry e) = e
  EntryOf p = TypeError ('Text "Concrete entry expected, but got: " ':<>: 'ShowType p)

data Subpath k = Entry k | Parent (Subpath k)

type Entry = 'Entry

type Parent = 'Parent

type ParentOf e = 'Parent ('Entry e)

type Retagged' :: forall k k' -> Base k -> Base k'
type family Retagged' k k' bk where
  Retagged' k k a = a
  Retagged' k k' Abs = Abs
  Retagged' k k' (RelTo p) =
    TypeError ('Text "Different kind of path cannot be rettaged with relative base: " ':<>: 'ShowType (RelTo p))

type Retagged :: forall {k} {k'}. Base k -> Base k'
type Retagged (a :: Base k) = Retagged' k k' a :: Base k'

retagPath :: PathTo p b t -> PathTo p' (Retagged b) t
retagPath :: forall {k} {k} (p :: k) (b :: Base k) t (p' :: k).
PathTo p b t -> PathTo p' (Retagged b) t
retagPath = PathTo p b t -> PathTo p' (Retagged' k k b) t
forall a b. Coercible a b => a -> b
coerce

deriving newtype instance FromJSON (PathTo k (RelTo b) File)

deriving newtype instance FromJSON (PathTo k (RelTo b) Dir)

deriving newtype instance FromJSON (PathTo k Abs File)

deriving newtype instance FromJSON (PathTo k Abs Dir)

deriving newtype instance FromJSONKey (PathTo k (RelTo b) File)

deriving newtype instance FromJSONKey (PathTo k (RelTo b) Dir)

deriving newtype instance FromJSONKey (PathTo k Abs File)

deriving newtype instance FromJSONKey (PathTo k Abs Dir)

type Untag :: forall {k}. Base k -> Type
type family Untag pk where
  Untag ('RelTo _) = P.Rel
  Untag 'Abs = P.Abs

data Base k = RelTo k | Abs

type RelTo = 'RelTo

type Abs = 'Abs

(</>) :: PathTo parent b Dir -> PathTo child (RelTo parent) t -> PathTo child b t
{-# INLINE (</>) #-}
</> :: forall {k} (parent :: k) (b :: Base k) (child :: k) t.
PathTo parent b Dir
-> PathTo child (RelTo parent) t -> PathTo child b t
(</>) = (Path Any Dir -> Path Rel Any -> Path Any Any)
-> PathTo parent b Dir
-> PathTo child (RelTo parent) t
-> PathTo child b t
forall a b. Coercible a b => a -> b
coerce Path Any Dir -> Path Rel Any -> Path Any Any
forall b t. Path b Dir -> Path Rel t -> Path b t
(P.</>)

infixr 5 </>

stripProperPrefix :: (MonadThrow m) => PathTo p b Dir -> PathTo l b t -> m (PathTo l (RelTo p) t)
stripProperPrefix :: forall {k} (m :: * -> *) (p :: k) (b :: Base k) (l :: k) t.
MonadThrow m =>
PathTo p b Dir -> PathTo l b t -> m (PathTo l (RelTo p) t)
stripProperPrefix (PathTo Path (Untag b) Dir
p) (PathTo Path (Untag b) t
l) = Path Rel t -> PathTo l (RelTo p) t
Path (Untag (RelTo p)) t -> PathTo l (RelTo p) t
forall {k} (entity :: k) (pk :: Base k) t.
Path (Untag pk) t -> PathTo entity pk t
PathTo (Path Rel t -> PathTo l (RelTo p) t)
-> m (Path Rel t) -> m (PathTo l (RelTo p) t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Path (Untag b) Dir -> Path (Untag b) t -> m (Path Rel t)
forall (m :: * -> *) b t.
MonadThrow m =>
Path b Dir -> Path b t -> m (Path Rel t)
P.stripProperPrefix Path (Untag b) Dir
p Path (Untag b) t
l

isProperPrefixOf :: PathTo p b Dir -> PathTo l b t -> Bool
isProperPrefixOf :: forall {k} (p :: k) (b :: Base k) (l :: k) t.
PathTo p b Dir -> PathTo l b t -> Bool
isProperPrefixOf PathTo p b Dir
p PathTo l b t
l = Maybe (PathTo l (RelTo p) t) -> Bool
forall a. Maybe a -> Bool
isJust (PathTo p b Dir -> PathTo l b t -> Maybe (PathTo l (RelTo p) t)
forall {k} (m :: * -> *) (p :: k) (b :: Base k) (l :: k) t.
MonadThrow m =>
PathTo p b Dir -> PathTo l b t -> m (PathTo l (RelTo p) t)
stripProperPrefix PathTo p b Dir
p PathTo l b t
l)

replaceProperPrefix ::
  (MonadThrow m) =>
  PathTo parent b Dir ->
  PathTo parent' b' Dir ->
  PathTo child b t ->
  m (PathTo child b' t)
replaceProperPrefix :: forall {k} (m :: * -> *) (parent :: k) (b :: Base k) (parent' :: k)
       (b' :: Base k) (child :: k) t.
MonadThrow m =>
PathTo parent b Dir
-> PathTo parent' b' Dir
-> PathTo child b t
-> m (PathTo child b' t)
replaceProperPrefix PathTo parent b Dir
src PathTo parent' b' Dir
dst PathTo child b t
fp = (PathTo parent' b' Dir
dst PathTo parent' b' Dir
-> PathTo child (RelTo parent') t -> PathTo child b' t
forall {k} (parent :: k) (b :: Base k) (child :: k) t.
PathTo parent b Dir
-> PathTo child (RelTo parent) t -> PathTo child b t
</>) (PathTo child (RelTo parent') t -> PathTo child b' t)
-> m (PathTo child (RelTo parent') t) -> m (PathTo child b' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PathTo parent' b Dir
-> PathTo child b t -> m (PathTo child (RelTo parent') t)
forall {k} (m :: * -> *) (p :: k) (b :: Base k) (l :: k) t.
MonadThrow m =>
PathTo p b Dir -> PathTo l b t -> m (PathTo l (RelTo p) t)
stripProperPrefix (PathTo parent b Dir -> PathTo parent' (Retagged b) Dir
forall {k} {k} (p :: k) (b :: Base k) t (p' :: k).
PathTo p b t -> PathTo p' (Retagged b) t
retagPath PathTo parent b Dir
src) PathTo child b t
fp

replaceProperPrefix' ::
  (MonadThrow m) =>
  PathTo parent b Dir ->
  PathTo parent b' Dir ->
  PathTo child b t ->
  m (PathTo child b' t)
replaceProperPrefix' :: forall {k} (m :: * -> *) (parent :: k) (b :: Base k) (b' :: Base k)
       (child :: k) t.
MonadThrow m =>
PathTo parent b Dir
-> PathTo parent b' Dir
-> PathTo child b t
-> m (PathTo child b' t)
replaceProperPrefix' PathTo parent b Dir
src PathTo parent b' Dir
dst PathTo child b t
fp = (PathTo parent b' Dir
dst PathTo parent b' Dir
-> PathTo child (RelTo parent) t -> PathTo child b' t
forall {k} (parent :: k) (b :: Base k) (child :: k) t.
PathTo parent b Dir
-> PathTo child (RelTo parent) t -> PathTo child b t
</>) (PathTo child (RelTo parent) t -> PathTo child b' t)
-> m (PathTo child (RelTo parent) t) -> m (PathTo child b' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PathTo parent b Dir
-> PathTo child b t -> m (PathTo child (RelTo parent) t)
forall {k} (m :: * -> *) (p :: k) (b :: Base k) (l :: k) t.
MonadThrow m =>
PathTo p b Dir -> PathTo l b t -> m (PathTo l (RelTo p) t)
stripProperPrefix PathTo parent b Dir
src PathTo child b t
fp

type ToSubpath :: forall {k}. Base k -> Base (Subpath k)
type family ToSubpath a where
  ToSubpath 'Abs = 'Abs
  ToSubpath ('RelTo e) = 'RelTo (Entry e)

parent :: PathTo e b t -> PathTo (ParentOf e) (ToSubpath b) Dir
parent :: forall {k} (e :: k) (b :: Base k) t.
PathTo e b t -> PathTo (ParentOf e) (ToSubpath b) Dir
parent = (Path Any Any -> Path Any Dir)
-> PathTo e b t -> PathTo (ParentOf e) (ToSubpath b) Dir
forall a b. Coercible a b => a -> b
coerce Path Any Any -> Path Any Dir
forall b t. Path b t -> Path b Dir
P.parent

filename :: PathTo e b File -> PathTo (Entry e) (RelTo (ParentOf e)) File
filename :: forall {k} (e :: k) (b :: Base k).
PathTo e b File -> PathTo (Entry e) (RelTo (ParentOf e)) File
filename = (Path Any File -> Path Rel File)
-> PathTo e b File -> PathTo (Entry e) (RelTo (ParentOf e)) File
forall a b. Coercible a b => a -> b
coerce Path Any File -> Path Rel File
forall b. Path b File -> Path Rel File
P.filename

dirname :: PathTo e b Dir -> PathTo (Entry e) (RelTo (ParentOf e)) Dir
dirname :: forall {k} (e :: k) (b :: Base k).
PathTo e b Dir -> PathTo (Entry e) (RelTo (ParentOf e)) Dir
dirname = (Path Any Dir -> Path Rel Dir)
-> PathTo e b Dir -> PathTo (Entry e) (RelTo (ParentOf e)) Dir
forall a b. Coercible a b => a -> b
coerce Path Any Dir -> Path Rel Dir
forall b. Path b Dir -> Path Rel Dir
P.dirname

addExtension :: forall e' m e b. (MonadThrow m) => String -> PathTo e b File -> m (PathTo e' b File)
addExtension :: forall {k} (e' :: k) (m :: * -> *) (e :: k) (b :: Base k).
MonadThrow m =>
String -> PathTo e b File -> m (PathTo e' b File)
addExtension String
ext = (Path (Untag b) File -> PathTo e' b File)
-> m (Path (Untag b) File) -> m (PathTo e' b File)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Path (Untag b) File -> PathTo e' b File
forall {k} (entity :: k) (pk :: Base k) t.
Path (Untag pk) t -> PathTo entity pk t
PathTo (m (Path (Untag b) File) -> m (PathTo e' b File))
-> (PathTo e b File -> m (Path (Untag b) File))
-> PathTo e b File
-> m (PathTo e' b File)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Path (Untag b) File -> m (Path (Untag b) File)
forall (m :: * -> *) b.
MonadThrow m =>
String -> Path b File -> m (Path b File)
P.addExtension String
ext (Path (Untag b) File -> m (Path (Untag b) File))
-> (PathTo e b File -> Path (Untag b) File)
-> PathTo e b File
-> m (Path (Untag b) File)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PathTo e b File -> Path (Untag b) File
forall a b. Coercible a b => a -> b
coerce

splitExtension ::
  forall e' m e b.
  (MonadThrow m) =>
  PathTo e b File ->
  m (PathTo e' b File, String)
splitExtension :: forall {k} (e' :: k) (m :: * -> *) (e :: k) (b :: Base k).
MonadThrow m =>
PathTo e b File -> m (PathTo e' b File, String)
splitExtension = ((Path (Untag b) File, String) -> (PathTo e' b File, String))
-> m (Path (Untag b) File, String) -> m (PathTo e' b File, String)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Path (Untag b) File -> PathTo e' b File)
-> (Path (Untag b) File, String) -> (PathTo e' b File, String)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
Bi.first Path (Untag b) File -> PathTo e' b File
forall {k} (entity :: k) (pk :: Base k) t.
Path (Untag pk) t -> PathTo entity pk t
PathTo) (m (Path (Untag b) File, String) -> m (PathTo e' b File, String))
-> (PathTo e b File -> m (Path (Untag b) File, String))
-> PathTo e b File
-> m (PathTo e' b File, String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Path (Untag b) File -> m (Path (Untag b) File, String)
forall (m :: * -> *) b.
MonadThrow m =>
Path b File -> m (Path b File, String)
P.splitExtension (Path (Untag b) File -> m (Path (Untag b) File, String))
-> (PathTo e b File -> Path (Untag b) File)
-> PathTo e b File
-> m (Path (Untag b) File, String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PathTo e b File -> Path (Untag b) File
forall a b. Coercible a b => a -> b
coerce

fileExtension :: (MonadThrow m) => PathTo e b File -> m String
fileExtension :: forall {k} (m :: * -> *) (e :: k) (b :: Base k).
MonadThrow m =>
PathTo e b File -> m String
fileExtension = Path Any File -> m String
forall (m :: * -> *) b. MonadThrow m => Path b File -> m String
P.fileExtension (Path Any File -> m String)
-> (PathTo e b File -> Path Any File)
-> PathTo e b File
-> m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PathTo e b File -> Path Any File
forall a b. Coercible a b => a -> b
coerce

replaceExtension ::
  forall e' m e b.
  (MonadThrow m) =>
  String ->
  PathTo e b File ->
  m (PathTo e' b File)
replaceExtension :: forall {k} (e' :: k) (m :: * -> *) (e :: k) (b :: Base k).
MonadThrow m =>
String -> PathTo e b File -> m (PathTo e' b File)
replaceExtension String
ext = (Path (Untag b) File -> PathTo e' b File)
-> m (Path (Untag b) File) -> m (PathTo e' b File)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Path (Untag b) File -> PathTo e' b File
forall {k} (entity :: k) (pk :: Base k) t.
Path (Untag pk) t -> PathTo entity pk t
PathTo (m (Path (Untag b) File) -> m (PathTo e' b File))
-> (PathTo e b File -> m (Path (Untag b) File))
-> PathTo e b File
-> m (PathTo e' b File)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Path (Untag b) File -> m (Path (Untag b) File)
forall (m :: * -> *) b.
MonadThrow m =>
String -> Path b File -> m (Path b File)
P.replaceExtension String
ext (Path (Untag b) File -> m (Path (Untag b) File))
-> (PathTo e b File -> Path (Untag b) File)
-> PathTo e b File
-> m (Path (Untag b) File)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PathTo e b File -> Path (Untag b) File
forall a b. Coercible a b => a -> b
coerce

mapSomeBase :: (forall c. PathTo e c t -> PathTo e' c t') -> SomeBase e b t -> SomeBase e' b t'
mapSomeBase :: forall {k} (e :: k) t (e' :: k) t' (b :: k).
(forall (c :: Base k). PathTo e c t -> PathTo e' c t')
-> SomeBase e b t -> SomeBase e' b t'
mapSomeBase forall (c :: Base k). PathTo e c t -> PathTo e' c t'
f = \case
  IsAbs PathTo e Abs t
fp -> PathTo e' Abs t' -> SomeBase e' b t'
forall {k} (e :: k) (b :: k) t. PathTo e Abs t -> SomeBase e b t
IsAbs (PathTo e Abs t -> PathTo e' Abs t'
forall (c :: Base k). PathTo e c t -> PathTo e' c t'
f PathTo e Abs t
fp)
  IsRel PathTo e (RelTo b) t
fp -> PathTo e' (RelTo b) t' -> SomeBase e' b t'
forall {k} (e :: k) (b :: k) t.
PathTo e (RelTo b) t -> SomeBase e b t
IsRel (PathTo e (RelTo b) t -> PathTo e' (RelTo b) t'
forall (c :: Base k). PathTo e c t -> PathTo e' c t'
f PathTo e (RelTo b) t
fp)

prjSomeBase :: (forall c. PathTo e c t -> a) -> SomeBase e b t -> a
prjSomeBase :: forall {k} (e :: k) t a (b :: k).
(forall (c :: Base k). PathTo e c t -> a) -> SomeBase e b t -> a
prjSomeBase forall (c :: Base k). PathTo e c t -> a
f = \case
  IsAbs PathTo e Abs t
fp -> PathTo e Abs t -> a
forall (c :: Base k). PathTo e c t -> a
f PathTo e Abs t
fp
  IsRel PathTo e (RelTo b) t
fp -> PathTo e (RelTo b) t -> a
forall (c :: Base k). PathTo e c t -> a
f PathTo e (RelTo b) t
fp

parseAbsDir :: forall e m. (MonadThrow m) => FilePath -> m (PathTo e Abs Dir)
parseAbsDir :: forall {k} (e :: k) (m :: * -> *).
MonadThrow m =>
String -> m (PathTo e Abs Dir)
parseAbsDir = (Path Abs Dir -> PathTo e Abs Dir)
-> m (Path Abs Dir) -> m (PathTo e Abs Dir)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Path Abs Dir -> PathTo e Abs Dir
forall a b. Coercible a b => a -> b
coerce (m (Path Abs Dir) -> m (PathTo e Abs Dir))
-> (String -> m (Path Abs Dir)) -> String -> m (PathTo e Abs Dir)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m (Path Abs Dir)
forall (m :: * -> *). MonadThrow m => String -> m (Path Abs Dir)
P.parseAbsDir

parseRelDir :: forall e b m. (MonadThrow m) => FilePath -> m (PathTo e (RelTo b) Dir)
parseRelDir :: forall {k} (e :: k) (b :: k) (m :: * -> *).
MonadThrow m =>
String -> m (PathTo e (RelTo b) Dir)
parseRelDir = (Path Rel Dir -> PathTo e (RelTo b) Dir)
-> m (Path Rel Dir) -> m (PathTo e (RelTo b) Dir)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Path Rel Dir -> PathTo e (RelTo b) Dir
forall a b. Coercible a b => a -> b
coerce (m (Path Rel Dir) -> m (PathTo e (RelTo b) Dir))
-> (String -> m (Path Rel Dir))
-> String
-> m (PathTo e (RelTo b) Dir)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m (Path Rel Dir)
forall (m :: * -> *). MonadThrow m => String -> m (Path Rel Dir)
P.parseRelDir

parseAbsFile :: forall e m. (MonadThrow m) => FilePath -> m (PathTo e Abs File)
parseAbsFile :: forall {k} (e :: k) (m :: * -> *).
MonadThrow m =>
String -> m (PathTo e Abs File)
parseAbsFile = (Path Abs File -> PathTo e Abs File)
-> m (Path Abs File) -> m (PathTo e Abs File)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Path Abs File -> PathTo e Abs File
forall a b. Coercible a b => a -> b
coerce (m (Path Abs File) -> m (PathTo e Abs File))
-> (String -> m (Path Abs File)) -> String -> m (PathTo e Abs File)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m (Path Abs File)
forall (m :: * -> *). MonadThrow m => String -> m (Path Abs File)
P.parseAbsFile

parseRelFile :: forall e b m. (MonadThrow m) => FilePath -> m (PathTo e (RelTo b) File)
parseRelFile :: forall {k} (e :: k) (b :: k) (m :: * -> *).
MonadThrow m =>
String -> m (PathTo e (RelTo b) File)
parseRelFile = (Path Rel File -> PathTo e (RelTo b) File)
-> m (Path Rel File) -> m (PathTo e (RelTo b) File)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Path Rel File -> PathTo e (RelTo b) File
forall a b. Coercible a b => a -> b
coerce (m (Path Rel File) -> m (PathTo e (RelTo b) File))
-> (String -> m (Path Rel File))
-> String
-> m (PathTo e (RelTo b) File)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m (Path Rel File)
forall (m :: * -> *). MonadThrow m => String -> m (Path Rel File)
P.parseRelFile

parseSomeDir :: (MonadThrow m) => FilePath -> m (SomeBase e b Dir)
{-# INLINE parseSomeDir #-}
parseSomeDir :: forall {k} (m :: * -> *) (e :: k) (b :: k).
MonadThrow m =>
String -> m (SomeBase e b Dir)
parseSomeDir String
fp =
  String -> m (SomeBase Dir)
forall (m :: * -> *). MonadThrow m => String -> m (SomeBase Dir)
P.parseSomeDir String
fp m (SomeBase Dir)
-> (SomeBase Dir -> SomeBase e b Dir) -> m (SomeBase e b Dir)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
    P.Abs Path Abs Dir
p -> PathTo e Abs Dir -> SomeBase e b Dir
forall {k} (e :: k) (b :: k) t. PathTo e Abs t -> SomeBase e b t
IsAbs (PathTo e Abs Dir -> SomeBase e b Dir)
-> PathTo e Abs Dir -> SomeBase e b Dir
forall a b. (a -> b) -> a -> b
$ Path (Untag Abs) Dir -> PathTo e Abs Dir
forall {k} (entity :: k) (pk :: Base k) t.
Path (Untag pk) t -> PathTo entity pk t
PathTo Path Abs Dir
Path (Untag Abs) Dir
p
    P.Rel Path Rel Dir
p -> PathTo e (RelTo b) Dir -> SomeBase e b Dir
forall {k} (e :: k) (b :: k) t.
PathTo e (RelTo b) t -> SomeBase e b t
IsRel (PathTo e (RelTo b) Dir -> SomeBase e b Dir)
-> PathTo e (RelTo b) Dir -> SomeBase e b Dir
forall a b. (a -> b) -> a -> b
$ Path (Untag (RelTo b)) Dir -> PathTo e (RelTo b) Dir
forall {k} (entity :: k) (pk :: Base k) t.
Path (Untag pk) t -> PathTo entity pk t
PathTo Path Rel Dir
Path (Untag (RelTo b)) Dir
p

parseSomeFile :: (MonadThrow m) => FilePath -> m (SomeBase e b File)
{-# INLINE parseSomeFile #-}
parseSomeFile :: forall {k} (m :: * -> *) (e :: k) (b :: k).
MonadThrow m =>
String -> m (SomeBase e b File)
parseSomeFile String
fp =
  String -> m (SomeBase File)
forall (m :: * -> *). MonadThrow m => String -> m (SomeBase File)
P.parseSomeFile String
fp m (SomeBase File)
-> (SomeBase File -> SomeBase e b File) -> m (SomeBase e b File)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
    P.Abs Path Abs File
p -> PathTo e Abs File -> SomeBase e b File
forall {k} (e :: k) (b :: k) t. PathTo e Abs t -> SomeBase e b t
IsAbs (PathTo e Abs File -> SomeBase e b File)
-> PathTo e Abs File -> SomeBase e b File
forall a b. (a -> b) -> a -> b
$ Path (Untag Abs) File -> PathTo e Abs File
forall {k} (entity :: k) (pk :: Base k) t.
Path (Untag pk) t -> PathTo entity pk t
PathTo Path Abs File
Path (Untag Abs) File
p
    P.Rel Path Rel File
p -> PathTo e (RelTo b) File -> SomeBase e b File
forall {k} (e :: k) (b :: k) t.
PathTo e (RelTo b) t -> SomeBase e b t
IsRel (PathTo e (RelTo b) File -> SomeBase e b File)
-> PathTo e (RelTo b) File -> SomeBase e b File
forall a b. (a -> b) -> a -> b
$ Path (Untag (RelTo b)) File -> PathTo e (RelTo b) File
forall {k} (entity :: k) (pk :: Base k) t.
Path (Untag pk) t -> PathTo entity pk t
PathTo Path Rel File
Path (Untag (RelTo b)) File
p

data SomeBase e b t
  = IsAbs (PathTo e Abs t)
  | IsRel (PathTo e (RelTo b) t)
  deriving (Int -> SomeBase e b t -> ShowS
[SomeBase e b t] -> ShowS
SomeBase e b t -> String
(Int -> SomeBase e b t -> ShowS)
-> (SomeBase e b t -> String)
-> ([SomeBase e b t] -> ShowS)
-> Show (SomeBase e b t)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (e :: k) (b :: k) t. Int -> SomeBase e b t -> ShowS
forall k (e :: k) (b :: k) t. [SomeBase e b t] -> ShowS
forall k (e :: k) (b :: k) t. SomeBase e b t -> String
$cshowsPrec :: forall k (e :: k) (b :: k) t. Int -> SomeBase e b t -> ShowS
showsPrec :: Int -> SomeBase e b t -> ShowS
$cshow :: forall k (e :: k) (b :: k) t. SomeBase e b t -> String
show :: SomeBase e b t -> String
$cshowList :: forall k (e :: k) (b :: k) t. [SomeBase e b t] -> ShowS
showList :: [SomeBase e b t] -> ShowS
Show, SomeBase e b t -> SomeBase e b t -> Bool
(SomeBase e b t -> SomeBase e b t -> Bool)
-> (SomeBase e b t -> SomeBase e b t -> Bool)
-> Eq (SomeBase e b t)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> Bool
$c== :: forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> Bool
== :: SomeBase e b t -> SomeBase e b t -> Bool
$c/= :: forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> Bool
/= :: SomeBase e b t -> SomeBase e b t -> Bool
Eq, Eq (SomeBase e b t)
Eq (SomeBase e b t) =>
(SomeBase e b t -> SomeBase e b t -> Ordering)
-> (SomeBase e b t -> SomeBase e b t -> Bool)
-> (SomeBase e b t -> SomeBase e b t -> Bool)
-> (SomeBase e b t -> SomeBase e b t -> Bool)
-> (SomeBase e b t -> SomeBase e b t -> Bool)
-> (SomeBase e b t -> SomeBase e b t -> SomeBase e b t)
-> (SomeBase e b t -> SomeBase e b t -> SomeBase e b t)
-> Ord (SomeBase e b t)
SomeBase e b t -> SomeBase e b t -> Bool
SomeBase e b t -> SomeBase e b t -> Ordering
SomeBase e b t -> SomeBase e b t -> SomeBase e b t
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall k (e :: k) (b :: k) t. Eq (SomeBase e b t)
forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> Bool
forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> Ordering
forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> SomeBase e b t
$ccompare :: forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> Ordering
compare :: SomeBase e b t -> SomeBase e b t -> Ordering
$c< :: forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> Bool
< :: SomeBase e b t -> SomeBase e b t -> Bool
$c<= :: forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> Bool
<= :: SomeBase e b t -> SomeBase e b t -> Bool
$c> :: forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> Bool
> :: SomeBase e b t -> SomeBase e b t -> Bool
$c>= :: forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> Bool
>= :: SomeBase e b t -> SomeBase e b t -> Bool
$cmax :: forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> SomeBase e b t
max :: SomeBase e b t -> SomeBase e b t -> SomeBase e b t
$cmin :: forall k (e :: k) (b :: k) t.
SomeBase e b t -> SomeBase e b t -> SomeBase e b t
min :: SomeBase e b t -> SomeBase e b t -> SomeBase e b t
Ord, (forall x. SomeBase e b t -> Rep (SomeBase e b t) x)
-> (forall x. Rep (SomeBase e b t) x -> SomeBase e b t)
-> Generic (SomeBase e b t)
forall x. Rep (SomeBase e b t) x -> SomeBase e b t
forall x. SomeBase e b t -> Rep (SomeBase e b t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k (e :: k) (b :: k) t x.
Rep (SomeBase e b t) x -> SomeBase e b t
forall k (e :: k) (b :: k) t x.
SomeBase e b t -> Rep (SomeBase e b t) x
$cfrom :: forall k (e :: k) (b :: k) t x.
SomeBase e b t -> Rep (SomeBase e b t) x
from :: forall x. SomeBase e b t -> Rep (SomeBase e b t) x
$cto :: forall k (e :: k) (b :: k) t x.
Rep (SomeBase e b t) x -> SomeBase e b t
to :: forall x. Rep (SomeBase e b t) x -> SomeBase e b t
Generic)
  deriving anyclass (SomeBase e b t -> ()
(SomeBase e b t -> ()) -> NFData (SomeBase e b t)
forall a. (a -> ()) -> NFData a
forall k (e :: k) (b :: k) t. SomeBase e b t -> ()
$crnf :: forall k (e :: k) (b :: k) t. SomeBase e b t -> ()
rnf :: SomeBase e b t -> ()
NFData, Eq (SomeBase e b t)
Eq (SomeBase e b t) =>
(Int -> SomeBase e b t -> Int)
-> (SomeBase e b t -> Int) -> Hashable (SomeBase e b t)
Int -> SomeBase e b t -> Int
SomeBase e b t -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
forall k (e :: k) (b :: k) t. Eq (SomeBase e b t)
forall k (e :: k) (b :: k) t. Int -> SomeBase e b t -> Int
forall k (e :: k) (b :: k) t. SomeBase e b t -> Int
$chashWithSalt :: forall k (e :: k) (b :: k) t. Int -> SomeBase e b t -> Int
hashWithSalt :: Int -> SomeBase e b t -> Int
$chash :: forall k (e :: k) (b :: k) t. SomeBase e b t -> Int
hash :: SomeBase e b t -> Int
Hashable)

instance FromJSON (SomeBase e b Dir) where
  parseJSON :: Value -> Parser (SomeBase e b Dir)
parseJSON = (String -> Either SomeException (SomeBase e b Dir))
-> Value -> Parser (SomeBase e b Dir)
forall e a b.
(Show e, FromJSON a) =>
(a -> Either e b) -> Value -> Parser b
parseJSONWith String -> Either SomeException (SomeBase e b Dir)
forall {k} (m :: * -> *) (e :: k) (b :: k).
MonadThrow m =>
String -> m (SomeBase e b Dir)
parseSomeDir
  {-# INLINE parseJSON #-}

instance FromJSON (SomeBase e b File) where
  parseJSON :: Value -> Parser (SomeBase e b File)
parseJSON = (String -> Either SomeException (SomeBase e b File))
-> Value -> Parser (SomeBase e b File)
forall e a b.
(Show e, FromJSON a) =>
(a -> Either e b) -> Value -> Parser b
parseJSONWith String -> Either SomeException (SomeBase e b File)
forall {k} (m :: * -> *) (e :: k) (b :: k).
MonadThrow m =>
String -> m (SomeBase e b File)
parseSomeFile
  {-# INLINE parseJSON #-}

instance ToJSON (SomeBase e b t) where
  toJSON :: SomeBase e b t -> Value
toJSON = String -> Value
forall a. ToJSON a => a -> Value
J.toJSON (String -> Value)
-> (SomeBase e b t -> String) -> SomeBase e b t -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (c :: Base k). PathTo e c t -> String)
-> SomeBase e b t -> String
forall {k} (e :: k) t a (b :: k).
(forall (c :: Base k). PathTo e c t -> a) -> SomeBase e b t -> a
prjSomeBase PathTo e c t -> String
forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> String
forall (c :: Base k). PathTo e c t -> String
toFilePath

parseJSONWith ::
  (Show e, FromJSON a) =>
  (a -> Either e b) ->
  Value ->
  J.Parser b
parseJSONWith :: forall e a b.
(Show e, FromJSON a) =>
(a -> Either e b) -> Value -> Parser b
parseJSONWith a -> Either e b
f Value
x =
  do
    a
fp <- Value -> Parser a
forall a. FromJSON a => Value -> Parser a
J.parseJSON Value
x
    case a -> Either e b
f a
fp of
      Right b
p -> b -> Parser b
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return b
p
      Left e
e -> String -> Parser b
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (e -> String
forall a. Show a => a -> String
show e
e)
{-# INLINE parseJSONWith #-}

untagSomeBase :: SomeBase e b t -> P.SomeBase t
untagSomeBase :: forall {k} (e :: k) (b :: k) t. SomeBase e b t -> SomeBase t
untagSomeBase (IsAbs (PathTo Path (Untag Abs) t
fp)) = Path Abs t -> SomeBase t
forall t. Path Abs t -> SomeBase t
P.Abs Path Abs t
Path (Untag Abs) t
fp
untagSomeBase (IsRel (PathTo Path (Untag (RelTo b)) t
fp)) = Path Rel t -> SomeBase t
forall t. Path Rel t -> SomeBase t
P.Rel Path Rel t
Path (Untag (RelTo b)) t
fp

wrapE :: (FilePath -> ExpQ) -> FilePath -> ExpQ
wrapE :: (String -> ExpQ) -> String -> ExpQ
wrapE String -> ExpQ
e String
fp = [|PathTo $(String -> ExpQ
e String
fp)|]

wrapPathQQ :: QuasiQuoter -> QuasiQuoter
wrapPathQQ :: QuasiQuoter -> QuasiQuoter
wrapPathQQ QuasiQuoter
qq = QuasiQuoter
qq {quoteExp = wrapE (quoteExp qq)}

relfile :: QuasiQuoter
relfile :: QuasiQuoter
relfile = QuasiQuoter -> QuasiQuoter
wrapPathQQ QuasiQuoter
P.relfile

absfile :: QuasiQuoter
absfile :: QuasiQuoter
absfile = QuasiQuoter -> QuasiQuoter
wrapPathQQ QuasiQuoter
P.absfile

reldir :: QuasiQuoter
reldir :: QuasiQuoter
reldir = QuasiQuoter -> QuasiQuoter
wrapPathQQ QuasiQuoter
P.reldir

absdir :: QuasiQuoter
absdir :: QuasiQuoter
absdir = QuasiQuoter -> QuasiQuoter
wrapPathQQ QuasiQuoter
P.absdir

toFilePath :: PathTo e b t -> FilePath
toFilePath :: forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> String
toFilePath = (Path Any Any -> String) -> PathTo e b t -> String
forall a b. Coercible a b => a -> b
coerce Path Any Any -> String
forall b t. Path b t -> String
P.toFilePath

fromAbsDir :: PathTo e Abs Dir -> FilePath
fromAbsDir :: forall {k} (e :: k). PathTo e Abs Dir -> String
fromAbsDir = Path Abs Dir -> String
P.fromAbsDir (Path Abs Dir -> String)
-> (PathTo e Abs Dir -> Path Abs Dir) -> PathTo e Abs Dir -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PathTo e Abs Dir -> Path Abs Dir
PathTo e Abs Dir -> Path (Untag Abs) Dir
forall {k} (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> Path (Untag pk) t
untagPath

fromRelDir :: PathTo e (RelTo b) Dir -> FilePath
fromRelDir :: forall {k} (e :: k) (b :: k). PathTo e (RelTo b) Dir -> String
fromRelDir = Path Rel Dir -> String
P.fromRelDir (Path Rel Dir -> String)
-> (PathTo e (RelTo b) Dir -> Path Rel Dir)
-> PathTo e (RelTo b) Dir
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PathTo e (RelTo b) Dir -> Path Rel Dir
PathTo e (RelTo b) Dir -> Path (Untag (RelTo b)) Dir
forall {k} (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> Path (Untag pk) t
untagPath

fromAbsFile :: PathTo e Abs File -> FilePath
fromAbsFile :: forall {k} (e :: k). PathTo e Abs File -> String
fromAbsFile = Path Abs File -> String
P.fromAbsFile (Path Abs File -> String)
-> (PathTo e Abs File -> Path Abs File)
-> PathTo e Abs File
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PathTo e Abs File -> Path Abs File
PathTo e Abs File -> Path (Untag Abs) File
forall {k} (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> Path (Untag pk) t
untagPath

fromRelFile :: PathTo e (RelTo b) File -> FilePath
fromRelFile :: forall {k} (e :: k) (b :: k). PathTo e (RelTo b) File -> String
fromRelFile = Path Rel File -> String
P.fromRelFile (Path Rel File -> String)
-> (PathTo e (RelTo b) File -> Path Rel File)
-> PathTo e (RelTo b) File
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PathTo e (RelTo b) File -> Path Rel File
PathTo e (RelTo b) File -> Path (Untag (RelTo b)) File
forall {k} (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> Path (Untag pk) t
untagPath

fromSomeDir :: SomeBase e b Dir -> FilePath
fromSomeDir :: forall {k} (e :: k) (b :: k). SomeBase e b Dir -> String
fromSomeDir = (forall (c :: Base k). PathTo e c Dir -> String)
-> SomeBase e b Dir -> String
forall {k} (e :: k) t a (b :: k).
(forall (c :: Base k). PathTo e c t -> a) -> SomeBase e b t -> a
prjSomeBase PathTo e c Dir -> String
forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> String
forall (c :: Base k). PathTo e c Dir -> String
toFilePath

fromSomeFile :: SomeBase e b File -> FilePath
fromSomeFile :: forall {k} (e :: k) (b :: k). SomeBase e b File -> String
fromSomeFile = (forall (c :: Base k). PathTo e c File -> String)
-> SomeBase e b File -> String
forall {k} (e :: k) t a (b :: k).
(forall (c :: Base k). PathTo e c t -> a) -> SomeBase e b t -> a
prjSomeBase PathTo e c File -> String
forall k (entity :: k) (pk :: Base k) t.
PathTo entity pk t -> String
forall (c :: Base k). PathTo e c File -> String
toFilePath

mkAbsDir :: FilePath -> ExpQ
mkAbsDir :: String -> ExpQ
mkAbsDir = (String -> ExpQ) -> String -> ExpQ
wrapE String -> ExpQ
mkAbsDir

mkRelDir :: FilePath -> ExpQ
mkRelDir :: String -> ExpQ
mkRelDir = (String -> ExpQ) -> String -> ExpQ
wrapE String -> ExpQ
mkRelDir

mkAbsFile :: FilePath -> ExpQ
mkAbsFile :: String -> ExpQ
mkAbsFile = (String -> ExpQ) -> String -> ExpQ
wrapE String -> ExpQ
mkAbsFile

mkRelFile :: FilePath -> ExpQ
mkRelFile :: String -> ExpQ
mkRelFile = (String -> ExpQ) -> String -> ExpQ
wrapE String -> ExpQ
mkRelFile

mkAbsDirT :: FilePath -> SpliceQ (PathTo e Abs Dir)
mkAbsDirT :: forall {k} (e :: k). String -> SpliceQ (PathTo e Abs Dir)
mkAbsDirT = ExpQ -> Splice Q (PathTo e Abs Dir)
forall a (m :: * -> *). Quote m => m Exp -> Splice m a
unsafeSpliceCoerce (ExpQ -> Splice Q (PathTo e Abs Dir))
-> (String -> ExpQ) -> String -> Splice Q (PathTo e Abs Dir)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ExpQ
mkAbsDir

mkRelDirT :: FilePath -> SpliceQ (PathTo e (RelTo b) Dir)
mkRelDirT :: forall {k} (e :: k) (b :: k).
String -> SpliceQ (PathTo e (RelTo b) Dir)
mkRelDirT = ExpQ -> Splice Q (PathTo e (RelTo b) Dir)
forall a (m :: * -> *). Quote m => m Exp -> Splice m a
unsafeSpliceCoerce (ExpQ -> Splice Q (PathTo e (RelTo b) Dir))
-> (String -> ExpQ) -> String -> Splice Q (PathTo e (RelTo b) Dir)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ExpQ
mkAbsDir

mkAbsFileT :: FilePath -> SpliceQ (PathTo e Abs File)
mkAbsFileT :: forall {k} (e :: k). String -> SpliceQ (PathTo e Abs File)
mkAbsFileT = ExpQ -> Splice Q (PathTo e Abs File)
forall a (m :: * -> *). Quote m => m Exp -> Splice m a
unsafeSpliceCoerce (ExpQ -> Splice Q (PathTo e Abs File))
-> (String -> ExpQ) -> String -> Splice Q (PathTo e Abs File)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ExpQ
mkAbsFile

mkRelFileT :: FilePath -> SpliceQ (PathTo e (RelTo b) File)
mkRelFileT :: forall {k} (e :: k) (b :: k).
String -> SpliceQ (PathTo e (RelTo b) File)
mkRelFileT = ExpQ -> Splice Q (PathTo e (RelTo b) File)
forall a (m :: * -> *). Quote m => m Exp -> Splice m a
unsafeSpliceCoerce (ExpQ -> Splice Q (PathTo e (RelTo b) File))
-> (String -> ExpQ) -> String -> Splice Q (PathTo e (RelTo b) File)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ExpQ
mkAbsFile