1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 06:41:45 +03:00

Define serialization tasks.

This commit is contained in:
Rob Rix 2018-05-11 14:13:17 -04:00
parent 456171a931
commit e8ccc67de8

View File

@ -22,6 +22,7 @@ module Semantic.Task
, decorate , decorate
, diff , diff
, render , render
, serialize
-- * Concurrency -- * Concurrency
, distribute , distribute
, distributeFor , distributeFor
@ -52,6 +53,7 @@ import Control.Monad.Effect.Exception
import Control.Monad.Effect.Reader import Control.Monad.Effect.Reader
import Control.Monad.Effect.Trace import Control.Monad.Effect.Trace
import Data.Blob import Data.Blob
import Data.ByteString.Builder
import Data.Diff import Data.Diff
import qualified Data.Error as Error import qualified Data.Error as Error
import Data.Record import Data.Record
@ -67,6 +69,7 @@ import Semantic.Log
import Semantic.Queue import Semantic.Queue
import Semantic.Stat as Stat import Semantic.Stat as Stat
import Semantic.Telemetry import Semantic.Telemetry
import Serializing.Format
import System.Exit (die) import System.Exit (die)
import System.IO (stderr) import System.IO (stderr)
@ -110,6 +113,9 @@ diff differ term1 term2 = send (Semantic.Task.Diff differ term1 term2)
render :: Member Task effs => Renderer input output -> input -> Eff effs output render :: Member Task effs => Renderer input output -> input -> Eff effs output
render renderer = send . Render renderer render renderer = send . Render renderer
serialize :: Member Task effs => Format input -> input -> Eff effs Builder
serialize format = send . Serialize format
-- | Execute a 'Task' with the 'defaultOptions', yielding its result value in 'IO'. -- | Execute a 'Task' with the 'defaultOptions', yielding its result value in 'IO'.
-- --
-- > runTask = runTaskWithOptions defaultOptions -- > runTask = runTaskWithOptions defaultOptions
@ -145,6 +151,7 @@ data Task output where
Decorate :: Functor f => RAlgebra (TermF f (Record fields)) (Term f (Record fields)) field -> Term f (Record fields) -> Task (Term f (Record (field ': fields))) Decorate :: Functor f => RAlgebra (TermF f (Record fields)) (Term f (Record fields)) field -> Term f (Record fields) -> Task (Term f (Record (field ': fields)))
Diff :: Differ syntax ann1 ann2 -> Term syntax ann1 -> Term syntax ann2 -> Task (Diff syntax ann1 ann2) Diff :: Differ syntax ann1 ann2 -> Term syntax ann1 -> Term syntax ann2 -> Task (Diff syntax ann1 ann2)
Render :: Renderer input output -> input -> Task output Render :: Renderer input output -> input -> Task output
Serialize :: Format input -> input -> Task Builder
-- | Run a 'Task' effect by performing the actions in 'IO'. -- | Run a 'Task' effect by performing the actions in 'IO'.
runTaskF :: Members '[Reader Options, Telemetry, Exc SomeException, Trace, IO] effs => Eff (Task ': effs) a -> Eff effs a runTaskF :: Members '[Reader Options, Telemetry, Exc SomeException, Trace, IO] effs => Eff (Task ': effs) a -> Eff effs a
@ -154,6 +161,7 @@ runTaskF = interpret $ \ task -> case task of
Decorate algebra term -> pure (decoratorWithAlgebra algebra term) Decorate algebra term -> pure (decoratorWithAlgebra algebra term)
Semantic.Task.Diff differ term1 term2 -> pure (differ term1 term2) Semantic.Task.Diff differ term1 term2 -> pure (differ term1 term2)
Render renderer input -> pure (renderer input) Render renderer input -> pure (renderer input)
Serialize format input -> pure (runSerialize format input)
-- | Log an 'Error.Error' at the specified 'Level'. -- | Log an 'Error.Error' at the specified 'Level'.