Skip to content

Commit

Permalink
Implement stimes for Doc (#135)
Browse files Browse the repository at this point in the history
Fixes #133.
  • Loading branch information
sjakobi authored Jun 30, 2020
1 parent 9635a5d commit fbbc66e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion prettyprinter/prettyprinter.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ library
if impl(ghc >= 8.0)
ghc-options: -Wcompat
if !impl(ghc >= 8.0)
build-depends: semigroups >= 0.16.1
build-depends: semigroups >= 0.17
build-depends: fail >= 4.9.0.0 && <4.10
if !impl(ghc >= 7.10)
build-depends: void >=0.4 && <0.8
Expand Down
20 changes: 20 additions & 0 deletions prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ data Doc ann =
instance Semigroup (Doc ann) where
(<>) = Cat
sconcat (x :| xs) = hcat (x:xs)
stimes n x
| n <= 0 = Empty
| n == 1 = x
| otherwise =
let n' = fromIntegral n
nx = hcat (replicate n' x)
in case x of
Fail -> Fail
Empty -> Empty
Char c -> Text n' (T.replicate n' (T.singleton c))
Text l t -> Text (n' * l) (T.replicate n' t)
Line -> nx
FlatAlt{} -> nx
Cat{} -> nx
Nest{} -> nx
Union{} -> nx
Column{} -> nx
WithPageWidth{} -> nx
Nesting{} -> nx
Annotated{} -> nx

-- |
-- @
Expand Down
2 changes: 2 additions & 0 deletions stack-older-snapshots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ extra-deps:
- pgp-wordlist-0.1.0.2
- ansi-wl-pprint-0.6.8
- fail-4.9.0.0
- semigroups-0.17.0.1
- void-0.7.3
flags: {}
extra-package-dbs: []

0 comments on commit fbbc66e

Please sign in to comment.