-----------------------------------------------------------------------------
-- |
-- Copyright   : (C) 2015 Dimitri Sabadie
-- License     : BSD3
--
-- Maintainer  : Dimitri Sabadie <dimitri.sabadie@gmail.com>
-- Stability   : experimental
-- Portability : portable
--
-----------------------------------------------------------------------------

module Codec.Wavefront.IO where

import Codec.Wavefront.Lexer ( lexer )
import Codec.Wavefront.Object ( WavefrontOBJ, ctxtToWavefrontOBJ )
import Codec.Wavefront.Token ( tokenize )
import Control.Monad.IO.Class ( MonadIO(..) )
import qualified Data.Text.IO as T ( readFile )

-- |Extract a 'WavefrontOBJ' from a Wavefront OBJ formatted file.
fromFile :: (MonadIO m) => FilePath -> m (Either String WavefrontOBJ)
fromFile :: forall (m :: * -> *).
MonadIO m =>
FilePath -> m (Either FilePath WavefrontOBJ)
fromFile FilePath
fd = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Ctxt -> WavefrontOBJ
ctxtToWavefrontOBJ forall b c a. (b -> c) -> (a -> b) -> a -> c
. TokenStream -> Ctxt
lexer) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either FilePath TokenStream
tokenize) (FilePath -> IO Text
T.readFile FilePath
fd)