module UVMHS.Lib.Pretty.Common where

import UVMHS.Core

import UVMHS.Lib.TreeAnnote
import UVMHS.Lib.Sep

import UVMHS.Lib.Pretty.Annotation
import UVMHS.Lib.Pretty.Shape

-----------------
-- Input Chunk --
-----------------
  
data ChunkI =
  --          length
  --          ⌄⌄⌄
    RawChunkI ℕ64 𝕊
  --              ^
  --              string with no newlines
  | NewlineChunkI ℕ64
  --              ^^^
  --              indent after newline
  deriving (ChunkI -> ChunkI -> Bool
(ChunkI -> ChunkI -> Bool)
-> (ChunkI -> ChunkI -> Bool) -> Eq ChunkI
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChunkI -> ChunkI -> Bool
== :: ChunkI -> ChunkI -> Bool
$c/= :: ChunkI -> ChunkI -> Bool
/= :: ChunkI -> ChunkI -> Bool
Eq,Eq ChunkI
Eq ChunkI =>
(ChunkI -> ChunkI -> Ordering)
-> (ChunkI -> ChunkI -> Bool)
-> (ChunkI -> ChunkI -> Bool)
-> (ChunkI -> ChunkI -> Bool)
-> (ChunkI -> ChunkI -> Bool)
-> (ChunkI -> ChunkI -> ChunkI)
-> (ChunkI -> ChunkI -> ChunkI)
-> Ord ChunkI
ChunkI -> ChunkI -> Bool
ChunkI -> ChunkI -> Ordering
ChunkI -> ChunkI -> ChunkI
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 :: ChunkI -> ChunkI -> Ordering
compare :: ChunkI -> ChunkI -> Ordering
$c< :: ChunkI -> ChunkI -> Bool
< :: ChunkI -> ChunkI -> Bool
$c<= :: ChunkI -> ChunkI -> Bool
<= :: ChunkI -> ChunkI -> Bool
$c> :: ChunkI -> ChunkI -> Bool
> :: ChunkI -> ChunkI -> Bool
$c>= :: ChunkI -> ChunkI -> Bool
>= :: ChunkI -> ChunkI -> Bool
$cmax :: ChunkI -> ChunkI -> ChunkI
max :: ChunkI -> ChunkI -> ChunkI
$cmin :: ChunkI -> ChunkI -> ChunkI
min :: ChunkI -> ChunkI -> ChunkI
Ord,Int -> ChunkI -> ShowS
[ChunkI] -> ShowS
ChunkI -> String
(Int -> ChunkI -> ShowS)
-> (ChunkI -> String) -> ([ChunkI] -> ShowS) -> Show ChunkI
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChunkI -> ShowS
showsPrec :: Int -> ChunkI -> ShowS
$cshow :: ChunkI -> String
show :: ChunkI -> String
$cshowList :: [ChunkI] -> ShowS
showList :: [ChunkI] -> ShowS
Show)

rawChunksI  𝕊  ChunkI
rawChunksI :: 𝕊 -> ChunkI
rawChunksI 𝕊
s = ℕ64 -> 𝕊 -> ChunkI
RawChunkI (ℕ -> ℕ64
𝕟64 (ℕ -> ℕ64) -> ℕ -> ℕ64
forall a b. (a -> b) -> a -> b
$ 𝕊 -> ℕ
length𝕊 𝕊
s) 𝕊
s
 
splitChunksI  𝕊  𝐼 ChunkI
splitChunksI :: 𝕊 -> 𝐼 ChunkI
splitChunksI 𝕊
s = 
  𝐼 ChunkI -> 𝐼 ChunkI
forall a t. ToIter a t => t -> 𝐼 a
materialize 
  (𝐼 ChunkI -> 𝐼 ChunkI) -> 𝐼 ChunkI -> 𝐼 ChunkI
forall a b. (a -> b) -> a -> b
$ (ChunkI -> Bool) -> 𝐼 ChunkI -> 𝐼 ChunkI
forall a t. ToIter a t => (a -> Bool) -> t -> 𝐼 a
filter (\ ChunkI
c  ChunkI
c ChunkI -> ChunkI -> Bool
forall a. Eq a => a -> a -> Bool
 ℕ64 -> 𝕊 -> ChunkI
RawChunkI (ℕ -> ℕ64
𝕟64 0) 𝕊
"") 
  (𝐼 ChunkI -> 𝐼 ChunkI) -> 𝐼 ChunkI -> 𝐼 ChunkI
forall a b. (a -> b) -> a -> b
$ ChunkI -> 𝐼 ChunkI -> 𝐼 ChunkI
forall a t. ToIter a t => a -> t -> 𝐼 a
inbetween (ℕ64 -> ChunkI
NewlineChunkI ℕ64
forall a. Zero a => a
zero) 
  (𝐼 ChunkI -> 𝐼 ChunkI) -> 𝐼 ChunkI -> 𝐼 ChunkI
forall a b. (a -> b) -> a -> b
$ (𝕊 -> ChunkI) -> 𝐼 𝕊 -> 𝐼 ChunkI
forall a b. (a -> b) -> 𝐼 a -> 𝐼 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map 𝕊 -> ChunkI
rawChunksI (𝐼 𝕊 -> 𝐼 ChunkI) -> 𝐼 𝕊 -> 𝐼 ChunkI
forall a b. (a -> b) -> a -> b
$ 𝕊 -> 𝕊 -> 𝐼 𝕊
splitOn𝕊 𝕊
"\n" 𝕊
s

shapeIChunk  ChunkI  Shape
shapeIChunk :: ChunkI -> Shape
shapeIChunk = \case
  RawChunkI ℕ64
l 𝕊
_  ℕ64 -> Shape
SingleLine ℕ64
l
  NewlineChunkI ℕ64
n  Shape
newlineShape Shape -> Shape -> Shape
forall a. Append a => a -> a -> a
 ℕ64 -> Shape
SingleLine ℕ64
n
 
extendNewlinesIChunk  ℕ64  ChunkI  ChunkI
extendNewlinesIChunk :: ℕ64 -> ChunkI -> ChunkI
extendNewlinesIChunk ℕ64
n = \case
  RawChunkI ℕ64
l 𝕊
s  ℕ64 -> 𝕊 -> ChunkI
RawChunkI ℕ64
l 𝕊
s
  NewlineChunkI ℕ64
l  ℕ64 -> ChunkI
NewlineChunkI (ℕ64 -> ChunkI) -> ℕ64 -> ChunkI
forall a b. (a -> b) -> a -> b
$ ℕ64
l ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
n

------------------
-- Output Chunk --
------------------

data ChunkO =
  --          length
  --          ⌄⌄⌄
    RawChunkO ℕ64 𝕊
  --              ^
  --              string with no newlines
  | PaddingChunkO ℕ64
  --              ^^^
  --              padding length
  deriving (ChunkO -> ChunkO -> Bool
(ChunkO -> ChunkO -> Bool)
-> (ChunkO -> ChunkO -> Bool) -> Eq ChunkO
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChunkO -> ChunkO -> Bool
== :: ChunkO -> ChunkO -> Bool
$c/= :: ChunkO -> ChunkO -> Bool
/= :: ChunkO -> ChunkO -> Bool
Eq,Eq ChunkO
Eq ChunkO =>
(ChunkO -> ChunkO -> Ordering)
-> (ChunkO -> ChunkO -> Bool)
-> (ChunkO -> ChunkO -> Bool)
-> (ChunkO -> ChunkO -> Bool)
-> (ChunkO -> ChunkO -> Bool)
-> (ChunkO -> ChunkO -> ChunkO)
-> (ChunkO -> ChunkO -> ChunkO)
-> Ord ChunkO
ChunkO -> ChunkO -> Bool
ChunkO -> ChunkO -> Ordering
ChunkO -> ChunkO -> ChunkO
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 :: ChunkO -> ChunkO -> Ordering
compare :: ChunkO -> ChunkO -> Ordering
$c< :: ChunkO -> ChunkO -> Bool
< :: ChunkO -> ChunkO -> Bool
$c<= :: ChunkO -> ChunkO -> Bool
<= :: ChunkO -> ChunkO -> Bool
$c> :: ChunkO -> ChunkO -> Bool
> :: ChunkO -> ChunkO -> Bool
$c>= :: ChunkO -> ChunkO -> Bool
>= :: ChunkO -> ChunkO -> Bool
$cmax :: ChunkO -> ChunkO -> ChunkO
max :: ChunkO -> ChunkO -> ChunkO
$cmin :: ChunkO -> ChunkO -> ChunkO
min :: ChunkO -> ChunkO -> ChunkO
Ord,Int -> ChunkO -> ShowS
[ChunkO] -> ShowS
ChunkO -> String
(Int -> ChunkO -> ShowS)
-> (ChunkO -> String) -> ([ChunkO] -> ShowS) -> Show ChunkO
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChunkO -> ShowS
showsPrec :: Int -> ChunkO -> ShowS
$cshow :: ChunkO -> String
show :: ChunkO -> String
$cshowList :: [ChunkO] -> ShowS
showList :: [ChunkO] -> ShowS
Show)

instance ASized ChunkO where
  asize :: ChunkO -> ℕ64
asize (RawChunkO ℕ64
n 𝕊
_) = ℕ64
n
  asize (PaddingChunkO ℕ64
n) = ℕ64
n

shapeOChunk  ChunkO  Shape
shapeOChunk :: ChunkO -> Shape
shapeOChunk = \case
  RawChunkO ℕ64
l 𝕊
_  ℕ64 -> Shape
SingleLine ℕ64
l
  PaddingChunkO ℕ64
n  ℕ64 -> Shape
SingleLine ℕ64
n

--------------------
-- Document Trees --
--------------------

type TreeI = 𝑇V Annotation (𝐼 ChunkI)

--                              stuff 
--                              between 
--                              newlines
--                              ⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄
type TreeO = 𝑇V Formats (Sep () (𝐼A ChunkO))
--                           ^^
--                           newline indicator

chunkIO  ChunkO  ChunkI
chunkIO :: ChunkO -> ChunkI
chunkIO = \case
  RawChunkO ℕ64
n 𝕊
s  ℕ64 -> 𝕊 -> ChunkI
RawChunkI ℕ64
n 𝕊
s
  PaddingChunkO ℕ64
n  ℕ64 -> 𝕊 -> ChunkI
RawChunkI ℕ64
n (𝕊 -> ChunkI) -> 𝕊 -> ChunkI
forall a b. (a -> b) -> a -> b
$ 𝐼 ℂ -> 𝕊
forall t. ToIter ℂ t => t -> 𝕊
string (𝐼 ℂ -> 𝕊) -> 𝐼 ℂ -> 𝕊
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ℂ -> 𝐼 ℂ
forall n a. (Eq n, Zero n, One n, Plus n) => n -> a -> 𝐼 a
replicate ℕ64
n ' '

treeIO  TreeO  TreeI
treeIO :: TreeO -> TreeI
treeIO = (Formats -> Annotation)
-> (Sep () (𝐼A ChunkO) -> 𝐼 ChunkI) -> TreeO -> TreeI
forall i j a b. (i -> j) -> (a -> b) -> 𝑇V i a -> 𝑇V j b
map𝑇V Formats -> Annotation
formatAnnotation ((Sep () (𝐼A ChunkO) -> 𝐼 ChunkI) -> TreeO -> TreeI)
-> (Sep () (𝐼A ChunkO) -> 𝐼 ChunkI) -> TreeO -> TreeI
forall a b. (a -> b) -> a -> b
$ 𝐼 (𝐼 ChunkI) -> 𝐼 ChunkI
forall a t. (Monoid a, ToIter a t) => t -> a
concat (𝐼 (𝐼 ChunkI) -> 𝐼 ChunkI)
-> (Sep (𝐼 ChunkI) (𝐼 ChunkI) -> 𝐼 (𝐼 ChunkI))
-> Sep (𝐼 ChunkI) (𝐼 ChunkI)
-> 𝐼 ChunkI
forall b c a. (b -> c) -> (a -> b) -> a -> c
 Sep (𝐼 ChunkI) (𝐼 ChunkI) -> 𝐼 (𝐼 ChunkI)
forall a t. ToIter a t => t -> 𝐼 a
iter (Sep (𝐼 ChunkI) (𝐼 ChunkI) -> 𝐼 ChunkI)
-> (Sep () (𝐼A ChunkO) -> Sep (𝐼 ChunkI) (𝐼 ChunkI))
-> Sep () (𝐼A ChunkO)
-> 𝐼 ChunkI
forall b c a. (b -> c) -> (a -> b) -> a -> c
 (() -> 𝐼 ChunkI)
-> (𝐼A ChunkO -> 𝐼 ChunkI)
-> Sep () (𝐼A ChunkO)
-> Sep (𝐼 ChunkI) (𝐼 ChunkI)
forall i j a b. (i -> j) -> (a -> b) -> Sep i a -> Sep j b
mapSep (𝐼 ChunkI -> () -> 𝐼 ChunkI
forall a b. a -> b -> a
const (𝐼 ChunkI -> () -> 𝐼 ChunkI) -> 𝐼 ChunkI -> () -> 𝐼 ChunkI
forall a b. (a -> b) -> a -> b
$ forall a t. Single a t => a -> t
single @_ @(𝐼 _) (ChunkI -> 𝐼 ChunkI) -> ChunkI -> 𝐼 ChunkI
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ChunkI
NewlineChunkI ℕ64
forall a. Zero a => a
zero) ((ChunkO -> ChunkI) -> 𝐼 ChunkO -> 𝐼 ChunkI
forall a b. (a -> b) -> 𝐼 a -> 𝐼 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ChunkO -> ChunkI
chunkIO (𝐼 ChunkO -> 𝐼 ChunkI)
-> (𝐼A ChunkO -> 𝐼 ChunkO) -> 𝐼A ChunkO -> 𝐼 ChunkI
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝐼A ChunkO -> 𝐼 ChunkO
forall a t. ToIter a t => t -> 𝐼 a
iter)

--------------
-- SummaryI --
--------------

data SummaryI = SummaryI
  { SummaryI -> Bool
summaryIForceBreak  𝔹
  , SummaryI -> ShapeA
summaryIShape  ShapeA
  , SummaryI -> TreeI
summaryIContents  TreeI
  }
makeLenses ''SummaryI

alignSummary  SummaryI  SummaryI
alignSummary :: SummaryI -> SummaryI
alignSummary (SummaryI Bool
b ShapeA
sh TreeI
c) = Bool -> ShapeA -> TreeI -> SummaryI
SummaryI Bool
b (ShapeA -> ShapeA
alignShapeA ShapeA
sh) TreeI
c

instance Null SummaryI where null :: SummaryI
null = Bool -> ShapeA -> TreeI -> SummaryI
SummaryI Bool
False ShapeA
forall a. Null a => a
null TreeI
forall a. Null a => a
null
instance Append SummaryI where
  SummaryI Bool
b₁ ShapeA
sh₁ TreeI
cs₁ ⧺ :: SummaryI -> SummaryI -> SummaryI
 SummaryI Bool
b₂ ShapeA
sh₂ TreeI
cs₂ = 
    let cs₂' :: TreeI
cs₂' =
          if Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ ShapeA -> Bool
shapeIAligned ShapeA
sh₂
          then TreeI
cs₂
          else TreeI -> (ChunkI -> ChunkI) -> TreeI
forall (t :: * -> *) (u :: * -> *) a b.
(Functor t, Functor u) =>
t (u a) -> (a -> b) -> t (u b)
mappOn TreeI
cs₂ ((ChunkI -> ChunkI) -> TreeI) -> (ChunkI -> ChunkI) -> TreeI
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ChunkI -> ChunkI
extendNewlinesIChunk (ℕ64 -> ChunkI -> ChunkI) -> ℕ64 -> ChunkI -> ChunkI
forall a b. (a -> b) -> a -> b
$ Shape -> ℕ64
shapeLastLength (Shape -> ℕ64) -> Shape -> ℕ64
forall a b. (a -> b) -> a -> b
$ ShapeA -> Shape
shapeIShape ShapeA
sh₁
    in Bool -> ShapeA -> TreeI -> SummaryI
SummaryI (Bool
b₁ Bool -> Bool -> Bool
 Bool
b₂) (ShapeA
sh₁ ShapeA -> ShapeA -> ShapeA
forall a. Append a => a -> a -> a
 ShapeA
sh₂) (TreeI -> SummaryI) -> TreeI -> SummaryI
forall a b. (a -> b) -> a -> b
$ TreeI
cs₁ TreeI -> TreeI -> TreeI
forall a. Append a => a -> a -> a
 TreeI
cs₂'
instance Monoid SummaryI

summaryChunksI  𝐼 ChunkI  SummaryI
summaryChunksI :: 𝐼 ChunkI -> SummaryI
summaryChunksI 𝐼 ChunkI
chunks =
  let sh :: Shape
sh = 𝐼 Shape -> Shape
forall a t. (Monoid a, ToIter a t) => t -> a
concat (𝐼 Shape -> Shape) -> 𝐼 Shape -> Shape
forall a b. (a -> b) -> a -> b
$ (ChunkI -> Shape) -> 𝐼 ChunkI -> 𝐼 Shape
forall a b. (a -> b) -> 𝐼 a -> 𝐼 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ChunkI -> Shape
shapeIChunk (𝐼 ChunkI -> 𝐼 Shape) -> 𝐼 ChunkI -> 𝐼 Shape
forall a b. (a -> b) -> a -> b
$ 𝐼 ChunkI -> 𝐼 ChunkI
forall a t. ToIter a t => t -> 𝐼 a
iter 𝐼 ChunkI
chunks
  in Bool -> ShapeA -> TreeI -> SummaryI
SummaryI Bool
False (Bool -> Shape -> ShapeA
ShapeA Bool
False Shape
sh) (TreeI -> SummaryI) -> TreeI -> SummaryI
forall a b. (a -> b) -> a -> b
$ 𝐼 ChunkI -> TreeI
forall a t. Single a t => a -> t
single 𝐼 ChunkI
chunks

annotateSummaryI  Annotation  SummaryI  SummaryI
annotateSummaryI :: Annotation -> SummaryI -> SummaryI
annotateSummaryI Annotation
a (SummaryI Bool
b ShapeA
sh TreeI
cs) = Bool -> ShapeA -> TreeI -> SummaryI
SummaryI Bool
b ShapeA
sh (TreeI -> SummaryI) -> TreeI -> SummaryI
forall a b. (a -> b) -> a -> b
$ Annotation -> TreeI -> TreeI
forall i a. Annote i a => i -> a -> a
annote Annotation
a TreeI
cs

--------------
-- SummaryO --
--------------

data SummaryO = SummaryO
  { SummaryO -> Shape
summaryOShape  Shape
  , SummaryO -> TreeO
summaryOContents  TreeO
  }
makeLenses ''SummaryO

instance Null SummaryO where null :: SummaryO
null = Shape -> TreeO -> SummaryO
SummaryO Shape
forall a. Null a => a
null TreeO
forall a. Null a => a
null
instance Append SummaryO where SummaryO Shape
sh₁ TreeO
cs₁ ⧺ :: SummaryO -> SummaryO -> SummaryO
 SummaryO Shape
sh₂ TreeO
cs₂ = Shape -> TreeO -> SummaryO
SummaryO (Shape
sh₁ Shape -> Shape -> Shape
forall a. Append a => a -> a -> a
 Shape
sh₂) (TreeO -> SummaryO) -> TreeO -> SummaryO
forall a b. (a -> b) -> a -> b
$ TreeO
cs₁ TreeO -> TreeO -> TreeO
forall a. Append a => a -> a -> a
 TreeO
cs₂
instance Monoid SummaryO

summaryChunksO  Sep () (𝐼A ChunkO)  SummaryO
summaryChunksO :: Sep () (𝐼A ChunkO) -> SummaryO
summaryChunksO Sep () (𝐼A ChunkO)
chunks =
  let sh :: Shape
sh = Sep Shape Shape -> Shape
forall a t. (Monoid a, ToIter a t) => t -> a
concat (Sep Shape Shape -> Shape) -> Sep Shape Shape -> Shape
forall a b. (a -> b) -> a -> b
$ (() -> Shape)
-> (𝐼A ChunkO -> Shape) -> Sep () (𝐼A ChunkO) -> Sep Shape Shape
forall i j a b. (i -> j) -> (a -> b) -> Sep i a -> Sep j b
mapSep (Shape -> () -> Shape
forall a b. a -> b -> a
const Shape
newlineShape) (𝐼 Shape -> Shape
forall a t. (Monoid a, ToIter a t) => t -> a
concat (𝐼 Shape -> Shape) -> (𝐼 ChunkO -> 𝐼 Shape) -> 𝐼 ChunkO -> Shape
forall b c a. (b -> c) -> (a -> b) -> a -> c
 (ChunkO -> Shape) -> 𝐼 ChunkO -> 𝐼 Shape
forall a b. (a -> b) -> 𝐼 a -> 𝐼 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ChunkO -> Shape
shapeOChunk (𝐼 ChunkO -> Shape)
-> (𝐼A ChunkO -> 𝐼 ChunkO) -> 𝐼A ChunkO -> Shape
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝐼A ChunkO -> 𝐼 ChunkO
forall a t. ToIter a t => t -> 𝐼 a
iter) Sep () (𝐼A ChunkO)
chunks
  in Shape -> TreeO -> SummaryO
SummaryO Shape
sh (TreeO -> SummaryO) -> TreeO -> SummaryO
forall a b. (a -> b) -> a -> b
$ Sep () (𝐼A ChunkO) -> TreeO
forall a t. Single a t => a -> t
single Sep () (𝐼A ChunkO)
chunks

annotateSummaryO  Formats  SummaryO  SummaryO
annotateSummaryO :: Formats -> SummaryO -> SummaryO
annotateSummaryO Formats
fm (SummaryO Shape
sh TreeO
cs) = Shape -> TreeO -> SummaryO
SummaryO Shape
sh (TreeO -> SummaryO) -> TreeO -> SummaryO
forall a b. (a -> b) -> a -> b
$ Formats -> TreeO -> TreeO
forall i a. Annote i a => i -> a -> a
annote Formats
fm TreeO
cs

---------------
-- Alignment --
---------------

data HAlign = LH | CH | RH
data VAlign = TV | CV | BV

hvalign  HAlign  VAlign  ℕ64  ℕ64  SummaryO  SummaryO
hvalign :: HAlign -> VAlign -> ℕ64 -> ℕ64 -> SummaryO -> SummaryO
hvalign HAlign
ha VAlign
va ℕ64
m ℕ64
n (SummaryO Shape
sh TreeO
cs) =
  let w :: ℕ64
w   = Shape -> ℕ64
shapeWidth Shape
sh
      wd :: ℕ64
wd  = (ℕ64
w ℕ64 -> ℕ64 -> ℕ64
forall a. Join a => a -> a -> a
 ℕ64
m) ℕ64 -> ℕ64 -> ℕ64
forall a. Minus a => a -> a -> a
- ℕ64
w
      wdm :: ℕ64
wdm = ℕ64
wd ℕ64 -> ℕ64 -> ℕ64
forall a. DivMod a => a -> a -> a
 ℕ -> ℕ64
𝕟64 2
      h :: ℕ64
h   = Shape -> ℕ64
shapeNewlines Shape
sh
      hd :: ℕ64
hd  = (ℕ64
h ℕ64 -> ℕ64 -> ℕ64
forall a. Join a => a -> a -> a
 ℕ64
n) ℕ64 -> ℕ64 -> ℕ64
forall a. Minus a => a -> a -> a
- ℕ64
h
      hdm :: ℕ64
hdm = ℕ64
hd ℕ64 -> ℕ64 -> ℕ64
forall a. DivMod a => a -> a -> a
 ℕ -> ℕ64
𝕟64 2
        -- mmmmmmmm
        -- wwwwwddd
        --        m 
        --
        -- nnnnnnnn
        -- hhhhhddd
        --        m
      f  𝐼A ChunkO  𝐼A ChunkO
      f :: 𝐼A ChunkO -> 𝐼A ChunkO
f = case HAlign
ha of
        -- mmmmmmmmm
        -- XX
        -- →
        -- XX␣␣␣␣␣␣␣
        HAlign
LH  (ℕ64 -> ℕ64) -> (ℕ64 -> ℕ64) -> 𝐼A ChunkO -> 𝐼A ChunkO
forall {a}.
(Monoid a, ASized a, Single ChunkO a) =>
(ℕ64 -> ℕ64) -> (ℕ64 -> ℕ64) -> a -> a
hwrap (ℕ64 -> ℕ64 -> ℕ64
forall a b. a -> b -> a
const ℕ64
forall a. Zero a => a
zero) ((ℕ64 -> ℕ64) -> 𝐼A ChunkO -> 𝐼A ChunkO)
-> (ℕ64 -> ℕ64) -> 𝐼A ChunkO -> 𝐼A ChunkO
forall a b. (a -> b) -> a -> b
$ \ ℕ64
s  ℕ64
m ℕ64 -> ℕ64 -> ℕ64
forall a. Minus a => a -> a -> a
- ℕ64
s
        -- mmmmmmmmm
        -- XX
        -- →
        -- ␣XX␣␣␣␣␣␣
        HAlign
CH  (ℕ64 -> ℕ64) -> (ℕ64 -> ℕ64) -> 𝐼A ChunkO -> 𝐼A ChunkO
forall {a}.
(Monoid a, ASized a, Single ChunkO a) =>
(ℕ64 -> ℕ64) -> (ℕ64 -> ℕ64) -> a -> a
hwrap (ℕ64 -> ℕ64 -> ℕ64
forall a b. a -> b -> a
const ℕ64
wdm) ((ℕ64 -> ℕ64) -> 𝐼A ChunkO -> 𝐼A ChunkO)
-> (ℕ64 -> ℕ64) -> 𝐼A ChunkO -> 𝐼A ChunkO
forall a b. (a -> b) -> a -> b
$ \ ℕ64
s  ℕ64
m ℕ64 -> ℕ64 -> ℕ64
forall a. Minus a => a -> a -> a
- ℕ64
s ℕ64 -> ℕ64 -> ℕ64
forall a. Minus a => a -> a -> a
- ℕ64
wdm
        -- mmmmmmmmm
        -- XX
        -- →
        -- ␣␣␣␣␣␣␣XX
        HAlign
RH  (ℕ64 -> ℕ64) -> (ℕ64 -> ℕ64) -> 𝐼A ChunkO -> 𝐼A ChunkO
forall {a}.
(Monoid a, ASized a, Single ChunkO a) =>
(ℕ64 -> ℕ64) -> (ℕ64 -> ℕ64) -> a -> a
hwrap (\ ℕ64
s  ℕ64
m ℕ64 -> ℕ64 -> ℕ64
forall a. Minus a => a -> a -> a
- ℕ64
s) ((ℕ64 -> ℕ64) -> 𝐼A ChunkO -> 𝐼A ChunkO)
-> (ℕ64 -> ℕ64) -> 𝐼A ChunkO -> 𝐼A ChunkO
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ℕ64 -> ℕ64
forall a b. a -> b -> a
const ℕ64
forall a. Zero a => a
zero
      g  Sep () (𝐼A ChunkO)  Sep () (𝐼A ChunkO)
      g :: Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO)
g = case VAlign
va of
        VAlign
TV  ℕ64 -> ℕ64 -> Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO)
forall {a} {p} {p}.
(Monoid a, Eq p, Eq p, Zero p, Zero p, One p, One p, Plus p,
 Plus p) =>
p -> p -> Sep () a -> Sep () a
vwrap (forall a. Zero a => a
zero @ℕ64) (ℕ64 -> Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO))
-> ℕ64 -> Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO)
forall a b. (a -> b) -> a -> b
$ ℕ64
n ℕ64 -> ℕ64 -> ℕ64
forall a. Minus a => a -> a -> a
- ℕ64
h
        VAlign
CV  ℕ64 -> ℕ64 -> Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO)
forall {a} {p} {p}.
(Monoid a, Eq p, Eq p, Zero p, Zero p, One p, One p, Plus p,
 Plus p) =>
p -> p -> Sep () a -> Sep () a
vwrap ℕ64
hdm (ℕ64 -> Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO))
-> ℕ64 -> Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO)
forall a b. (a -> b) -> a -> b
$ ℕ64
n ℕ64 -> ℕ64 -> ℕ64
forall a. Minus a => a -> a -> a
- ℕ64
h ℕ64 -> ℕ64 -> ℕ64
forall a. Minus a => a -> a -> a
- ℕ64
hdm
        VAlign
BV  ℕ64 -> ℕ64 -> Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO)
forall {a} {p} {p}.
(Monoid a, Eq p, Eq p, Zero p, Zero p, One p, One p, Plus p,
 Plus p) =>
p -> p -> Sep () a -> Sep () a
vwrap (ℕ64
n ℕ64 -> ℕ64 -> ℕ64
forall a. Minus a => a -> a -> a
- ℕ64
h) (ℕ64 -> Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO))
-> ℕ64 -> Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO)
forall a b. (a -> b) -> a -> b
$ forall a. Zero a => a
zero @ℕ64
  in Shape -> TreeO -> SummaryO
SummaryO (ℕ64 -> ℕ64 -> Shape
boxShape ℕ64
m ℕ64
n) (TreeO -> SummaryO) -> TreeO -> SummaryO
forall a b. (a -> b) -> a -> b
$ (Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO)) -> TreeO -> TreeO
forall a b. (a -> b) -> 𝑇V Formats a -> 𝑇V Formats b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ((𝐼A ChunkO -> 𝐼A ChunkO)
-> Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO)
forall a b. (a -> b) -> Sep () a -> Sep () b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map 𝐼A ChunkO -> 𝐼A ChunkO
f (Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO))
-> (Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO))
-> Sep () (𝐼A ChunkO)
-> Sep () (𝐼A ChunkO)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 Sep () (𝐼A ChunkO) -> Sep () (𝐼A ChunkO)
g) TreeO
cs
  where
    hwrap :: (ℕ64 -> ℕ64) -> (ℕ64 -> ℕ64) -> a -> a
hwrap ℕ64 -> ℕ64
fi ℕ64 -> ℕ64
fj a
xs =
      let s :: ℕ64
s = a -> ℕ64
forall a. ASized a => a -> ℕ64
asize a
xs
          i :: ℕ64
i = ℕ64 -> ℕ64
fi ℕ64
s
          j :: ℕ64
j = ℕ64 -> ℕ64
fj ℕ64
s
      in [a] -> a
forall a t. (Monoid a, ToIter a t) => t -> a
concat
        [ if ℕ64
i ℕ64 -> ℕ64 -> Bool
forall a. Eq a => a -> a -> Bool
 ℕ64
forall a. Zero a => a
zero then a
forall a. Null a => a
null else ChunkO -> a
forall a t. Single a t => a -> t
single (ChunkO -> a) -> ChunkO -> a
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ChunkO
PaddingChunkO ℕ64
i
        , a
xs 
        , if ℕ64
j ℕ64 -> ℕ64 -> Bool
forall a. Eq a => a -> a -> Bool
 ℕ64
forall a. Zero a => a
zero then a
forall a. Null a => a
null else ChunkO -> a
forall a t. Single a t => a -> t
single (ChunkO -> a) -> ChunkO -> a
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ChunkO
PaddingChunkO ℕ64
j
        ]
    vwrap :: p -> p -> Sep () a -> Sep () a
vwrap p
i p
j Sep () a
xs =
      [Sep () a] -> Sep () a
forall a t. (Monoid a, ToIter a t) => t -> a
concat
      [ 𝐼 (Sep () a) -> Sep () a
forall a t. (Monoid a, ToIter a t) => t -> a
concat (𝐼 (Sep () a) -> Sep () a) -> 𝐼 (Sep () a) -> Sep () a
forall a b. (a -> b) -> a -> b
$ p -> Sep () a -> 𝐼 (Sep () a)
forall n a. (Eq n, Zero n, One n, Plus n) => n -> a -> 𝐼 a
replicate p
i (Sep () a -> 𝐼 (Sep () a)) -> Sep () a -> 𝐼 (Sep () a)
forall a b. (a -> b) -> a -> b
$ () -> Sep () a
forall a i. Null a => i -> Sep i a
sepI ()
      , Sep () a
xs
      , 𝐼 (Sep () a) -> Sep () a
forall a t. (Monoid a, ToIter a t) => t -> a
concat (𝐼 (Sep () a) -> Sep () a) -> 𝐼 (Sep () a) -> Sep () a
forall a b. (a -> b) -> a -> b
$ p -> Sep () a -> 𝐼 (Sep () a)
forall n a. (Eq n, Zero n, One n, Plus n) => n -> a -> 𝐼 a
replicate p
j (Sep () a -> 𝐼 (Sep () a)) -> Sep () a -> 𝐼 (Sep () a)
forall a b. (a -> b) -> a -> b
$ () -> Sep () a
forall a i. Null a => i -> Sep i a
sepI ()
      ]