Skip to content

Commit dda7ed6

Browse files
committed
Migrate to text-builder-linear
1 parent 2ae35fb commit dda7ed6

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

cabal.project

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ packages: prettyprinter
88
, prettyprinter-compat-annotated-wl-pprint
99
tests: true
1010
benchmarks: true
11+
12+
source-repository-package
13+
type: git
14+
location: https://github.com/Bodigrim/linear-builder

prettyprinter/prettyprinter.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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

prettyprinter/src/Prettyprinter/Render/Text.hs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
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
3639
import 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.
7277
renderStrict :: 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
--

0 commit comments

Comments
 (0)