{-# LANGUAGE OverloadedStrings #-}
module Prettyprinter.Custom (
brackets',
braces',
parens',
sexp,
(<?>),
vcatHard,
) where
import Prettyprinter
section' :: Doc a -> Doc a -> Doc a -> Doc a
section' :: forall a. Doc a -> Doc a -> Doc a -> Doc a
section' Doc a
c1 Doc a
c2 Doc a
d = Doc a -> Doc a
forall ann. Doc ann -> Doc ann
group (Doc a -> Doc a) -> Doc a -> Doc a
forall a b. (a -> b) -> a -> b
$ Int -> Doc a -> Doc a
forall ann. Int -> Doc ann -> Doc ann
nest Int
2 (Doc a
c1 Doc a -> Doc a -> Doc a
forall a. Semigroup a => a -> a -> a
<> Doc a
d) Doc a -> Doc a -> Doc a
forall a. Semigroup a => a -> a -> a
<> Doc a
c2
section :: Doc a -> Doc a -> Doc a -> Doc a
section :: forall a. Doc a -> Doc a -> Doc a -> Doc a
section Doc a
c1 Doc a
c2 = Doc a -> Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a -> Doc a
section' (Doc a
c1 Doc a -> Doc a -> Doc a
forall a. Semigroup a => a -> a -> a
<> Doc a
forall ann. Doc ann
line) (Doc a
forall ann. Doc ann
line Doc a -> Doc a -> Doc a
forall a. Semigroup a => a -> a -> a
<> Doc a
c2)
brackets' :: Doc a -> Doc a
brackets' :: forall ann. Doc ann -> Doc ann
brackets' = Doc a -> Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a -> Doc a
section Doc a
"[" Doc a
"]"
braces' :: Doc a -> Doc a
braces' :: forall ann. Doc ann -> Doc ann
braces' = Doc a -> Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a -> Doc a
section Doc a
"{" Doc a
"}"
parens' :: Doc a -> Doc a
parens' :: forall ann. Doc ann -> Doc ann
parens' = Doc a -> Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a -> Doc a
section Doc a
"(" Doc a
")"
sexp :: Doc a -> [Doc a] -> Doc a
sexp :: forall a. Doc a -> [Doc a] -> Doc a
sexp Doc a
a [Doc a]
es =
Doc a -> Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a -> Doc a
section' (Doc a
"(" Doc a -> Doc a -> Doc a
forall a. Semigroup a => a -> a -> a
<> Doc a
a Doc a -> Doc a -> Doc a
forall a. Semigroup a => a -> a -> a
<> if [Doc a] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Doc a]
es then Doc a
forall ann. Doc ann
line' else Doc a
forall ann. Doc ann
line) (Doc a
forall ann. Doc ann
line' Doc a -> Doc a -> Doc a
forall a. Semigroup a => a -> a -> a
<> Doc a
")") ([Doc a] -> Doc a
forall ann. [Doc ann] -> Doc ann
sep [Doc a]
es)
vcatHard :: [Doc ann] -> Doc ann
vcatHard :: forall ann. [Doc ann] -> Doc ann
vcatHard = (Doc ann -> Doc ann -> Doc ann) -> [Doc ann] -> Doc ann
forall (t :: * -> *) ann.
Foldable t =>
(Doc ann -> Doc ann -> Doc ann) -> t (Doc ann) -> Doc ann
concatWith (\Doc ann
x Doc ann
y -> Doc ann
x Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
forall ann. Doc ann
hardline Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
y)
(<?>) :: Doc ann -> Doc ann -> Doc ann
Doc ann
p <?> :: forall ann. Doc ann -> Doc ann -> Doc ann
<?> Doc ann
q = Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
align (Doc ann -> Doc ann) -> (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
nest Int
2 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
sep [Doc ann
p, Doc ann
q]
infixr 6 <?>