ligo/tools/lsp/squirrel/src/Extension.hs

37 lines
713 B
Haskell
Raw Normal View History

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
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