File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,3 +8,7 @@ packages: prettyprinter
88 , prettyprinter-compat-annotated-wl-pprint
99tests : true
1010benchmarks : true
11+
12+ source-repository-package
13+ type : git
14+ location : https://github.com/Bodigrim/linear-builder
Original file line number Diff line number Diff line change @@ -68,7 +68,8 @@ library
6868 , ScopedTypeVariables
6969
7070 build-depends :
71- base >= 4.5 && < 5
71+ base >= 4.5 && < 5 ,
72+ text-builder-linear
7273
7374 if flag(text)
7475 build-depends : text >= 1.2
Original file line number Diff line number Diff line change 11{-# LANGUAGE CPP #-}
2+ {-# LANGUAGE LinearTypes #-}
3+ {-# LANGUAGE UnicodeSyntax #-}
4+ {-# LANGUAGE BangPatterns #-}
25
36#include "version-compatibility-macros.h"
47
@@ -36,6 +39,8 @@ import Data.Semigroup
3639import Control.Applicative
3740#endif
3841
42+ import Data.Text.Builder.Linear.Buffer
43+
3944-- $setup
4045--
4146-- (Definitions for the doctests)
@@ -70,9 +75,17 @@ renderLazy = TLB.toLazyText . go
7075-- | @('renderStrict' sdoc)@ takes the output @sdoc@ from a rendering function
7176-- and transforms it to strict text.
7277renderStrict :: SimpleDocStream ann -> Text
73- renderStrict = TL. toStrict . renderLazy
74-
75-
78+ renderStrict sdc = runBuffer (\ b -> (go b sdc))
79+ where
80+ go :: Buffer ⊸ SimpleDocStream ann -> Buffer
81+ go ! b ! sbc = case sbc of
82+ SFail -> undefined b
83+ SEmpty -> b
84+ SChar c rest -> go (b |>. c) rest
85+ SText _l t rest -> go (b |> t) rest
86+ SLine i rest -> go ((b |>. ' \n ' ) |>… i) rest
87+ SAnnPush _ann rest -> go b rest
88+ SAnnPop rest -> go b rest
7689
7790-- | @('renderIO' h sdoc)@ writes @sdoc@ to the file @h@.
7891--
You can’t perform that action at this time.
0 commit comments