module Darcs.Patch.Bracketed
( Bracketed(..), mapBracketed, unBracketed
, BracketedFL, mapBracketedFLFL, unBracketedFL
) where
import Darcs.Prelude
import Darcs.Patch.Format ( PatchListFormat )
import Darcs.Patch.Show ( ShowPatchBasic(..) )
import Darcs.Patch.Witnesses.Ordered ( FL(..), mapFL, mapFL_FL, concatFL )
import Darcs.Util.Printer ( vcat, blueText, ($$) )
data Bracketed p wX wY where
Singleton :: p wX wY -> Bracketed p wX wY
Braced :: BracketedFL p wX wY -> Bracketed p wX wY
Parens :: BracketedFL p wX wY -> Bracketed p wX wY
type BracketedFL p wX wY = FL (Bracketed p) wX wY
unBracketed :: Bracketed p wX wY -> FL p wX wY
unBracketed (Singleton p) = p :>: NilFL
unBracketed (Braced ps) = unBracketedFL ps
unBracketed (Parens ps) = unBracketedFL ps
unBracketedFL :: BracketedFL p wX wY -> FL p wX wY
unBracketedFL = concatFL . mapFL_FL unBracketed
mapBracketed :: (forall wA wB . p wA wB -> q wA wB) -> Bracketed p wX wY -> Bracketed q wX wY
mapBracketed f (Singleton p) = Singleton (f p)
mapBracketed f (Braced ps) = Braced (mapBracketedFLFL f ps)
mapBracketed f (Parens ps) = Parens (mapBracketedFLFL f ps)
mapBracketedFLFL :: (forall wA wB . p wA wB -> q wA wB) -> BracketedFL p wX wY -> BracketedFL q wX wY
mapBracketedFLFL f = mapFL_FL (mapBracketed f)
instance PatchListFormat (Bracketed p)
instance ShowPatchBasic p => ShowPatchBasic (Bracketed p) where
showPatch f (Singleton p) = showPatch f p
showPatch _ (Braced NilFL) = blueText "{" $$ blueText "}"
showPatch f (Braced ps) = blueText "{" $$ vcat (mapFL (showPatch f) ps) $$ blueText "}"
showPatch f (Parens ps) = blueText "(" $$ vcat (mapFL (showPatch f) ps) $$ blueText ")"