1
1
mirror of https://github.com/github/semantic.git synced 2024-11-30 14:47:30 +03:00

s/TranslationException/TranslationError

This commit is contained in:
Timothy Clem 2018-08-27 14:51:39 -07:00
parent ae82756f59
commit 9c673e2fcb
5 changed files with 15 additions and 15 deletions

View File

@ -1,10 +1,10 @@
module Data.Reprinting.Errors ( TranslationException (..) ) where
module Data.Reprinting.Errors ( TranslationError (..) ) where
import Data.Reprinting.Token
-- | Represents failure occurring in a 'Concrete' machine during the translation
-- phases of the reprinting pipeline.
data TranslationException
data TranslationError
= UnbalancedPair Context [Context]
-- ^ Thrown if an unbalanced 'Enter'/'Exit' pair is encountered.
| NoTranslation Element [Context]

View File

@ -17,7 +17,7 @@ import Data.Reprinting.Splice
import Data.Reprinting.Token
-- | Default printing pipeline for JSON.
defaultJSONPipeline :: (Member (Exc TranslationException) effs)
defaultJSONPipeline :: (Member (Exc TranslationError) effs)
=> ProcessT (Eff effs) Fragment Splice
defaultJSONPipeline
= printingJSON
@ -56,7 +56,7 @@ defaultBeautyOpts :: JSONBeautyOpts
defaultBeautyOpts = JSONBeautyOpts 2 False
-- | Produce JSON with configurable whitespace and layout.
beautifyingJSON :: (Member (Exc TranslationException) effs)
beautifyingJSON :: (Member (Exc TranslationError) effs)
=> JSONBeautyOpts -> ProcessT (Eff effs) Fragment Splice
beautifyingJSON _ = flattened <~ autoT (Kleisli step) where
step (Defer el cs) = throwError (NoTranslation el cs)
@ -70,7 +70,7 @@ beautifyingJSON _ = flattened <~ autoT (Kleisli step) where
_ -> emit txt
-- | Produce whitespace minimal JSON.
minimizingJSON :: (Member (Exc TranslationException) effs)
minimizingJSON :: (Member (Exc TranslationError) effs)
=> ProcessT (Eff effs) Fragment Splice
minimizingJSON = flattened <~ autoT (Kleisli step) where
step (Defer el cs) = throwError (NoTranslation el cs)

View File

@ -11,10 +11,10 @@ import Data.Reprinting.Splice
import Data.Reprinting.Token as Token
-- | Print Ruby syntax.
printingRuby :: (Member (Exc TranslationException) effs) => ProcessT (Eff effs) Fragment Splice
printingRuby :: (Member (Exc TranslationError) effs) => ProcessT (Eff effs) Fragment Splice
printingRuby = flattened <~ autoT (Kleisli step)
step :: (Member (Exc TranslationException) effs) => Fragment -> Eff effs (Seq Splice)
step :: (Member (Exc TranslationError) effs) => Fragment -> Eff effs (Seq Splice)
step (Verbatim txt) = pure $ emit txt
step (New _ _ txt) = pure $ emit txt
step (Defer el cs) = case (el, cs) of
@ -53,9 +53,9 @@ step (Defer el cs) = case (el, cs) of
endContext times = layout HardWrap <> indent (pred times)
-- Example of what writing a plan style machine looks like
-- printingRuby' :: (Member (Exc TranslationException) effs) => MachineT (Eff effs) (Is Fragment) Splice
-- printingRuby' :: (Member (Exc TranslationError) effs) => MachineT (Eff effs) (Is Fragment) Splice
-- printingRuby' = flattened <~ repeatedly plan where
-- plan :: (Member (Exc TranslationException) effs) => PlanT (Is Fragment) (Seq Splice) (Eff effs) ()
-- plan :: (Member (Exc TranslationError) effs) => PlanT (Is Fragment) (Seq Splice) (Eff effs) ()
-- plan = do
-- frag <- await
-- x <- lift (step frag)

View File

@ -130,7 +130,7 @@ runReprinter ::
=> Source.Source
-> ProcessT Translator Fragment Splice
-> Term a (Record fields)
-> Either TranslationException Source.Source
-> Either TranslationError Source.Source
runReprinter src translating tree
= fmap go
. Effect.run
@ -163,7 +163,7 @@ runContextualizing ::
)
=> Source.Source
-> Term a (Record fields)
-> Either TranslationException [Fragment]
-> Either TranslationError [Fragment]
runContextualizing src tree
= Effect.run
. Exc.runError
@ -180,7 +180,7 @@ runTranslating ::
=> Source.Source
-> ProcessT Translator Fragment Splice
-> Term a (Record fields)
-> Either TranslationException [Splice]
-> Either TranslationError [Splice]
runTranslating src translating tree
= Effect.run
. Exc.runError

View File

@ -18,13 +18,13 @@ import Data.Reprinting.Token
import Data.Reprinting.Errors
import qualified Data.Source as Source
type Translator = Eff '[State [Context], Exc TranslationException]
type Translator = Eff '[State [Context], Exc TranslationError]
-- | Prepare for language specific translation by contextualizing 'Token's to
-- 'Fragment's.
contextualizing ::
( Member (State [Context]) effs
, Member (Exc TranslationException) effs
, Member (Exc TranslationError) effs
)
=> ProcessT (Eff effs) Token Fragment
contextualizing = flattened <~ autoT (Kleisli step) where
@ -45,7 +45,7 @@ contextualizing = flattened <~ autoT (Kleisli step) where
exitContext ::
( Member (State [Context]) effs
, Member (Exc TranslationException) effs
, Member (Exc TranslationError) effs
)
=> Context -> Eff effs ()
exitContext c = do