41 lines
918 B
Haskell
41 lines
918 B
Haskell
{-# LANGUAGE ConstraintKinds #-}
|
|
module SJW.Source (
|
|
CodePath(..)
|
|
, Source(..)
|
|
, HasSource
|
|
, Path(..)
|
|
, source
|
|
) where
|
|
|
|
import Control.Monad.Reader (MonadReader)
|
|
import Data.List (intercalate)
|
|
import Text.ParserCombinators.ReadP (char, munch, sepBy)
|
|
import Text.ParserCombinators.ReadPrec (lift)
|
|
import Text.Read (readPrec)
|
|
|
|
newtype Path = Path [String] deriving (Eq, Ord)
|
|
newtype CodePath = CodePath [FilePath]
|
|
|
|
data Source = Source {
|
|
code :: CodePath
|
|
, mainModule :: Path
|
|
}
|
|
|
|
type HasSource = MonadReader Source
|
|
|
|
instance Show Path where
|
|
show (Path components) = intercalate "." components
|
|
|
|
instance Read Path where
|
|
readPrec = fmap Path . lift $
|
|
munch (/= '.') `sepBy` char '.'
|
|
|
|
instance Show CodePath where
|
|
show (CodePath dirs) = intercalate ":" dirs
|
|
|
|
source :: [String] -> Source
|
|
source paths = Source {
|
|
code = CodePath paths
|
|
, mainModule = Path ["Main"]
|
|
}
|