module Language.Haskell.Brittany.Internal.Transformations.Floating
( transformSimplifyFloating
)
where
#include "prelude.inc"
import Language.Haskell.Brittany.Internal.Utils
import Language.Haskell.Brittany.Internal.Config.Types
import Language.Haskell.Brittany.Internal.Types
import qualified Data.Generics.Uniplate.Direct as Uniplate
mergeIndents :: BrIndent -> BrIndent -> BrIndent
mergeIndents :: BrIndent -> BrIndent -> BrIndent
mergeIndents BrIndent
BrIndentNone BrIndent
x = BrIndent
x
mergeIndents BrIndent
x BrIndent
BrIndentNone = BrIndent
x
mergeIndents (BrIndentSpecial Int
i) (BrIndentSpecial Int
j) = Int -> BrIndent
BrIndentSpecial (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
i Int
j)
mergeIndents BrIndent
_ BrIndent
_ = [Char] -> BrIndent
forall a. HasCallStack => [Char] -> a
error [Char]
"mergeIndents"
transformSimplifyFloating :: BriDoc -> BriDoc
transformSimplifyFloating :: BriDoc -> BriDoc
transformSimplifyFloating = BriDoc -> BriDoc
stepBO (BriDoc -> BriDoc) -> (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b c. (a -> b) -> (b -> c) -> a -> c
.> BriDoc -> BriDoc
stepFull
where
descendPrior :: BriDoc -> BriDoc
descendPrior = (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall on. Uniplate on => (on -> Maybe on) -> on -> on
transformDownMay ((BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc)
-> (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ \case
BDAnnotationPrior AnnKey
annKey1 (BDPar BrIndent
ind BriDoc
line BriDoc
indented) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc -> BriDoc
BDPar BrIndent
ind (AnnKey -> BriDoc -> BriDoc
BDAnnotationPrior AnnKey
annKey1 BriDoc
line) BriDoc
indented
BDAnnotationPrior AnnKey
annKey1 (BDSeq (BriDoc
l:[BriDoc]
lr)) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDSeq (AnnKey -> BriDoc -> BriDoc
BDAnnotationPrior AnnKey
annKey1 BriDoc
lBriDoc -> [BriDoc] -> [BriDoc]
forall a. a -> [a] -> [a]
:[BriDoc]
lr)
BDAnnotationPrior AnnKey
annKey1 (BDLines (BriDoc
l:[BriDoc]
lr)) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDLines (AnnKey -> BriDoc -> BriDoc
BDAnnotationPrior AnnKey
annKey1 BriDoc
lBriDoc -> [BriDoc] -> [BriDoc]
forall a. a -> [a] -> [a]
:[BriDoc]
lr)
BDAnnotationPrior AnnKey
annKey1 (BDCols ColSig
sig (BriDoc
l:[BriDoc]
lr)) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ ColSig -> [BriDoc] -> BriDoc
BDCols ColSig
sig (AnnKey -> BriDoc -> BriDoc
BDAnnotationPrior AnnKey
annKey1 BriDoc
lBriDoc -> [BriDoc] -> [BriDoc]
forall a. a -> [a] -> [a]
:[BriDoc]
lr)
BDAnnotationPrior AnnKey
annKey1 (BDAddBaseY BrIndent
indent BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
indent (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> BriDoc -> BriDoc
BDAnnotationPrior AnnKey
annKey1 BriDoc
x
BDAnnotationPrior AnnKey
annKey1 (BDDebug [Char]
s BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [Char] -> BriDoc -> BriDoc
BDDebug [Char]
s (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> BriDoc -> BriDoc
BDAnnotationPrior AnnKey
annKey1 BriDoc
x
BriDoc
_ -> Maybe BriDoc
forall a. Maybe a
Nothing
descendRest :: BriDoc -> BriDoc
descendRest = (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall on. Uniplate on => (on -> Maybe on) -> on -> on
transformDownMay ((BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc)
-> (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ \case
BDAnnotationRest AnnKey
annKey1 (BDPar BrIndent
ind BriDoc
line BriDoc
indented) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc -> BriDoc
BDPar BrIndent
ind BriDoc
line (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> BriDoc -> BriDoc
BDAnnotationRest AnnKey
annKey1 BriDoc
indented
BDAnnotationRest AnnKey
annKey1 (BDSeq [BriDoc]
list) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDSeq ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
list [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [AnnKey -> BriDoc -> BriDoc
BDAnnotationRest AnnKey
annKey1 (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
list]
BDAnnotationRest AnnKey
annKey1 (BDLines [BriDoc]
list) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDLines ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
list [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [AnnKey -> BriDoc -> BriDoc
BDAnnotationRest AnnKey
annKey1 (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
list]
BDAnnotationRest AnnKey
annKey1 (BDCols ColSig
sig [BriDoc]
cols) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ ColSig -> [BriDoc] -> BriDoc
BDCols ColSig
sig ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
cols [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [AnnKey -> BriDoc -> BriDoc
BDAnnotationRest AnnKey
annKey1 (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
cols]
BDAnnotationRest AnnKey
annKey1 (BDAddBaseY BrIndent
indent BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
indent (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> BriDoc -> BriDoc
BDAnnotationRest AnnKey
annKey1 BriDoc
x
BDAnnotationRest AnnKey
annKey1 (BDDebug [Char]
s BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [Char] -> BriDoc -> BriDoc
BDDebug [Char]
s (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> BriDoc -> BriDoc
BDAnnotationRest AnnKey
annKey1 BriDoc
x
BriDoc
_ -> Maybe BriDoc
forall a. Maybe a
Nothing
descendKW :: BriDoc -> BriDoc
descendKW = (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall on. Uniplate on => (on -> Maybe on) -> on -> on
transformDownMay ((BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc)
-> (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ \case
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw (BDPar BrIndent
ind BriDoc
line BriDoc
indented) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc -> BriDoc
BDPar BrIndent
ind BriDoc
line (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> Maybe AnnKeywordId -> BriDoc -> BriDoc
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw BriDoc
indented
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw (BDSeq [BriDoc]
list) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDSeq ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
list [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [AnnKey -> Maybe AnnKeywordId -> BriDoc -> BriDoc
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
list]
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw (BDLines [BriDoc]
list) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDLines ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
list [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [AnnKey -> Maybe AnnKeywordId -> BriDoc -> BriDoc
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
list]
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw (BDCols ColSig
sig [BriDoc]
cols) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ ColSig -> [BriDoc] -> BriDoc
BDCols ColSig
sig ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
cols [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [AnnKey -> Maybe AnnKeywordId -> BriDoc -> BriDoc
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
cols]
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw (BDAddBaseY BrIndent
indent BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
indent (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> Maybe AnnKeywordId -> BriDoc -> BriDoc
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw BriDoc
x
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw (BDDebug [Char]
s BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [Char] -> BriDoc -> BriDoc
BDDebug [Char]
s (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> Maybe AnnKeywordId -> BriDoc -> BriDoc
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw BriDoc
x
BriDoc
_ -> Maybe BriDoc
forall a. Maybe a
Nothing
descendBYPush :: BriDoc -> BriDoc
descendBYPush = (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall on. Uniplate on => (on -> Maybe on) -> on -> on
transformDownMay ((BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc)
-> (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ \case
BDBaseYPushCur (BDCols ColSig
sig cols :: [BriDoc]
cols@(BriDoc
_:[BriDoc]
_)) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ ColSig -> [BriDoc] -> BriDoc
BDCols ColSig
sig (BriDoc -> BriDoc
BDBaseYPushCur ([BriDoc] -> BriDoc
forall a. [a] -> a
List.head [BriDoc]
cols) BriDoc -> [BriDoc] -> [BriDoc]
forall a. a -> [a] -> [a]
: [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.tail [BriDoc]
cols)
BDBaseYPushCur (BDDebug [Char]
s BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [Char] -> BriDoc -> BriDoc
BDDebug [Char]
s (BriDoc -> BriDoc
BDBaseYPushCur BriDoc
x)
BriDoc
_ -> Maybe BriDoc
forall a. Maybe a
Nothing
descendBYPop :: BriDoc -> BriDoc
descendBYPop = (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall on. Uniplate on => (on -> Maybe on) -> on -> on
transformDownMay ((BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc)
-> (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ \case
BDBaseYPop (BDCols ColSig
sig cols :: [BriDoc]
cols@(BriDoc
_:[BriDoc]
_)) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ ColSig -> [BriDoc] -> BriDoc
BDCols ColSig
sig ([BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
cols [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [BriDoc -> BriDoc
BDBaseYPop ([BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
cols)])
BDBaseYPop (BDDebug [Char]
s BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [Char] -> BriDoc -> BriDoc
BDDebug [Char]
s (BriDoc -> BriDoc
BDBaseYPop BriDoc
x)
BriDoc
_ -> Maybe BriDoc
forall a. Maybe a
Nothing
descendILPush :: BriDoc -> BriDoc
descendILPush = (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall on. Uniplate on => (on -> Maybe on) -> on -> on
transformDownMay ((BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc)
-> (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ \case
BDIndentLevelPushCur (BDCols ColSig
sig cols :: [BriDoc]
cols@(BriDoc
_:[BriDoc]
_)) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ ColSig -> [BriDoc] -> BriDoc
BDCols ColSig
sig (BriDoc -> BriDoc
BDIndentLevelPushCur ([BriDoc] -> BriDoc
forall a. [a] -> a
List.head [BriDoc]
cols) BriDoc -> [BriDoc] -> [BriDoc]
forall a. a -> [a] -> [a]
: [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.tail [BriDoc]
cols)
BDIndentLevelPushCur (BDDebug [Char]
s BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [Char] -> BriDoc -> BriDoc
BDDebug [Char]
s (BriDoc -> BriDoc
BDIndentLevelPushCur BriDoc
x)
BriDoc
_ -> Maybe BriDoc
forall a. Maybe a
Nothing
descendILPop :: BriDoc -> BriDoc
descendILPop = (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall on. Uniplate on => (on -> Maybe on) -> on -> on
transformDownMay ((BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc)
-> (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ \case
BDIndentLevelPop (BDCols ColSig
sig cols :: [BriDoc]
cols@(BriDoc
_:[BriDoc]
_)) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ ColSig -> [BriDoc] -> BriDoc
BDCols ColSig
sig ([BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
cols [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [BriDoc -> BriDoc
BDIndentLevelPop ([BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
cols)])
BDIndentLevelPop (BDDebug [Char]
s BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [Char] -> BriDoc -> BriDoc
BDDebug [Char]
s (BriDoc -> BriDoc
BDIndentLevelPop BriDoc
x)
BriDoc
_ -> Maybe BriDoc
forall a. Maybe a
Nothing
descendAddB :: BriDoc -> BriDoc
descendAddB = (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall on. Uniplate on => (on -> Maybe on) -> on -> on
transformDownMay ((BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc)
-> (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ \case
BDAddBaseY BrIndent
BrIndentNone BriDoc
x ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just BriDoc
x
BDAddBaseY BrIndent
indent (BDLines [BriDoc]
lines) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDLines ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
indent (BriDoc -> BriDoc) -> [BriDoc] -> [BriDoc]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BriDoc]
lines
BDAddBaseY BrIndent
indent (BDCols ColSig
sig [BriDoc]
cols) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ ColSig -> [BriDoc] -> BriDoc
BDCols ColSig
sig ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
cols [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
indent (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
cols]
BDAddBaseY BrIndent
ind1 (BDPar BrIndent
ind2 BriDoc
line BriDoc
indented) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc -> BriDoc
BDPar (BrIndent -> BrIndent -> BrIndent
mergeIndents BrIndent
ind1 BrIndent
ind2) BriDoc
line BriDoc
indented
BDAddBaseY BrIndent
ind (BDAnnotationPrior AnnKey
annKey1 BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> BriDoc -> BriDoc
BDAnnotationPrior AnnKey
annKey1 (BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind BriDoc
x)
BDAddBaseY BrIndent
ind (BDAnnotationRest AnnKey
annKey1 BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> BriDoc -> BriDoc
BDAnnotationRest AnnKey
annKey1 (BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind BriDoc
x)
BDAddBaseY BrIndent
ind (BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> Maybe AnnKeywordId -> BriDoc -> BriDoc
BDAnnotationKW AnnKey
annKey1 Maybe AnnKeywordId
kw (BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind BriDoc
x)
BDAddBaseY BrIndent
ind (BDSeq [BriDoc]
list) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDSeq ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
list [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind ([BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
list)]
BDAddBaseY BrIndent
_ lit :: BriDoc
lit@BDLit{} ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BriDoc
lit
BDAddBaseY BrIndent
ind (BDBaseYPushCur BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BriDoc -> BriDoc
BDBaseYPushCur (BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind BriDoc
x)
BDAddBaseY BrIndent
ind (BDBaseYPop BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BriDoc -> BriDoc
BDBaseYPop (BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind BriDoc
x)
BDAddBaseY BrIndent
ind (BDDebug [Char]
s BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [Char] -> BriDoc -> BriDoc
BDDebug [Char]
s (BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind BriDoc
x)
BDAddBaseY BrIndent
ind (BDIndentLevelPop BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BriDoc -> BriDoc
BDIndentLevelPop (BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind BriDoc
x)
BDAddBaseY BrIndent
ind (BDIndentLevelPushCur BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BriDoc -> BriDoc
BDIndentLevelPushCur (BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind BriDoc
x)
BDAddBaseY BrIndent
ind (BDEnsureIndent BrIndent
ind2 BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc
BDEnsureIndent (BrIndent -> BrIndent -> BrIndent
mergeIndents BrIndent
ind BrIndent
ind2) BriDoc
x
BriDoc
_ -> Maybe BriDoc
forall a. Maybe a
Nothing
stepBO :: BriDoc -> BriDoc
stepBO :: BriDoc -> BriDoc
stepBO =
(BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall on. Uniplate on => (on -> on) -> on -> on
transformUp BriDoc -> BriDoc
f
where
f :: BriDoc -> BriDoc
f = \case
x :: BriDoc
x@BDAnnotationPrior{} -> BriDoc -> BriDoc
descendPrior BriDoc
x
x :: BriDoc
x@BDAnnotationKW{} -> BriDoc -> BriDoc
descendKW BriDoc
x
x :: BriDoc
x@BDAnnotationRest{} -> BriDoc -> BriDoc
descendRest BriDoc
x
x :: BriDoc
x@BDAddBaseY{} -> BriDoc -> BriDoc
descendAddB BriDoc
x
x :: BriDoc
x@BDBaseYPushCur{} -> BriDoc -> BriDoc
descendBYPush BriDoc
x
x :: BriDoc
x@BDBaseYPop{} -> BriDoc -> BriDoc
descendBYPop BriDoc
x
x :: BriDoc
x@BDIndentLevelPushCur{} -> BriDoc -> BriDoc
descendILPush BriDoc
x
x :: BriDoc
x@BDIndentLevelPop{} -> BriDoc -> BriDoc
descendILPop BriDoc
x
BriDoc
x -> BriDoc
x
stepFull :: BriDoc -> BriDoc
stepFull =
(BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall on. Uniplate on => (on -> Maybe on) -> on -> on
Uniplate.rewrite ((BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc)
-> (BriDoc -> Maybe BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ \case
BDAddBaseY BrIndent
BrIndentNone BriDoc
x ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BriDoc
x
BDAddBaseY BrIndent
indent (BDLines [BriDoc]
lines) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDLines ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
indent (BriDoc -> BriDoc) -> [BriDoc] -> [BriDoc]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BriDoc]
lines
BDAddBaseY BrIndent
indent (BDCols ColSig
sig [BriDoc]
cols) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ ColSig -> [BriDoc] -> BriDoc
BDCols ColSig
sig ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
cols [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
indent (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
cols]
BDAddBaseY BrIndent
ind (BDSeq [BriDoc]
list) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDSeq ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
list [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind ([BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
list)]
BDAddBaseY BrIndent
ind1 (BDPar BrIndent
ind2 BriDoc
line BriDoc
indented) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc -> BriDoc
BDPar (BrIndent -> BrIndent -> BrIndent
mergeIndents BrIndent
ind1 BrIndent
ind2) BriDoc
line BriDoc
indented
BDAddBaseY BrIndent
_ lit :: BriDoc
lit@BDLit{} ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BriDoc
lit
BDAddBaseY BrIndent
ind (BDBaseYPushCur BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BriDoc -> BriDoc
BDBaseYPushCur (BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind BriDoc
x)
BDAddBaseY BrIndent
ind (BDBaseYPop BriDoc
x) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BriDoc -> BriDoc
BDBaseYPop (BrIndent -> BriDoc -> BriDoc
BDAddBaseY BrIndent
ind BriDoc
x)
BDAnnotationPrior AnnKey
annKey1 (BDPar BrIndent
ind BriDoc
line BriDoc
indented) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc -> BriDoc
BDPar BrIndent
ind (AnnKey -> BriDoc -> BriDoc
BDAnnotationPrior AnnKey
annKey1 BriDoc
line) BriDoc
indented
BDAnnotationPrior AnnKey
annKey1 (BDSeq (BriDoc
l:[BriDoc]
lr)) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDSeq ((AnnKey -> BriDoc -> BriDoc
BDAnnotationPrior AnnKey
annKey1 BriDoc
l)BriDoc -> [BriDoc] -> [BriDoc]
forall a. a -> [a] -> [a]
:[BriDoc]
lr)
BDAnnotationPrior AnnKey
annKey1 (BDLines (BriDoc
l:[BriDoc]
lr)) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDLines ((AnnKey -> BriDoc -> BriDoc
BDAnnotationPrior AnnKey
annKey1 BriDoc
l)BriDoc -> [BriDoc] -> [BriDoc]
forall a. a -> [a] -> [a]
:[BriDoc]
lr)
BDAnnotationPrior AnnKey
annKey1 (BDCols ColSig
sig (BriDoc
l:[BriDoc]
lr)) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ ColSig -> [BriDoc] -> BriDoc
BDCols ColSig
sig ((AnnKey -> BriDoc -> BriDoc
BDAnnotationPrior AnnKey
annKey1 BriDoc
l)BriDoc -> [BriDoc] -> [BriDoc]
forall a. a -> [a] -> [a]
:[BriDoc]
lr)
BDAnnotationRest AnnKey
annKey1 (BDPar BrIndent
ind BriDoc
line BriDoc
indented) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ BrIndent -> BriDoc -> BriDoc -> BriDoc
BDPar BrIndent
ind BriDoc
line (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ AnnKey -> BriDoc -> BriDoc
BDAnnotationRest AnnKey
annKey1 BriDoc
indented
BDAnnotationRest AnnKey
annKey1 (BDSeq [BriDoc]
list) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDSeq ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
list [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [AnnKey -> BriDoc -> BriDoc
BDAnnotationRest AnnKey
annKey1 (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
list]
BDAnnotationRest AnnKey
annKey1 (BDLines [BriDoc]
list) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
BDLines ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
list [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [AnnKey -> BriDoc -> BriDoc
BDAnnotationRest AnnKey
annKey1 (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
list]
BDAnnotationRest AnnKey
annKey1 (BDCols ColSig
sig [BriDoc]
cols) ->
BriDoc -> Maybe BriDoc
forall a. a -> Maybe a
Just (BriDoc -> Maybe BriDoc) -> BriDoc -> Maybe BriDoc
forall a b. (a -> b) -> a -> b
$ ColSig -> [BriDoc] -> BriDoc
BDCols ColSig
sig ([BriDoc] -> BriDoc) -> [BriDoc] -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> [BriDoc]
forall a. [a] -> [a]
List.init [BriDoc]
cols [BriDoc] -> [BriDoc] -> [BriDoc]
forall a. [a] -> [a] -> [a]
++ [AnnKey -> BriDoc -> BriDoc
BDAnnotationRest AnnKey
annKey1 (BriDoc -> BriDoc) -> BriDoc -> BriDoc
forall a b. (a -> b) -> a -> b
$ [BriDoc] -> BriDoc
forall a. [a] -> a
List.last [BriDoc]
cols]
BriDoc
_ -> Maybe BriDoc
forall a. Maybe a
Nothing