blob: 25cdec768812f495906950bd2a28faaa140de569 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}
module Collection where
import Miso.String (MisoString, toMisoString)
import Text.ParserCombinators.ReadP qualified as R
import Text.ParserCombinators.ReadPrec qualified as R
import Text.Read (Read (..))
newtype Collection = Collection {name :: MisoString}
deriving (Read, Eq, Show)
data CollectionItem = CollectionItem
{ collection :: Collection,
itemFileName :: FilePath
}
deriving (Eq)
instance Read CollectionItem where
readPrec = R.lift $ do
(Collection . toMisoString -> collection) <- R.munch (/= '/')
_ <- R.string "/"
itemFileName <- do
itemFileName <- R.munch (liftA2 (&&) (/= '.') (/= '/'))
fileExt <- R.string ".json"
pure (itemFileName <> fileExt)
pure CollectionItem {..}
instance Show CollectionItem where
show (CollectionItem {collection = Collection cn, itemFileName}) =
show (cn <> "/" <> toMisoString itemFileName)
|