module Unison.Codebase.ProjectPath
  ( ProjectPathG (..),
    ProjectPathIds,
    ProjectPathNames,
    ProjectPath,
    fromProjectAndBranch,
    projectBranchRoot,
    toRoot,
    absPath_,
    path_,
    path,
    toProjectAndBranch,
    projectAndBranch_,
    toText,
    toIds,
    toNames,
    projectPathParser,
    parseProjectPath,

    -- * Re-exports, this also helps with using dot-notation
    ProjectAndBranch (..),
    Project (..),
    ProjectBranch (..),
  )
where

import Control.Lens hiding (from)
import Data.Bifoldable (Bifoldable (..))
import Data.Bitraversable (Bitraversable (..))
import Data.Text qualified as Text
import Text.Megaparsec qualified as Megaparsec
import Text.Megaparsec.Char qualified as Megaparsec
import U.Codebase.Sqlite.DbId (ProjectBranchId, ProjectId)
import U.Codebase.Sqlite.Project (Project (..))
import U.Codebase.Sqlite.ProjectBranch (ProjectBranch (..))
import Unison.Codebase.Path qualified as Path
import Unison.Codebase.Path.Parse qualified as Path
import Unison.Prelude
import Unison.Project (ProjectAndBranch (..), ProjectBranchName, ProjectName)
import Unison.Project qualified as Project

data ProjectPathG proj branch = ProjectPath
  { forall proj branch. ProjectPathG proj branch -> proj
project :: proj,
    forall proj branch. ProjectPathG proj branch -> branch
branch :: branch,
    forall proj branch. ProjectPathG proj branch -> Absolute
absPath :: Path.Absolute
  }
  deriving stock (ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
(ProjectPathG proj branch -> ProjectPathG proj branch -> Bool)
-> (ProjectPathG proj branch -> ProjectPathG proj branch -> Bool)
-> Eq (ProjectPathG proj branch)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall proj branch.
(Eq proj, Eq branch) =>
ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
$c== :: forall proj branch.
(Eq proj, Eq branch) =>
ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
== :: ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
$c/= :: forall proj branch.
(Eq proj, Eq branch) =>
ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
/= :: ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
Eq, (forall a b.
 (a -> b) -> ProjectPathG proj a -> ProjectPathG proj b)
-> (forall a b. a -> ProjectPathG proj b -> ProjectPathG proj a)
-> Functor (ProjectPathG proj)
forall a b. a -> ProjectPathG proj b -> ProjectPathG proj a
forall a b. (a -> b) -> ProjectPathG proj a -> ProjectPathG proj b
forall proj a b. a -> ProjectPathG proj b -> ProjectPathG proj a
forall proj a b.
(a -> b) -> ProjectPathG proj a -> ProjectPathG proj b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall proj a b.
(a -> b) -> ProjectPathG proj a -> ProjectPathG proj b
fmap :: forall a b. (a -> b) -> ProjectPathG proj a -> ProjectPathG proj b
$c<$ :: forall proj a b. a -> ProjectPathG proj b -> ProjectPathG proj a
<$ :: forall a b. a -> ProjectPathG proj b -> ProjectPathG proj a
Functor, Eq (ProjectPathG proj branch)
Eq (ProjectPathG proj branch) =>
(ProjectPathG proj branch -> ProjectPathG proj branch -> Ordering)
-> (ProjectPathG proj branch -> ProjectPathG proj branch -> Bool)
-> (ProjectPathG proj branch -> ProjectPathG proj branch -> Bool)
-> (ProjectPathG proj branch -> ProjectPathG proj branch -> Bool)
-> (ProjectPathG proj branch -> ProjectPathG proj branch -> Bool)
-> (ProjectPathG proj branch
    -> ProjectPathG proj branch -> ProjectPathG proj branch)
-> (ProjectPathG proj branch
    -> ProjectPathG proj branch -> ProjectPathG proj branch)
-> Ord (ProjectPathG proj branch)
ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
ProjectPathG proj branch -> ProjectPathG proj branch -> Ordering
ProjectPathG proj branch
-> ProjectPathG proj branch -> ProjectPathG proj branch
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 proj branch.
(Ord proj, Ord branch) =>
Eq (ProjectPathG proj branch)
forall proj branch.
(Ord proj, Ord branch) =>
ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
forall proj branch.
(Ord proj, Ord branch) =>
ProjectPathG proj branch -> ProjectPathG proj branch -> Ordering
forall proj branch.
(Ord proj, Ord branch) =>
ProjectPathG proj branch
-> ProjectPathG proj branch -> ProjectPathG proj branch
$ccompare :: forall proj branch.
(Ord proj, Ord branch) =>
ProjectPathG proj branch -> ProjectPathG proj branch -> Ordering
compare :: ProjectPathG proj branch -> ProjectPathG proj branch -> Ordering
$c< :: forall proj branch.
(Ord proj, Ord branch) =>
ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
< :: ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
$c<= :: forall proj branch.
(Ord proj, Ord branch) =>
ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
<= :: ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
$c> :: forall proj branch.
(Ord proj, Ord branch) =>
ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
> :: ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
$c>= :: forall proj branch.
(Ord proj, Ord branch) =>
ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
>= :: ProjectPathG proj branch -> ProjectPathG proj branch -> Bool
$cmax :: forall proj branch.
(Ord proj, Ord branch) =>
ProjectPathG proj branch
-> ProjectPathG proj branch -> ProjectPathG proj branch
max :: ProjectPathG proj branch
-> ProjectPathG proj branch -> ProjectPathG proj branch
$cmin :: forall proj branch.
(Ord proj, Ord branch) =>
ProjectPathG proj branch
-> ProjectPathG proj branch -> ProjectPathG proj branch
min :: ProjectPathG proj branch
-> ProjectPathG proj branch -> ProjectPathG proj branch
Ord, Int -> ProjectPathG proj branch -> ShowS
[ProjectPathG proj branch] -> ShowS
ProjectPathG proj branch -> String
(Int -> ProjectPathG proj branch -> ShowS)
-> (ProjectPathG proj branch -> String)
-> ([ProjectPathG proj branch] -> ShowS)
-> Show (ProjectPathG proj branch)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall proj branch.
(Show proj, Show branch) =>
Int -> ProjectPathG proj branch -> ShowS
forall proj branch.
(Show proj, Show branch) =>
[ProjectPathG proj branch] -> ShowS
forall proj branch.
(Show proj, Show branch) =>
ProjectPathG proj branch -> String
$cshowsPrec :: forall proj branch.
(Show proj, Show branch) =>
Int -> ProjectPathG proj branch -> ShowS
showsPrec :: Int -> ProjectPathG proj branch -> ShowS
$cshow :: forall proj branch.
(Show proj, Show branch) =>
ProjectPathG proj branch -> String
show :: ProjectPathG proj branch -> String
$cshowList :: forall proj branch.
(Show proj, Show branch) =>
[ProjectPathG proj branch] -> ShowS
showList :: [ProjectPathG proj branch] -> ShowS
Show, (forall x.
 ProjectPathG proj branch -> Rep (ProjectPathG proj branch) x)
-> (forall x.
    Rep (ProjectPathG proj branch) x -> ProjectPathG proj branch)
-> Generic (ProjectPathG proj branch)
forall x.
Rep (ProjectPathG proj branch) x -> ProjectPathG proj branch
forall x.
ProjectPathG proj branch -> Rep (ProjectPathG proj branch) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall proj branch x.
Rep (ProjectPathG proj branch) x -> ProjectPathG proj branch
forall proj branch x.
ProjectPathG proj branch -> Rep (ProjectPathG proj branch) x
$cfrom :: forall proj branch x.
ProjectPathG proj branch -> Rep (ProjectPathG proj branch) x
from :: forall x.
ProjectPathG proj branch -> Rep (ProjectPathG proj branch) x
$cto :: forall proj branch x.
Rep (ProjectPathG proj branch) x -> ProjectPathG proj branch
to :: forall x.
Rep (ProjectPathG proj branch) x -> ProjectPathG proj branch
Generic)

type ProjectPathIds = ProjectPathG ProjectId ProjectBranchId

type ProjectPathNames = ProjectPathG ProjectName ProjectBranchName

instance From ProjectPath Text where
  from :: ProjectPath -> Text
from = ProjectPathNames -> Text
forall source target. From source target => source -> target
from (ProjectPathNames -> Text)
-> (ProjectPath -> ProjectPathNames) -> ProjectPath -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProjectPath -> ProjectPathNames
toNames

instance From ProjectPathNames Text where
  from :: ProjectPathNames -> Text
from (ProjectPath ProjectName
proj ProjectBranchName
branch (Path.Absolute Path
path)) =
    forall target source. From source target => source -> target
into @Text (ProjectName
-> ProjectBranchName
-> ProjectAndBranch ProjectName ProjectBranchName
forall a b. a -> b -> ProjectAndBranch a b
ProjectAndBranch ProjectName
proj ProjectBranchName
branch) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Path -> Text
Path.toText Path
path

instance From (ProjectPathG () ProjectBranchName) Text where
  from :: ProjectPathG () ProjectBranchName -> Text
from (ProjectPath () ProjectBranchName
branch (Path.Absolute Path
path)) =
    Text
"/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> forall target source. From source target => source -> target
into @Text ProjectBranchName
branch Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Path -> Text
Path.toText Path
path

type ProjectPath = ProjectPathG Project ProjectBranch

projectBranchRoot :: ProjectAndBranch Project ProjectBranch -> ProjectPath
projectBranchRoot :: ProjectAndBranch Project ProjectBranch -> ProjectPath
projectBranchRoot (ProjectAndBranch Project
proj ProjectBranch
branch) = Project -> ProjectBranch -> Absolute -> ProjectPath
forall proj branch.
proj -> branch -> Absolute -> ProjectPathG proj branch
ProjectPath Project
proj ProjectBranch
branch Absolute
Path.absoluteEmpty

-- | Discard any path within the project and get the project's root
toRoot :: ProjectPath -> ProjectPath
toRoot :: ProjectPath -> ProjectPath
toRoot (ProjectPath Project
proj ProjectBranch
branch Absolute
_) = Project -> ProjectBranch -> Absolute -> ProjectPath
forall proj branch.
proj -> branch -> Absolute -> ProjectPathG proj branch
ProjectPath Project
proj ProjectBranch
branch Absolute
Path.absoluteEmpty

fromProjectAndBranch :: ProjectAndBranch Project ProjectBranch -> Path.Absolute -> ProjectPath
fromProjectAndBranch :: ProjectAndBranch Project ProjectBranch -> Absolute -> ProjectPath
fromProjectAndBranch (ProjectAndBranch Project
proj ProjectBranch
branch) Absolute
path = Project -> ProjectBranch -> Absolute -> ProjectPath
forall proj branch.
proj -> branch -> Absolute -> ProjectPathG proj branch
ProjectPath Project
proj ProjectBranch
branch Absolute
path

-- | Project a project context into a project path of just IDs
toIds :: ProjectPath -> ProjectPathIds
toIds :: ProjectPath -> ProjectPathIds
toIds (ProjectPath Project
proj ProjectBranch
branch Absolute
path) = ProjectId -> ProjectBranchId -> Absolute -> ProjectPathIds
forall proj branch.
proj -> branch -> Absolute -> ProjectPathG proj branch
ProjectPath (Project
proj Project -> Getting ProjectId Project ProjectId -> ProjectId
forall s a. s -> Getting a s a -> a
^. Getting ProjectId Project ProjectId
#projectId) (ProjectBranch
branch ProjectBranch
-> Getting ProjectBranchId ProjectBranch ProjectBranchId
-> ProjectBranchId
forall s a. s -> Getting a s a -> a
^. Getting ProjectBranchId ProjectBranch ProjectBranchId
#branchId) Absolute
path

-- | Project a project context into a project path of just names
toNames :: ProjectPath -> ProjectPathNames
toNames :: ProjectPath -> ProjectPathNames
toNames (ProjectPath Project
proj ProjectBranch
branch Absolute
path) = ProjectName -> ProjectBranchName -> Absolute -> ProjectPathNames
forall proj branch.
proj -> branch -> Absolute -> ProjectPathG proj branch
ProjectPath (Project
proj Project -> Getting ProjectName Project ProjectName -> ProjectName
forall s a. s -> Getting a s a -> a
^. Getting ProjectName Project ProjectName
#name) (ProjectBranch
branch ProjectBranch
-> Getting ProjectBranchName ProjectBranch ProjectBranchName
-> ProjectBranchName
forall s a. s -> Getting a s a -> a
^. Getting ProjectBranchName ProjectBranch ProjectBranchName
#name) Absolute
path

toProjectAndBranch :: ProjectPathG p b -> ProjectAndBranch p b
toProjectAndBranch :: forall p b. ProjectPathG p b -> ProjectAndBranch p b
toProjectAndBranch (ProjectPath p
proj b
branch Absolute
_) = p -> b -> ProjectAndBranch p b
forall a b. a -> b -> ProjectAndBranch a b
ProjectAndBranch p
proj b
branch

instance Bifunctor ProjectPathG where
  bimap :: forall a b c d.
(a -> b) -> (c -> d) -> ProjectPathG a c -> ProjectPathG b d
bimap a -> b
f c -> d
g (ProjectPath a
p c
b Absolute
path) = b -> d -> Absolute -> ProjectPathG b d
forall proj branch.
proj -> branch -> Absolute -> ProjectPathG proj branch
ProjectPath (a -> b
f a
p) (c -> d
g c
b) Absolute
path

instance Bifoldable ProjectPathG where
  bifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> ProjectPathG a b -> m
bifoldMap a -> m
f b -> m
g (ProjectPath a
p b
b Absolute
_) = a -> m
f a
p m -> m -> m
forall a. Semigroup a => a -> a -> a
<> b -> m
g b
b

instance Bitraversable ProjectPathG where
  bitraverse :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c)
-> (b -> f d) -> ProjectPathG a b -> f (ProjectPathG c d)
bitraverse a -> f c
f b -> f d
g (ProjectPath a
p b
b Absolute
path) = c -> d -> Absolute -> ProjectPathG c d
forall proj branch.
proj -> branch -> Absolute -> ProjectPathG proj branch
ProjectPath (c -> d -> Absolute -> ProjectPathG c d)
-> f c -> f (d -> Absolute -> ProjectPathG c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f c
f a
p f (d -> Absolute -> ProjectPathG c d)
-> f d -> f (Absolute -> ProjectPathG c d)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> f d
g b
b f (Absolute -> ProjectPathG c d)
-> f Absolute -> f (ProjectPathG c d)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Absolute -> f Absolute
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Absolute
path

toText :: ProjectPathG Project ProjectBranch -> Text
toText :: ProjectPath -> Text
toText (ProjectPath Project
proj ProjectBranch
branch Absolute
path) =
  forall target source. From source target => source -> target
into @Text (Project
proj Project -> Getting ProjectName Project ProjectName -> ProjectName
forall s a. s -> Getting a s a -> a
^. Getting ProjectName Project ProjectName
#name) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> forall target source. From source target => source -> target
into @Text (ProjectBranch
branch ProjectBranch
-> Getting ProjectBranchName ProjectBranch ProjectBranchName
-> ProjectBranchName
forall s a. s -> Getting a s a -> a
^. Getting ProjectBranchName ProjectBranch ProjectBranchName
#name) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Absolute -> Text
Path.absToText Absolute
path

absPath_ :: Lens' (ProjectPathG p b) Path.Absolute
absPath_ :: forall p b (f :: * -> *).
Functor f =>
(Absolute -> f Absolute)
-> ProjectPathG p b -> f (ProjectPathG p b)
absPath_ = (ProjectPathG p b -> Absolute)
-> (ProjectPathG p b -> Absolute -> ProjectPathG p b)
-> Lens (ProjectPathG p b) (ProjectPathG p b) Absolute Absolute
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens ProjectPathG p b -> Absolute
forall proj branch. ProjectPathG proj branch -> Absolute
absPath ProjectPathG p b -> Absolute -> ProjectPathG p b
forall {proj} {branch}.
ProjectPathG proj branch -> Absolute -> ProjectPathG proj branch
set
  where
    set :: ProjectPathG proj branch -> Absolute -> ProjectPathG proj branch
set (ProjectPath proj
n branch
b Absolute
_) Absolute
p = proj -> branch -> Absolute -> ProjectPathG proj branch
forall proj branch.
proj -> branch -> Absolute -> ProjectPathG proj branch
ProjectPath proj
n branch
b Absolute
p

path :: (ProjectPathG p b) -> Path.Path
path :: forall p b. ProjectPathG p b -> Path
path (ProjectPath p
_ b
_ Absolute
p) = Absolute -> Path
Path.unabsolute Absolute
p

path_ :: Lens' (ProjectPathG p b) Path.Path
path_ :: forall p b (f :: * -> *).
Functor f =>
(Path -> f Path) -> ProjectPathG p b -> f (ProjectPathG p b)
path_ = (Absolute -> f Absolute)
-> ProjectPathG p b -> f (ProjectPathG p b)
forall p b (f :: * -> *).
Functor f =>
(Absolute -> f Absolute)
-> ProjectPathG p b -> f (ProjectPathG p b)
absPath_ ((Absolute -> f Absolute)
 -> ProjectPathG p b -> f (ProjectPathG p b))
-> ((Path -> f Path) -> Absolute -> f Absolute)
-> (Path -> f Path)
-> ProjectPathG p b
-> f (ProjectPathG p b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Path -> f Path) -> Absolute -> f Absolute
Lens' Absolute Path
Path.absPath_

projectAndBranch_ :: Lens (ProjectPathG p b) (ProjectPathG p' b') (ProjectAndBranch p b) (ProjectAndBranch p' b')
projectAndBranch_ :: forall p b p' b' (f :: * -> *).
Functor f =>
(ProjectAndBranch p b -> f (ProjectAndBranch p' b'))
-> ProjectPathG p b -> f (ProjectPathG p' b')
projectAndBranch_ = (ProjectPathG p b -> ProjectAndBranch p b)
-> (ProjectPathG p b
    -> ProjectAndBranch p' b' -> ProjectPathG p' b')
-> Lens
     (ProjectPathG p b)
     (ProjectPathG p' b')
     (ProjectAndBranch p b)
     (ProjectAndBranch p' b')
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens ProjectPathG p b -> ProjectAndBranch p b
forall p b. ProjectPathG p b -> ProjectAndBranch p b
go ProjectPathG p b -> ProjectAndBranch p' b' -> ProjectPathG p' b'
forall {proj} {branch} {proj} {branch}.
ProjectPathG proj branch
-> ProjectAndBranch proj branch -> ProjectPathG proj branch
set
  where
    go :: ProjectPathG a b -> ProjectAndBranch a b
go (ProjectPath a
proj b
branch Absolute
_) = a -> b -> ProjectAndBranch a b
forall a b. a -> b -> ProjectAndBranch a b
ProjectAndBranch a
proj b
branch
    set :: ProjectPathG proj branch
-> ProjectAndBranch proj branch -> ProjectPathG proj branch
set (ProjectPath proj
_ branch
_ Absolute
p) (ProjectAndBranch proj
proj branch
branch) = proj -> branch -> Absolute -> ProjectPathG proj branch
forall proj branch.
proj -> branch -> Absolute -> ProjectPathG proj branch
ProjectPath proj
proj branch
branch Absolute
p

type Parser = Megaparsec.Parsec Void Text

projectPathParser :: Parser ProjectPathNames
projectPathParser :: Parser ProjectPathNames
projectPathParser = do
  (ProjectName
projName, Bool
hasTrailingSlash) <- Parsec Void Text (ProjectName, Bool)
Project.projectNameParser
  ProjectBranchName
projBranchName <- Bool -> Parsec Void Text ProjectBranchName
Project.projectBranchNameParser (Bool -> Bool
not Bool
hasTrailingSlash)
  Char
_ <- Token Text -> ParsecT Void Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
Megaparsec.char Char
Token Text
':'
  Parser Path'
path' Parser Path'
-> (Path' -> Parser ProjectPathNames) -> Parser ProjectPathNames
forall a b.
ParsecT Void Text Identity a
-> (a -> ParsecT Void Text Identity b)
-> ParsecT Void Text Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    Path.AbsolutePath' Absolute
p -> ProjectPathNames -> Parser ProjectPathNames
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ProjectPathNames -> Parser ProjectPathNames)
-> ProjectPathNames -> Parser ProjectPathNames
forall a b. (a -> b) -> a -> b
$ ProjectName -> ProjectBranchName -> Absolute -> ProjectPathNames
forall proj branch.
proj -> branch -> Absolute -> ProjectPathG proj branch
ProjectPath ProjectName
projName ProjectBranchName
projBranchName Absolute
p
    Path.RelativePath' {} -> String -> Parser ProjectPathNames
forall a. String -> ParsecT Void Text Identity a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Expected an absolute path"
  where
    path' :: Parser Path.Path'
    path' :: Parser Path'
path' = do
      Text
pathStr <- ParsecT Void Text Identity Text
ParsecT Void Text Identity (Tokens Text)
forall e s (m :: * -> *). MonadParsec e s m => m (Tokens s)
Megaparsec.takeRest
      case String -> Either Text Path'
Path.parsePath' (Text -> String
Text.unpack Text
pathStr) of
        Left Text
err -> String -> Parser Path'
forall a. String -> ParsecT Void Text Identity a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (Text -> String
Text.unpack Text
err)
        Right Path'
x -> Path' -> Parser Path'
forall a. a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Path'
x

parseProjectPath :: Text -> Either Text ProjectPathNames
parseProjectPath :: Text -> Either Text ProjectPathNames
parseProjectPath Text
txt = (ParseErrorBundle Text Void -> Text)
-> Either (ParseErrorBundle Text Void) ProjectPathNames
-> Either Text ProjectPathNames
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (String -> Text
Text.pack (String -> Text)
-> (ParseErrorBundle Text Void -> String)
-> ParseErrorBundle Text Void
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseErrorBundle Text Void -> String
forall s e.
(VisualStream s, TraversableStream s, ShowErrorComponent e) =>
ParseErrorBundle s e -> String
Megaparsec.errorBundlePretty) (Either (ParseErrorBundle Text Void) ProjectPathNames
 -> Either Text ProjectPathNames)
-> Either (ParseErrorBundle Text Void) ProjectPathNames
-> Either Text ProjectPathNames
forall a b. (a -> b) -> a -> b
$ Parser ProjectPathNames
-> String
-> Text
-> Either (ParseErrorBundle Text Void) ProjectPathNames
forall e s a.
Parsec e s a -> String -> s -> Either (ParseErrorBundle s e) a
Megaparsec.parse Parser ProjectPathNames
projectPathParser String
"" Text
txt