module UVMHS.Lib.Pretty.DocA where
import UVMHS.Core
import UVMHS.Lib.TreeAnnote
import UVMHS.Lib.Pretty.Annotation
import UVMHS.Lib.Pretty.Common
import UVMHS.Lib.Pretty.Shape
data DocAEnv = DocAEnv
{ DocAEnv -> 𝑂 ℕ64
docAEnvMaxLineWidth ∷ 𝑂 ℕ64
, DocAEnv -> 𝑂 ℕ64
docAEnvMaxRibbonWidth ∷ 𝑂 ℕ64
, DocAEnv -> ℕ64
docAEnvNest ∷ ℕ64
} deriving (DocAEnv -> DocAEnv -> Bool
(DocAEnv -> DocAEnv -> Bool)
-> (DocAEnv -> DocAEnv -> Bool) -> Eq DocAEnv
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DocAEnv -> DocAEnv -> Bool
== :: DocAEnv -> DocAEnv -> Bool
$c/= :: DocAEnv -> DocAEnv -> Bool
/= :: DocAEnv -> DocAEnv -> Bool
Eq,Eq DocAEnv
Eq DocAEnv =>
(DocAEnv -> DocAEnv -> Ordering)
-> (DocAEnv -> DocAEnv -> Bool)
-> (DocAEnv -> DocAEnv -> Bool)
-> (DocAEnv -> DocAEnv -> Bool)
-> (DocAEnv -> DocAEnv -> Bool)
-> (DocAEnv -> DocAEnv -> DocAEnv)
-> (DocAEnv -> DocAEnv -> DocAEnv)
-> Ord DocAEnv
DocAEnv -> DocAEnv -> Bool
DocAEnv -> DocAEnv -> Ordering
DocAEnv -> DocAEnv -> DocAEnv
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: DocAEnv -> DocAEnv -> Ordering
compare :: DocAEnv -> DocAEnv -> Ordering
$c< :: DocAEnv -> DocAEnv -> Bool
< :: DocAEnv -> DocAEnv -> Bool
$c<= :: DocAEnv -> DocAEnv -> Bool
<= :: DocAEnv -> DocAEnv -> Bool
$c> :: DocAEnv -> DocAEnv -> Bool
> :: DocAEnv -> DocAEnv -> Bool
$c>= :: DocAEnv -> DocAEnv -> Bool
>= :: DocAEnv -> DocAEnv -> Bool
$cmax :: DocAEnv -> DocAEnv -> DocAEnv
max :: DocAEnv -> DocAEnv -> DocAEnv
$cmin :: DocAEnv -> DocAEnv -> DocAEnv
min :: DocAEnv -> DocAEnv -> DocAEnv
Ord,Int -> DocAEnv -> ShowS
[DocAEnv] -> ShowS
DocAEnv -> String
(Int -> DocAEnv -> ShowS)
-> (DocAEnv -> String) -> ([DocAEnv] -> ShowS) -> Show DocAEnv
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DocAEnv -> ShowS
showsPrec :: Int -> DocAEnv -> ShowS
$cshow :: DocAEnv -> String
show :: DocAEnv -> String
$cshowList :: [DocAEnv] -> ShowS
showList :: [DocAEnv] -> ShowS
Show)
makeLenses ''DocAEnv
docAEnv₀ ∷ DocAEnv
docAEnv₀ :: DocAEnv
docAEnv₀ = DocAEnv
{ docAEnvMaxLineWidth :: 𝑂 ℕ64
docAEnvMaxLineWidth = ℕ64 -> 𝑂 ℕ64
forall a. a -> 𝑂 a
Some (ℕ64 -> 𝑂 ℕ64) -> ℕ64 -> 𝑂 ℕ64
forall a b. (a -> b) -> a -> b
$ ℕ -> ℕ64
𝕟64 ℕ
120
, docAEnvMaxRibbonWidth :: 𝑂 ℕ64
docAEnvMaxRibbonWidth = ℕ64 -> 𝑂 ℕ64
forall a. a -> 𝑂 a
Some (ℕ64 -> 𝑂 ℕ64) -> ℕ64 -> 𝑂 ℕ64
forall a b. (a -> b) -> a -> b
$ ℕ -> ℕ64
𝕟64 ℕ
100
, docAEnvNest :: ℕ64
docAEnvNest = ℕ -> ℕ64
𝕟64 ℕ
0
}
data DocAState = DocAState
{ DocAState -> ℕ64
docAStateRib ∷ ℕ64
, DocAState -> ℕ64
docAStateRow ∷ ℕ64
, DocAState -> ℕ64
docAStateCol ∷ ℕ64
} deriving (DocAState -> DocAState -> Bool
(DocAState -> DocAState -> Bool)
-> (DocAState -> DocAState -> Bool) -> Eq DocAState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DocAState -> DocAState -> Bool
== :: DocAState -> DocAState -> Bool
$c/= :: DocAState -> DocAState -> Bool
/= :: DocAState -> DocAState -> Bool
Eq,Eq DocAState
Eq DocAState =>
(DocAState -> DocAState -> Ordering)
-> (DocAState -> DocAState -> Bool)
-> (DocAState -> DocAState -> Bool)
-> (DocAState -> DocAState -> Bool)
-> (DocAState -> DocAState -> Bool)
-> (DocAState -> DocAState -> DocAState)
-> (DocAState -> DocAState -> DocAState)
-> Ord DocAState
DocAState -> DocAState -> Bool
DocAState -> DocAState -> Ordering
DocAState -> DocAState -> DocAState
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: DocAState -> DocAState -> Ordering
compare :: DocAState -> DocAState -> Ordering
$c< :: DocAState -> DocAState -> Bool
< :: DocAState -> DocAState -> Bool
$c<= :: DocAState -> DocAState -> Bool
<= :: DocAState -> DocAState -> Bool
$c> :: DocAState -> DocAState -> Bool
> :: DocAState -> DocAState -> Bool
$c>= :: DocAState -> DocAState -> Bool
>= :: DocAState -> DocAState -> Bool
$cmax :: DocAState -> DocAState -> DocAState
max :: DocAState -> DocAState -> DocAState
$cmin :: DocAState -> DocAState -> DocAState
min :: DocAState -> DocAState -> DocAState
Ord,Int -> DocAState -> ShowS
[DocAState] -> ShowS
DocAState -> String
(Int -> DocAState -> ShowS)
-> (DocAState -> String)
-> ([DocAState] -> ShowS)
-> Show DocAState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DocAState -> ShowS
showsPrec :: Int -> DocAState -> ShowS
$cshow :: DocAState -> String
show :: DocAState -> String
$cshowList :: [DocAState] -> ShowS
showList :: [DocAState] -> ShowS
Show)
makeLenses ''DocAState
docAState₀ ∷ DocAState
docAState₀ :: DocAState
docAState₀ = DocAState
{ docAStateRib :: ℕ64
docAStateRib = ℕ -> ℕ64
𝕟64 ℕ
0
, docAStateRow :: ℕ64
docAStateRow = ℕ -> ℕ64
𝕟64 ℕ
0
, docAStateCol :: ℕ64
docAStateCol = ℕ -> ℕ64
𝕟64 ℕ
0
}
type DocAM = RWS DocAEnv TreeI DocAState
data DocA =
StaticDocA SummaryI
| DynamicDocA SummaryI (DocAM ())
makePrisms ''DocA
staticDocA ∷ DocA → SummaryI
staticDocA :: DocA -> SummaryI
staticDocA = \case
StaticDocA SummaryI
s → SummaryI
s
DynamicDocA SummaryI
s DocAM ()
_ → SummaryI
s
dynamicDocA ∷ DocA → DocAM ()
dynamicDocA :: DocA -> DocAM ()
dynamicDocA = \case
StaticDocA SummaryI
s → SummaryI -> DocAM ()
renderSummaryI SummaryI
s
DynamicDocA SummaryI
_ DocAM ()
d → DocAM ()
d
instance Null DocA where null :: DocA
null = SummaryI -> DocA
StaticDocA SummaryI
forall a. Null a => a
null
instance Append DocA where
StaticDocA SummaryI
s₁ ⧺ :: DocA -> DocA -> DocA
⧺ StaticDocA SummaryI
s₂ = SummaryI -> DocA
StaticDocA (SummaryI -> DocA) -> SummaryI -> DocA
forall a b. (a -> b) -> a -> b
$ SummaryI
s₁ SummaryI -> SummaryI -> SummaryI
forall a. Append a => a -> a -> a
⧺ SummaryI
s₂
StaticDocA SummaryI
s₁ ⧺ DynamicDocA SummaryI
s₂ DocAM ()
r₂ = SummaryI -> DocAM () -> DocA
DynamicDocA (SummaryI
s₁ SummaryI -> SummaryI -> SummaryI
forall a. Append a => a -> a -> a
⧺ SummaryI
s₂) (DocAM () -> DocA) -> DocAM () -> DocA
forall a b. (a -> b) -> a -> b
$ SummaryI -> DocAM ()
renderSummaryI SummaryI
s₁ DocAM () -> DocAM () -> DocAM ()
forall (m :: * -> *) a b. Bind m => m a -> m b -> m b
≫ DocAM ()
r₂
DynamicDocA SummaryI
s₁ DocAM ()
r₁ ⧺ StaticDocA SummaryI
s₂ = SummaryI -> DocAM () -> DocA
DynamicDocA (SummaryI
s₁ SummaryI -> SummaryI -> SummaryI
forall a. Append a => a -> a -> a
⧺ SummaryI
s₂) (DocAM () -> DocA) -> DocAM () -> DocA
forall a b. (a -> b) -> a -> b
$ DocAM ()
r₁ DocAM () -> DocAM () -> DocAM ()
forall (m :: * -> *) a b. Bind m => m a -> m b -> m b
≫ SummaryI -> DocAM ()
renderSummaryI SummaryI
s₂
DynamicDocA SummaryI
s₁ DocAM ()
r₁ ⧺ DynamicDocA SummaryI
s₂ DocAM ()
r₂ = SummaryI -> DocAM () -> DocA
DynamicDocA (SummaryI
s₁ SummaryI -> SummaryI -> SummaryI
forall a. Append a => a -> a -> a
⧺ SummaryI
s₂) (DocAM () -> DocA) -> DocAM () -> DocA
forall a b. (a -> b) -> a -> b
$ DocAM ()
r₁ DocAM () -> DocAM () -> DocAM ()
forall (m :: * -> *) a b. Bind m => m a -> m b -> m b
≫ DocAM ()
r₂
instance Monoid DocA
renderSummaryI ∷ SummaryI → DocAM ()
renderSummaryI :: SummaryI -> DocAM ()
renderSummaryI SummaryI
s =
let f :: DocAM () -> DocAM ()
f =
if ShapeA -> Bool
shapeIAligned (ShapeA -> Bool) -> ShapeA -> Bool
forall a b. (a -> b) -> a -> b
$ SummaryI -> ShapeA
summaryIShape SummaryI
s
then DocAM () -> DocAM ()
forall a. DocAM a -> DocAM a
alignDocAM
else DocAM () -> DocAM ()
forall a. a -> a
id
in DocAM () -> DocAM ()
f (DocAM () -> DocAM ()) -> DocAM () -> DocAM ()
forall a b. (a -> b) -> a -> b
$ do
ℕ64
nest ← (DocAEnv ⟢ ℕ64) -> RWST DocAEnv TreeI DocAState ID ℕ64
forall r'. (DocAEnv ⟢ r') -> RWST DocAEnv TreeI DocAState ID r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL DocAEnv ⟢ ℕ64
docAEnvNestL
let o :: TreeI
o = TreeI -> (𝐼 ChunkI -> 𝐼 ChunkI) -> TreeI
forall (t :: * -> *) a b. Functor t => t a -> (a -> b) -> t b
mapOn (SummaryI -> TreeI
summaryIContents SummaryI
s) ((𝐼 ChunkI -> 𝐼 ChunkI) -> TreeI)
-> (𝐼 ChunkI -> 𝐼 ChunkI) -> TreeI
forall a b. (a -> b) -> a -> b
$ (ChunkI -> ChunkI) -> 𝐼 ChunkI -> 𝐼 ChunkI
forall a b. (a -> b) -> 𝐼 a -> 𝐼 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ((ChunkI -> ChunkI) -> 𝐼 ChunkI -> 𝐼 ChunkI)
-> (ChunkI -> ChunkI) -> 𝐼 ChunkI -> 𝐼 ChunkI
forall a b. (a -> b) -> a -> b
$ \case
NewlineChunkI ℕ64
n → ℕ64 -> ChunkI
NewlineChunkI (ℕ64 -> ChunkI) -> ℕ64 -> ChunkI
forall a b. (a -> b) -> a -> b
$ ℕ64
n ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
nest
ChunkI
c → ChunkI
c
TreeI -> DocAM ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell TreeI
o
case ShapeA -> Shape
shapeIShape (ShapeA -> Shape) -> ShapeA -> Shape
forall a b. (a -> b) -> a -> b
$ SummaryI -> ShapeA
summaryIShape SummaryI
s of
SingleLine ℕ64
l → do
(DocAState ⟢ ℕ64) -> (ℕ64 -> ℕ64) -> DocAM ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> (a -> a) -> m ()
modifyL DocAState ⟢ ℕ64
docAStateRibL ((ℕ64 -> ℕ64) -> DocAM ()) -> (ℕ64 -> ℕ64) -> DocAM ()
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
(+) ℕ64
l
(DocAState ⟢ ℕ64) -> (ℕ64 -> ℕ64) -> DocAM ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> (a -> a) -> m ()
modifyL DocAState ⟢ ℕ64
docAStateColL ((ℕ64 -> ℕ64) -> DocAM ()) -> (ℕ64 -> ℕ64) -> DocAM ()
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
(+) ℕ64
l
MultiLine (ShapeM ℕ64
_ ℕ64
_ ℕ64
ll ℕ64
lines) → do
(DocAState ⟢ ℕ64) -> (ℕ64 -> ℕ64) -> DocAM ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> (a -> a) -> m ()
modifyL DocAState ⟢ ℕ64
docAStateRowL ((ℕ64 -> ℕ64) -> DocAM ()) -> (ℕ64 -> ℕ64) -> DocAM ()
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
(+) ℕ64
lines
(DocAState ⟢ ℕ64) -> ℕ64 -> DocAM ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL DocAState ⟢ ℕ64
docAStateRibL ℕ64
ll
(DocAState ⟢ ℕ64) -> ℕ64 -> DocAM ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL DocAState ⟢ ℕ64
docAStateColL ℕ64
ll
stringDocA ∷ 𝕊 → DocA
stringDocA :: 𝕊 -> DocA
stringDocA = SummaryI -> DocA
StaticDocA (SummaryI -> DocA) -> (𝐼 ChunkI -> SummaryI) -> 𝐼 ChunkI -> DocA
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ 𝐼 ChunkI -> SummaryI
summaryChunksI (𝐼 ChunkI -> DocA) -> (𝕊 -> 𝐼 ChunkI) -> 𝕊 -> DocA
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ 𝕊 -> 𝐼 ChunkI
splitChunksI
docAModal ∷ DocA → DocA → DocA
docAModal :: DocA -> DocA -> DocA
docAModal DocA
d₁ DocA
d₂ = SummaryI -> DocAM () -> DocA
DynamicDocA (DocA -> SummaryI
staticDocA DocA
d₁) (DocAM () -> DocA) -> DocAM () -> DocA
forall a b. (a -> b) -> a -> b
$ DocA -> DocAM ()
dynamicDocA DocA
d₂
annotateDocA ∷ Annotation → DocA → DocA
annotateDocA :: Annotation -> DocA -> DocA
annotateDocA Annotation
a = \case
StaticDocA SummaryI
s → SummaryI -> DocA
StaticDocA (SummaryI -> DocA) -> SummaryI -> DocA
forall a b. (a -> b) -> a -> b
$ Annotation -> SummaryI -> SummaryI
annotateSummaryI Annotation
a SummaryI
s
DynamicDocA SummaryI
s DocAM ()
xM → SummaryI -> DocAM () -> DocA
DynamicDocA (Annotation -> SummaryI -> SummaryI
annotateSummaryI Annotation
a SummaryI
s) (DocAM () -> DocA) -> DocAM () -> DocA
forall a b. (a -> b) -> a -> b
$ (TreeI -> TreeI) -> DocAM () -> DocAM ()
forall (m :: * -> *) o a.
(Monad m, MonadWriter o m) =>
(o -> o) -> m a -> m a
mapOut (Annotation -> TreeI -> TreeI
forall i a. Annote i a => i -> a -> a
annote Annotation
a) DocAM ()
xM
groupDocAM ∷ SummaryI → DocAM () → DocAM ()
groupDocAM :: SummaryI -> DocAM () -> DocAM ()
groupDocAM SummaryI
s DocAM ()
xM = do
if SummaryI -> Bool
summaryIForceBreak SummaryI
s
then DocAM ()
xM
else do
𝑂 ℕ64
lwO ← (DocAEnv ⟢ 𝑂 ℕ64) -> RWST DocAEnv TreeI DocAState ID (𝑂 ℕ64)
forall r'. (DocAEnv ⟢ r') -> RWST DocAEnv TreeI DocAState ID r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL DocAEnv ⟢ 𝑂 ℕ64
docAEnvMaxLineWidthL
𝑂 ℕ64
rwO ← (DocAEnv ⟢ 𝑂 ℕ64) -> RWST DocAEnv TreeI DocAState ID (𝑂 ℕ64)
forall r'. (DocAEnv ⟢ r') -> RWST DocAEnv TreeI DocAState ID r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL DocAEnv ⟢ 𝑂 ℕ64
docAEnvMaxRibbonWidthL
ℕ64
nest ← (DocAEnv ⟢ ℕ64) -> RWST DocAEnv TreeI DocAState ID ℕ64
forall r'. (DocAEnv ⟢ r') -> RWST DocAEnv TreeI DocAState ID r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL DocAEnv ⟢ ℕ64
docAEnvNestL
ℕ64
rib ← (DocAState ⟢ ℕ64) -> RWST DocAEnv TreeI DocAState ID ℕ64
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL DocAState ⟢ ℕ64
docAStateRibL
ℕ64
col ← (DocAState ⟢ ℕ64) -> RWST DocAEnv TreeI DocAState ID ℕ64
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL DocAState ⟢ ℕ64
docAStateColL
let ℕ64
ml :* ℕ64
mr = case ShapeA -> Shape
shapeIShape (ShapeA -> Shape) -> ShapeA -> Shape
forall a b. (a -> b) -> a -> b
$ SummaryI -> ShapeA
summaryIShape SummaryI
s of
SingleLine ℕ64
l → (ℕ64
nest ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
col ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
l) ℕ64 -> ℕ64 -> ℕ64 ∧ ℕ64
forall a b. a -> b -> a ∧ b
:* (ℕ64
rib ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
l)
MultiLine (ShapeM ℕ64
fl ℕ64
mml ℕ64
ll ℕ64
_) →
[ℕ64] -> ℕ64
forall a t. (JoinLattice a, ToIter a t) => t -> a
joins [ ℕ64
nest ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
col ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
fl , ℕ64
nest ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
mml , ℕ64
nest ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
ll ]
ℕ64 -> ℕ64 -> ℕ64 ∧ ℕ64
forall a b. a -> b -> a ∧ b
:*
[ℕ64] -> ℕ64
forall a t. (JoinLattice a, ToIter a t) => t -> a
joins [ ℕ64
rib ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
fl , ℕ64
mml , ℕ64
ll ]
mlb :: Bool
mlb = case 𝑂 ℕ64
lwO of
𝑂 ℕ64
None → Bool
True
Some ℕ64
lw → ℕ64
ml ℕ64 -> ℕ64 -> Bool
forall a. Ord a => a -> a -> Bool
≤ ℕ64
lw
mrb :: Bool
mrb = case 𝑂 ℕ64
rwO of
𝑂 ℕ64
None → Bool
True
Some ℕ64
rw → ℕ64
mr ℕ64 -> ℕ64 -> Bool
forall a. Ord a => a -> a -> Bool
≤ ℕ64
rw
case Bool
mlb Bool -> Bool -> Bool
⩓ Bool
mrb of
Bool
True → SummaryI -> DocAM ()
renderSummaryI SummaryI
s
Bool
False → DocAM ()
xM
groupDocA ∷ DocA → DocA
groupDocA :: DocA -> DocA
groupDocA = \case
StaticDocA SummaryI
s → SummaryI -> DocA
StaticDocA SummaryI
s
DynamicDocA SummaryI
s DocAM ()
xM → SummaryI -> DocAM () -> DocA
DynamicDocA SummaryI
s (DocAM () -> DocA) -> DocAM () -> DocA
forall a b. (a -> b) -> a -> b
$ SummaryI -> DocAM () -> DocAM ()
groupDocAM SummaryI
s DocAM ()
xM
alignDocAM ∷ DocAM a → DocAM a
alignDocAM :: forall a. DocAM a -> DocAM a
alignDocAM DocAM a
xM = do
ℕ64
col ← (DocAState ⟢ ℕ64) -> RWST DocAEnv TreeI DocAState ID ℕ64
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> m a
getL DocAState ⟢ ℕ64
docAStateColL
ℕ64
nest ← (DocAEnv ⟢ ℕ64) -> RWST DocAEnv TreeI DocAState ID ℕ64
forall r'. (DocAEnv ⟢ r') -> RWST DocAEnv TreeI DocAState ID r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL DocAEnv ⟢ ℕ64
docAEnvNestL
(DocAState ⟢ ℕ64) -> ℕ64 -> DocAM ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> a -> m ()
putL DocAState ⟢ ℕ64
docAStateColL (ℕ64 -> DocAM ()) -> ℕ64 -> DocAM ()
forall a b. (a -> b) -> a -> b
$ ℕ -> ℕ64
𝕟64 ℕ
0
a
x ← (DocAEnv ⟢ ℕ64) -> ℕ64 -> DocAM a -> DocAM a
forall a r'.
(DocAEnv ⟢ r')
-> r'
-> RWST DocAEnv TreeI DocAState ID a
-> RWST DocAEnv TreeI DocAState ID a
forall r (m :: * -> *) a r'.
MonadReader r m =>
(r ⟢ r') -> r' -> m a -> m a
localL DocAEnv ⟢ ℕ64
docAEnvNestL (ℕ64
nest ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
col) DocAM a
xM
(DocAState ⟢ ℕ64) -> (ℕ64 -> ℕ64) -> DocAM ()
forall (m :: * -> *) s a.
(Monad m, MonadState s m) =>
(s ⟢ a) -> (a -> a) -> m ()
modifyL DocAState ⟢ ℕ64
docAStateColL ((ℕ64 -> ℕ64) -> DocAM ()) -> (ℕ64 -> ℕ64) -> DocAM ()
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
(+) ℕ64
col
a -> DocAM a
forall a. a -> RWST DocAEnv TreeI DocAState ID a
forall (m :: * -> *) a. Return m => a -> m a
return a
x
alignDocA ∷ DocA → DocA
alignDocA :: DocA -> DocA
alignDocA = \case
StaticDocA SummaryI
s → SummaryI -> DocA
StaticDocA (SummaryI -> DocA) -> SummaryI -> DocA
forall a b. (a -> b) -> a -> b
$ SummaryI -> SummaryI
alignSummary SummaryI
s
DynamicDocA SummaryI
s DocAM ()
r → SummaryI -> DocAM () -> DocA
DynamicDocA (SummaryI -> SummaryI
alignSummary SummaryI
s) (DocAM () -> DocA) -> DocAM () -> DocA
forall a b. (a -> b) -> a -> b
$ DocAM () -> DocAM ()
forall a. DocAM a -> DocAM a
alignDocAM DocAM ()
r
execDocAWith ∷ (DocAM () → DocAM ()) → DocA → TreeI
execDocAWith :: (DocAM () -> DocAM ()) -> DocA -> TreeI
execDocAWith DocAM () -> DocAM ()
f DocA
d = DocAEnv -> DocAState -> RWS DocAEnv TreeI DocAState TreeI -> TreeI
forall r o s a. r -> s -> RWS r o s a -> a
evalRWS DocAEnv
docAEnv₀ DocAState
docAState₀ (RWS DocAEnv TreeI DocAState TreeI -> TreeI)
-> RWS DocAEnv TreeI DocAState TreeI -> TreeI
forall a b. (a -> b) -> a -> b
$ DocAM () -> RWS DocAEnv TreeI DocAState TreeI
forall o (m :: * -> *) a. (Monad m, MonadWriter o m) => m a -> m o
retOut (DocAM () -> RWS DocAEnv TreeI DocAState TreeI)
-> DocAM () -> RWS DocAEnv TreeI DocAState TreeI
forall a b. (a -> b) -> a -> b
$ DocAM () -> DocAM ()
f (DocAM () -> DocAM ()) -> DocAM () -> DocAM ()
forall a b. (a -> b) -> a -> b
$ case DocA
d of
StaticDocA SummaryI
s → TreeI -> DocAM ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell (TreeI -> DocAM ()) -> TreeI -> DocAM ()
forall a b. (a -> b) -> a -> b
$ SummaryI -> TreeI
summaryIContents SummaryI
s
DynamicDocA SummaryI
_ DocAM ()
r → DocAM ()
r
execDocA ∷ DocA → TreeI
execDocA :: DocA -> TreeI
execDocA = (DocAM () -> DocAM ()) -> DocA -> TreeI
execDocAWith DocAM () -> DocAM ()
forall a. a -> a
id