Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 40e5adf

Browse files
author
Patrick Thomson
committed
Further simplifications.
1 parent 17407c0 commit 40e5adf

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

src/Reprinting/Pipeline.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ import Reprinting.Typeset
126126
-- translation function (as a function over 'Stream's) and the provided 'Term'.
127127
runReprinter :: Tokenize a
128128
=> Source.Source
129-
-> (Stream (Of Fragment) _ () -> Stream (Of Splice) _ ())
129+
-> (Stream (Of Fragment) TranslatorC () -> Stream (Of Splice) TranslatorC ())
130130
-> Term a History
131131
-> Either TranslationError Source.Source
132132
runReprinter src translating
@@ -153,9 +153,9 @@ runTokenizing src
153153

154154
-- | Run the reprinting pipeline up to contextualizing.
155155
runContextualizing :: Tokenize a
156-
=> Source.Source
157-
-> Term a History
158-
-> Either TranslationError [Fragment]
156+
=> Source.Source
157+
-> Term a History
158+
-> Either TranslationError [Fragment]
159159
runContextualizing src
160160
= Effect.run
161161
. Effect.runError
@@ -165,10 +165,10 @@ runContextualizing src
165165
. tokenizing src
166166

167167
runTranslating :: Tokenize a
168-
=> Source.Source
169-
-> (Stream (Of Fragment) _ () -> Stream (Of Splice) _ ())
170-
-> Term a History
171-
-> Either TranslationError [Splice]
168+
=> Source.Source
169+
-> (Stream (Of Fragment) TranslatorC () -> Stream (Of Splice) TranslatorC ())
170+
-> Term a History
171+
-> Either TranslationError [Splice]
172172
runTranslating src translating
173173
= Effect.run
174174
. Effect.runError

src/Reprinting/Translate.hs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{-# LANGUAGE LambdaCase #-}
22

33
module Reprinting.Translate
4-
( Translator
5-
, contextualizing
4+
( contextualizing
5+
, TranslatorC
66
) where
77

88
import Control.Effect
@@ -20,25 +20,33 @@ import Data.Reprinting.Splice
2020
import Data.Reprinting.Token
2121
import qualified Data.Source as Source
2222

23-
type Translator
23+
type TranslatorC
2424
= StateC [Scope]
2525
( ErrorC TranslationError PureC)
2626

27-
contextualizing :: Stream (Of Token) Translator a
28-
-> Stream (Of Fragment) Translator a
27+
contextualizing :: Stream (Of Token) TranslatorC a
28+
-> Stream (Of Fragment) TranslatorC a
2929
contextualizing s = Streaming.for s $ \case
3030
Chunk source -> yield . Verbatim . Source.toText $ source
3131
Element t -> case t of
3232
Run f -> lift get >>= \c -> yield (New t c f)
3333
_ -> lift get >>= yield . Defer t
3434
Control ctl -> case ctl of
35-
Enter c -> enterScope c
36-
Exit c -> exitScope c
35+
Enter c -> lift (enterScope c)
36+
Exit c -> lift (exitScope c)
3737
_ -> pure ()
3838

39-
-- PT TODO: this can be nicer
40-
enterScope, exitScope :: Scope -> Stream (Of Fragment) Translator ()
41-
enterScope c = lift (modify (c :))
42-
exitScope c = lift get >>= \case
43-
(x:xs) -> when (x == c) (lift (modify (const xs)))
44-
cs -> lift (throwError (UnbalancedPair c cs))
39+
enterScope :: (Member (State [Scope]) sig, Carrier sig m)
40+
=> Scope
41+
-> m ()
42+
enterScope c = modify (c :)
43+
44+
exitScope :: ( Member (State [Scope]) sig
45+
, Member (Error TranslationError) sig
46+
, Carrier sig m
47+
)
48+
=> Scope
49+
-> m ()
50+
exitScope c = get >>= \case
51+
(x:xs) -> when (x == c) (put xs)
52+
cs -> throwError (UnbalancedPair c cs)

0 commit comments

Comments
 (0)