module Context ( CodePath(..) , Context(..) , Contextual , Path(..) ) where import Control.Monad.RWS (RWST) import Data.List (intercalate) import Data.Map (Map) import Text.ParserCombinators.ReadP (char, munch, sepBy) import Text.ParserCombinators.ReadPrec (lift) import Text.Read (readPrec) newtype Path = Path [String] newtype CodePath = CodePath [FilePath] type Dependencies = Map Path [Path] data Context = Context { codePaths :: CodePath , mainModule :: Path } type Contextual = RWST Context [String] Dependencies IO 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