module Cabal.Package (
readPackage,
parsePackage,
) where
import Control.Exception (throwIO)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import qualified Distribution.Fields as C
import qualified Distribution.PackageDescription as C
import qualified Distribution.PackageDescription.Parsec as C
import Cabal.Parse
readPackage :: FilePath -> IO C.GenericPackageDescription
readPackage fp = do
contents <- BS.readFile fp
either throwIO return (parsePackage fp contents)
parsePackage :: FilePath -> ByteString -> Either ParseError C.GenericPackageDescription
parsePackage fp contents = case C.runParseResult $ C.parseGenericPackageDescription contents of
(ws, Left (_mv, errs)) -> Left $ ParseError fp contents errs ws
(_, Right gpd) -> Right gpd