2020-08-14 15:40:30 +04:00
|
|
|
|
|
|
|
module Extension where
|
|
|
|
|
|
|
|
import Control.Monad.Catch
|
|
|
|
|
|
|
|
import System.FilePath
|
|
|
|
|
|
|
|
data Ext
|
|
|
|
= Pascal
|
|
|
|
| Caml
|
|
|
|
| Reason
|
|
|
|
|
|
|
|
data ElimExt a = ElimExt
|
|
|
|
{ eePascal :: a
|
|
|
|
, eeCaml :: a
|
|
|
|
, eeReason :: a
|
|
|
|
}
|
|
|
|
|
|
|
|
data UnsupportedExtension = UnsupportedExtension String
|
|
|
|
deriving stock Show
|
|
|
|
deriving anyclass Exception
|
|
|
|
|
|
|
|
getExt :: MonadThrow m => FilePath -> m Ext
|
|
|
|
getExt path = do
|
|
|
|
case takeExtension path of
|
2020-08-17 16:29:42 +04:00
|
|
|
".religo" -> return Reason
|
|
|
|
".ligo" -> return Pascal
|
|
|
|
".mligo" -> return Caml
|
2020-08-14 15:40:30 +04:00
|
|
|
ext -> throwM $ UnsupportedExtension ext
|
|
|
|
|
|
|
|
onExt :: ElimExt a -> FilePath -> IO a
|
|
|
|
onExt ee path = do
|
|
|
|
getExt path >>= return . \case
|
|
|
|
Pascal -> eePascal ee
|
|
|
|
Caml -> eeCaml ee
|
|
|
|
Reason -> eeReason ee
|