{- |
Module      :  ./Common/DocUtils.hs
Description :  Pretty class for pretty printing with instances plus utilities
Copyright   :  (c) jianchun wang and Uni Bremen 2006
License     :  GPLv2 or higher, see LICENSE.txt

Maintainer  :  Christian.Maeder@dfki.de
Stability   :  provisional
Portability :  portable

'Pretty' class for pretty printing, some instances and other utility functions
-}

module Common.DocUtils where

import Common.AS_Annotation
import Common.Doc
import Common.Id
import Common.IRI
import qualified Data.Set as Set
import qualified Data.Map as Map
import Common.GlobalAnnotations

-- * the class stuff
class Show a => Pretty a where
    pretty :: a -> Doc
    pretties :: [a] -> Doc
    pretties = Doc -> Doc
brackets (Doc -> Doc) -> ([a] -> Doc) -> [a] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Doc
forall a. Pretty a => [a] -> Doc
ppWithCommas

instance Pretty Char where
    pretty :: Char -> Doc
pretty c :: Char
c = [Char] -> Doc
text [Char
c]
    pretties :: [Char] -> Doc
pretties = [Char] -> Doc
text ([Char] -> Doc) -> ([Char] -> [Char]) -> [Char] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take 25

instance Pretty () where
    pretty :: () -> Doc
pretty () = Doc
empty

instance Pretty Id where
    pretty :: Id -> Doc
pretty = Id -> Doc
idDoc

instance Pretty Annotation where
    pretty :: Annotation -> Doc
pretty = Annotation -> Doc
annoDoc

instance Pretty Token where
   pretty :: Token -> Doc
pretty = Token -> Doc
sidDoc

-- | convert a token to a document (different from 'text' for LaTex)
sidDoc :: Token -> Doc
sidDoc :: Token -> Doc
sidDoc = Id -> Doc
idDoc (Id -> Doc) -> (Token -> Id) -> Token -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Token -> Id
simpleIdToId

-- | print several annotations vertically (each in a new line)
printAnnotationList :: [Annotation] -> Doc
printAnnotationList :: [Annotation] -> Doc
printAnnotationList = [Doc] -> Doc
vcat ([Doc] -> Doc) -> ([Annotation] -> [Doc]) -> [Annotation] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Annotation -> Doc) -> [Annotation] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Annotation -> Doc
annoDoc

-- | print annotations flush right
printTrailer :: [Annotation] -> Doc
printTrailer :: [Annotation] -> Doc
printTrailer = Doc -> Doc
flushRight (Doc -> Doc) -> ([Annotation] -> Doc) -> [Annotation] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
hsep ([Doc] -> Doc) -> ([Annotation] -> [Doc]) -> [Annotation] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Annotation -> Doc) -> [Annotation] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Annotation -> Doc
annoDoc

-- | add trailing annotation to a document
splitAndPrintRAnnos :: Doc -> [Annotation] -> Doc
splitAndPrintRAnnos :: Doc -> [Annotation] -> Doc
splitAndPrintRAnnos i :: Doc
i ras :: [Annotation]
ras =
    let (r :: [Annotation]
r, s :: [Annotation]
s) = [Annotation] -> ([Annotation], [Annotation])
splitRAnnos [Annotation]
ras
    in (if [Annotation] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Annotation]
s then Doc -> Doc
forall a. a -> a
id else (Doc -> Doc -> Doc
$+$ [Annotation] -> Doc
printAnnotationList [Annotation]
s))
       (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ if [Annotation] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Annotation]
r then Doc
i else [Doc] -> Doc
fsep [Doc
i, [Annotation] -> Doc
printTrailer [Annotation]
r]

-- | conditionally add a 'semi' after the doc but before trailing annotations
printSemiAnno :: (a -> Doc) -> Bool -> Annoted a -> Doc
printSemiAnno :: (a -> Doc) -> Bool -> Annoted a -> Doc
printSemiAnno pp :: a -> Doc
pp addSemi :: Bool
addSemi (Annoted i :: a
i _ las :: [Annotation]
las ras :: [Annotation]
ras) =
    let r :: Doc
r = Doc -> [Annotation] -> Doc
splitAndPrintRAnnos
            ((if Bool
addSemi then (Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
semi) else Doc -> Doc
forall a. a -> a
id) (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ a -> Doc
pp a
i) [Annotation]
ras
    in if [Annotation] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Annotation]
las then Doc
r else
           (if [Annotation] -> Bool
startsWithSemanticAnno [Annotation]
las then Doc -> Doc
forall a. a -> a
id else ([Char] -> Doc
text "" Doc -> Doc -> Doc
$+$))
              (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Annotation] -> Doc
printAnnotationList [Annotation]
las Doc -> Doc -> Doc
$+$ Doc
r

-- | test for semantic annos before structured specs
startsWithSemanticAnno :: [Annotation] -> Bool
startsWithSemanticAnno :: [Annotation] -> Bool
startsWithSemanticAnno l :: [Annotation]
l = case [Annotation]
l of
    Semantic_anno _ _ : _ -> Bool
True
    _ -> Bool
False

-- | print annoted items with trailing semicolons except for the last item
semiAnnos :: (a -> Doc) -> [Annoted a] -> Doc
semiAnnos :: (a -> Doc) -> [Annoted a] -> Doc
semiAnnos pp :: a -> Doc
pp l :: [Annoted a]
l = if [Annoted a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Annoted a]
l then Doc
empty else
           [Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Annoted a -> Doc) -> [Annoted a] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ((a -> Doc) -> Bool -> Annoted a -> Doc
forall a. (a -> Doc) -> Bool -> Annoted a -> Doc
printSemiAnno a -> Doc
pp Bool
True) ([Annoted a] -> [Annoted a]
forall a. [a] -> [a]
init [Annoted a]
l)
                [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [(a -> Doc) -> Annoted a -> Doc
forall a. (a -> Doc) -> Annoted a -> Doc
printAnnoted a -> Doc
pp (Annoted a -> Doc) -> Annoted a -> Doc
forall a b. (a -> b) -> a -> b
$ [Annoted a] -> Annoted a
forall a. [a] -> a
last [Annoted a]
l]

-- | print sentence with label and non-axioms with implied annotation
printAnnoted :: (a -> Doc) -> Annoted a -> Doc
printAnnoted :: (a -> Doc) -> Annoted a -> Doc
printAnnoted pp :: a -> Doc
pp = (a -> Doc) -> Bool -> Annoted a -> Doc
forall a. (a -> Doc) -> Bool -> Annoted a -> Doc
printSemiAnno a -> Doc
pp Bool
False

instance (Pretty a) => Pretty (Annoted a) where
    pretty :: Annoted a -> Doc
pretty = (a -> Doc) -> Annoted a -> Doc
forall a. (a -> Doc) -> Annoted a -> Doc
printAnnoted a -> Doc
forall a. Pretty a => a -> Doc
pretty

-- | convert a named sentence into an annoted one
fromLabelledSen :: Named s -> Annoted s
fromLabelledSen :: Named s -> Annoted s
fromLabelledSen s :: Named s
s = let label :: [Char]
label = Named s -> [Char]
forall s a. SenAttr s a -> a
senAttr Named s
s in
    Annoted s -> [Annotation] -> Annoted s
forall a. Annoted a -> [Annotation] -> Annoted a
appendAnno (s -> Annoted s
forall a. a -> Annoted a
emptyAnno (s -> Annoted s) -> s -> Annoted s
forall a b. (a -> b) -> a -> b
$ Named s -> s
forall s a. SenAttr s a -> s
sentence Named s
s) ([Annotation] -> Annoted s) -> [Annotation] -> Annoted s
forall a b. (a -> b) -> a -> b
$
    (if [Char] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
label then [] else [[[Char]] -> Range -> Annotation
Label [[Char]
label] Range
nullRange])
    [Annotation] -> [Annotation] -> [Annotation]
forall a. [a] -> [a] -> [a]
++ if Named s -> Bool
forall s a. SenAttr s a -> Bool
isAxiom Named s
s then [] else [Semantic_anno -> Range -> Annotation
Semantic_anno Semantic_anno
SA_implied Range
nullRange]

{- | function to split the annotation to the right of an item.
* fst contains printed label and implied annotion
  if any at the begining of the list of annotations
* snd contains the remaining annos -}
splitRAnnos :: [Annotation] -> ([Annotation], [Annotation])
splitRAnnos :: [Annotation] -> ([Annotation], [Annotation])
splitRAnnos r :: [Annotation]
r = case [Annotation]
r of
    [l :: Annotation
l] | Annotation -> Bool
isLabel Annotation
l Bool -> Bool -> Bool
|| Annotation -> Bool
isImplied Annotation
l -> ([Annotation]
r, [])
    l :: Annotation
l : s :: [Annotation]
s@(i :: Annotation
i : t :: [Annotation]
t)
      | Annotation -> Bool
isLabel Annotation
l ->
            if Annotation -> Bool
isImplied Annotation
i then ([Annotation
l, Annotation
i], [Annotation]
t)
            else ([Annotation
l], [Annotation]
s)
      | Annotation -> Bool
isImplied Annotation
l -> ([Annotation
l], [Annotation]
s)
    _ -> ([], [Annotation]
r)

-- | add global annotations for proper mixfix printing
useGlobalAnnos :: GlobalAnnos -> Doc -> Doc
useGlobalAnnos :: GlobalAnnos -> Doc -> Doc
useGlobalAnnos = (GlobalAnnos -> GlobalAnnos) -> Doc -> Doc
changeGlobalAnnos ((GlobalAnnos -> GlobalAnnos) -> Doc -> Doc)
-> (GlobalAnnos -> GlobalAnnos -> GlobalAnnos)
-> GlobalAnnos
-> Doc
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GlobalAnnos -> GlobalAnnos -> GlobalAnnos
forall a b. a -> b -> a
const

-- | like punctuate but prepends the symbol to all tail elements
prepPunctuate :: Doc -> [Doc] -> [Doc]
prepPunctuate :: Doc -> [Doc] -> [Doc]
prepPunctuate s :: Doc
s l :: [Doc]
l = case [Doc]
l of
    x :: Doc
x : r :: [Doc]
r@(_ : _) -> Doc
x Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: (Doc -> Doc) -> [Doc] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Doc
s Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<>) [Doc]
r
    _ -> [Doc]
l

instance (Pretty a, Pretty b) => Pretty (Either a b) where
    pretty :: Either a b -> Doc
pretty = (a -> Doc) -> (b -> Doc) -> Either a b -> Doc
forall a b. (a -> Doc) -> (b -> Doc) -> Either a b -> Doc
printEither a -> Doc
forall a. Pretty a => a -> Doc
pretty b -> Doc
forall a. Pretty a => a -> Doc
pretty

printEither :: (a -> Doc) -> (b -> Doc) -> Either a b -> Doc
printEither :: (a -> Doc) -> (b -> Doc) -> Either a b -> Doc
printEither fA :: a -> Doc
fA fB :: b -> Doc
fB ei :: Either a b
ei = case Either a b
ei of
    Left x :: a
x -> a -> Doc
fA a
x
    Right x :: b
x -> b -> Doc
fB b
x

instance Pretty a => Pretty (Maybe a) where
    pretty :: Maybe a -> Doc
pretty = (a -> Doc) -> Maybe a -> Doc
forall a. (a -> Doc) -> Maybe a -> Doc
printMaybe a -> Doc
forall a. Pretty a => a -> Doc
pretty

printMaybe :: (a -> Doc) -> Maybe a -> Doc
printMaybe :: (a -> Doc) -> Maybe a -> Doc
printMaybe fA :: a -> Doc
fA mb :: Maybe a
mb = case Maybe a
mb of
    Just x :: a
x -> a -> Doc
fA a
x
    Nothing -> Doc
empty

ppWithCommas :: Pretty a => [a] -> Doc
ppWithCommas :: [a] -> Doc
ppWithCommas = [Doc] -> Doc
sepByCommas ([Doc] -> Doc) -> ([a] -> [Doc]) -> [a] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Doc) -> [a] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map a -> Doc
forall a. Pretty a => a -> Doc
pretty

instance (Pretty a, Pretty b) => Pretty (a, b) where
    pretty :: (a, b) -> Doc
pretty = (a -> Doc) -> (b -> Doc) -> (a, b) -> Doc
forall a b. (a -> Doc) -> (b -> Doc) -> (a, b) -> Doc
printPair a -> Doc
forall a. Pretty a => a -> Doc
pretty b -> Doc
forall a. Pretty a => a -> Doc
pretty

printPair :: (a -> Doc) -> (b -> Doc) -> (a, b) -> Doc
printPair :: (a -> Doc) -> (b -> Doc) -> (a, b) -> Doc
printPair fA :: a -> Doc
fA fB :: b -> Doc
fB (a :: a
a, b :: b
b) = Doc -> Doc
parens (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sepByCommas [a -> Doc
fA a
a, b -> Doc
fB b
b]

instance (Pretty a, Pretty b, Pretty c) => Pretty (a, b, c) where
    pretty :: (a, b, c) -> Doc
pretty = (a -> Doc) -> (b -> Doc) -> (c -> Doc) -> (a, b, c) -> Doc
forall a b c.
(a -> Doc) -> (b -> Doc) -> (c -> Doc) -> (a, b, c) -> Doc
printTriple a -> Doc
forall a. Pretty a => a -> Doc
pretty b -> Doc
forall a. Pretty a => a -> Doc
pretty c -> Doc
forall a. Pretty a => a -> Doc
pretty

printTriple :: (a -> Doc) -> (b -> Doc) -> (c -> Doc) -> (a, b, c) -> Doc
printTriple :: (a -> Doc) -> (b -> Doc) -> (c -> Doc) -> (a, b, c) -> Doc
printTriple fA :: a -> Doc
fA fB :: b -> Doc
fB fC :: c -> Doc
fC (a :: a
a, b :: b
b, c :: c
c) = Doc -> Doc
parens (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sepByCommas [a -> Doc
fA a
a, b -> Doc
fB b
b, c -> Doc
fC c
c]

instance (Pretty a, Pretty b, Pretty c, Pretty d) => Pretty (a, b, c, d) where
    pretty :: (a, b, c, d) -> Doc
pretty (a :: a
a, b :: b
b, c :: c
c, d :: d
d) =
      Doc -> Doc
parens (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sepByCommas [a -> Doc
forall a. Pretty a => a -> Doc
pretty a
a, b -> Doc
forall a. Pretty a => a -> Doc
pretty b
b, c -> Doc
forall a. Pretty a => a -> Doc
pretty c
c, d -> Doc
forall a. Pretty a => a -> Doc
pretty d
d]

instance Pretty Int where
    pretty :: Int -> Doc
pretty = Token -> Doc
sidDoc (Token -> Doc) -> (Int -> Token) -> Int -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Token
mkSimpleId ([Char] -> Token) -> (Int -> [Char]) -> Int -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Char]
forall a. Show a => a -> [Char]
show

instance Pretty Integer where
    pretty :: Integer -> Doc
pretty = Token -> Doc
sidDoc (Token -> Doc) -> (Integer -> Token) -> Integer -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Token
mkSimpleId ([Char] -> Token) -> (Integer -> [Char]) -> Integer -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> [Char]
forall a. Show a => a -> [Char]
show

instance Pretty a => Pretty [a] where
    pretty :: [a] -> Doc
pretty = [a] -> Doc
forall a. Pretty a => [a] -> Doc
pretties

instance Pretty a => Pretty (Set.Set a) where
    pretty :: Set a -> Doc
pretty = (Doc -> Doc) -> ([Doc] -> Doc) -> Set a -> Doc
forall a.
Pretty a =>
(Doc -> Doc) -> ([Doc] -> Doc) -> Set a -> Doc
printSet Doc -> Doc
braces [Doc] -> Doc
sepByCommas

-- | container size
data CSize = CEmpty | CSingle | CMult

ppList :: (a -> Doc) -> (CSize -> Doc -> Doc) -> ([Doc] -> Doc) -> [a] -> Doc
ppList :: (a -> Doc) -> (CSize -> Doc -> Doc) -> ([Doc] -> Doc) -> [a] -> Doc
ppList fa :: a -> Doc
fa brace :: CSize -> Doc -> Doc
brace inter :: [Doc] -> Doc
inter l :: [a]
l = case [a]
l of
  [] -> CSize -> Doc -> Doc
brace CSize
CEmpty Doc
empty
  [e :: a
e] -> CSize -> Doc -> Doc
brace CSize
CSingle (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ a -> Doc
fa a
e
  _ -> CSize -> Doc -> Doc
brace CSize
CMult (Doc -> Doc) -> ([Doc] -> Doc) -> [Doc] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
inter ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (a -> Doc) -> [a] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map a -> Doc
fa [a]
l

ppSet :: (a -> Doc) -> (CSize -> Doc -> Doc) -> ([Doc] -> Doc)
  -> Set.Set a -> Doc
ppSet :: (a -> Doc)
-> (CSize -> Doc -> Doc) -> ([Doc] -> Doc) -> Set a -> Doc
ppSet fa :: a -> Doc
fa brace :: CSize -> Doc -> Doc
brace inter :: [Doc] -> Doc
inter = (a -> Doc) -> (CSize -> Doc -> Doc) -> ([Doc] -> Doc) -> [a] -> Doc
forall a.
(a -> Doc) -> (CSize -> Doc -> Doc) -> ([Doc] -> Doc) -> [a] -> Doc
ppList a -> Doc
fa CSize -> Doc -> Doc
brace [Doc] -> Doc
inter ([a] -> Doc) -> (Set a -> [a]) -> Set a -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set a -> [a]
forall a. Set a -> [a]
Set.toList

optBraces :: CSize -> Doc -> Doc
optBraces :: CSize -> Doc -> Doc
optBraces c :: CSize
c = case CSize
c of
  CSingle -> Doc -> Doc
forall a. a -> a
id
  _ -> Doc -> Doc
braces

printSet :: Pretty a => (Doc -> Doc) -> ([Doc] -> Doc) -> Set.Set a -> Doc
printSet :: (Doc -> Doc) -> ([Doc] -> Doc) -> Set a -> Doc
printSet = (a -> Doc)
-> (CSize -> Doc -> Doc) -> ([Doc] -> Doc) -> Set a -> Doc
forall a.
(a -> Doc)
-> (CSize -> Doc -> Doc) -> ([Doc] -> Doc) -> Set a -> Doc
ppSet a -> Doc
forall a. Pretty a => a -> Doc
pretty ((CSize -> Doc -> Doc) -> ([Doc] -> Doc) -> Set a -> Doc)
-> ((Doc -> Doc) -> CSize -> Doc -> Doc)
-> (Doc -> Doc)
-> ([Doc] -> Doc)
-> Set a
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Doc -> Doc) -> CSize -> Doc -> Doc
forall a b. a -> b -> a
const

printSetMap :: (Pretty k, Pretty a) => Doc -> Doc -> Map.Map k (Set.Set a)
  -> Doc
printSetMap :: Doc -> Doc -> Map k (Set a) -> Doc
printSetMap header :: Doc
header sepa :: Doc
sepa = [Doc] -> Doc
vcat ([Doc] -> Doc) -> (Map k (Set a) -> [Doc]) -> Map k (Set a) -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((k, Set a) -> [Doc]) -> [(k, Set a)] -> [Doc]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ( \ (i :: k
i, s :: Set a
s) ->
    (a -> Doc) -> [a] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ( \ e :: a
e -> Doc
header Doc -> Doc -> Doc
<+> k -> Doc
forall a. Pretty a => a -> Doc
pretty k
i Doc -> Doc -> Doc
<+> Doc
colon Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
sepa Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> a -> Doc
forall a. Pretty a => a -> Doc
pretty a
e)
            ([a] -> [Doc]) -> [a] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Set a -> [a]
forall a. Set a -> [a]
Set.toList Set a
s) ([(k, Set a)] -> [Doc])
-> (Map k (Set a) -> [(k, Set a)]) -> Map k (Set a) -> [Doc]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k (Set a) -> [(k, Set a)]
forall k a. Map k a -> [(k, a)]
Map.toList

printMap :: (Pretty a, Pretty b) => (Doc -> Doc) -> ([Doc] -> Doc)
         -> (Doc -> Doc -> Doc) -> Map.Map a b -> Doc
printMap :: (Doc -> Doc)
-> ([Doc] -> Doc) -> (Doc -> Doc -> Doc) -> Map a b -> Doc
printMap = (a -> Doc)
-> (b -> Doc)
-> (CSize -> Doc -> Doc)
-> ([Doc] -> Doc)
-> (Doc -> Doc -> Doc)
-> Map a b
-> Doc
forall a b.
(a -> Doc)
-> (b -> Doc)
-> (CSize -> Doc -> Doc)
-> ([Doc] -> Doc)
-> (Doc -> Doc -> Doc)
-> Map a b
-> Doc
ppMap a -> Doc
forall a. Pretty a => a -> Doc
pretty b -> Doc
forall a. Pretty a => a -> Doc
pretty ((CSize -> Doc -> Doc)
 -> ([Doc] -> Doc) -> (Doc -> Doc -> Doc) -> Map a b -> Doc)
-> ((Doc -> Doc) -> CSize -> Doc -> Doc)
-> (Doc -> Doc)
-> ([Doc] -> Doc)
-> (Doc -> Doc -> Doc)
-> Map a b
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Doc -> Doc) -> CSize -> Doc -> Doc
forall a b. a -> b -> a
const

ppMap :: (a -> Doc) -> (b -> Doc) -> (CSize -> Doc -> Doc) -> ([Doc] -> Doc)
      -> (Doc -> Doc -> Doc) -> Map.Map a b -> Doc
ppMap :: (a -> Doc)
-> (b -> Doc)
-> (CSize -> Doc -> Doc)
-> ([Doc] -> Doc)
-> (Doc -> Doc -> Doc)
-> Map a b
-> Doc
ppMap fa :: a -> Doc
fa fb :: b -> Doc
fb brace :: CSize -> Doc -> Doc
brace inter :: [Doc] -> Doc
inter pairDoc :: Doc -> Doc -> Doc
pairDoc =
    (a -> Doc)
-> (b -> Doc)
-> (CSize -> Doc -> Doc)
-> ([Doc] -> Doc)
-> (Doc -> Doc -> Doc)
-> [(a, b)]
-> Doc
forall a b.
(a -> Doc)
-> (b -> Doc)
-> (CSize -> Doc -> Doc)
-> ([Doc] -> Doc)
-> (Doc -> Doc -> Doc)
-> [(a, b)]
-> Doc
ppPairlist a -> Doc
fa b -> Doc
fb CSize -> Doc -> Doc
brace [Doc] -> Doc
inter Doc -> Doc -> Doc
pairDoc ([(a, b)] -> Doc) -> (Map a b -> [(a, b)]) -> Map a b -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map a b -> [(a, b)]
forall k a. Map k a -> [(k, a)]
Map.toList

ppPairlist :: (a -> Doc) -> (b -> Doc) -> (CSize -> Doc -> Doc)
  -> ([Doc] -> Doc) -> (Doc -> Doc -> Doc) -> [(a, b)] -> Doc
ppPairlist :: (a -> Doc)
-> (b -> Doc)
-> (CSize -> Doc -> Doc)
-> ([Doc] -> Doc)
-> (Doc -> Doc -> Doc)
-> [(a, b)]
-> Doc
ppPairlist fa :: a -> Doc
fa fb :: b -> Doc
fb brace :: CSize -> Doc -> Doc
brace inter :: [Doc] -> Doc
inter pairDoc :: Doc -> Doc -> Doc
pairDoc =
  ((a, b) -> Doc)
-> (CSize -> Doc -> Doc) -> ([Doc] -> Doc) -> [(a, b)] -> Doc
forall a.
(a -> Doc) -> (CSize -> Doc -> Doc) -> ([Doc] -> Doc) -> [a] -> Doc
ppList (\ (a :: a
a, b :: b
b) -> Doc -> Doc -> Doc
pairDoc (a -> Doc
fa a
a) (b -> Doc
fb b
b)) CSize -> Doc -> Doc
brace [Doc] -> Doc
inter

pairElems :: Doc -> Doc -> Doc
pairElems :: Doc -> Doc -> Doc
pairElems a :: Doc
a b :: Doc
b = Doc
a Doc -> Doc -> Doc
<+> Doc
mapsto Doc -> Doc -> Doc
<+> Doc
b

instance (Pretty a, Pretty b) => Pretty (Map.Map a b) where
    pretty :: Map a b -> Doc
pretty = (Doc -> Doc)
-> ([Doc] -> Doc) -> (Doc -> Doc -> Doc) -> Map a b -> Doc
forall a b.
(Pretty a, Pretty b) =>
(Doc -> Doc)
-> ([Doc] -> Doc) -> (Doc -> Doc -> Doc) -> Map a b -> Doc
printMap Doc -> Doc
braces [Doc] -> Doc
sepByCommas Doc -> Doc -> Doc
pairElems

-- | start with a bullet, i.e. formulas
addBullet :: Doc -> Doc
addBullet :: Doc -> Doc
addBullet = (Doc
bullet Doc -> Doc -> Doc
<+>)

showDoc :: Pretty a => a -> ShowS
showDoc :: a -> [Char] -> [Char]
showDoc = Doc -> [Char] -> [Char]
forall a. Show a => a -> [Char] -> [Char]
shows (Doc -> [Char] -> [Char]) -> (a -> Doc) -> a -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Doc
forall a. Pretty a => a -> Doc
pretty

-- | like showDoc but considers global annotations
showGlobalDoc :: Pretty a => GlobalAnnos -> a -> ShowS
showGlobalDoc :: GlobalAnnos -> a -> [Char] -> [Char]
showGlobalDoc ga :: GlobalAnnos
ga = Doc -> [Char] -> [Char]
forall a. Show a => a -> [Char] -> [Char]
shows (Doc -> [Char] -> [Char]) -> (a -> Doc) -> a -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GlobalAnnos -> Doc -> Doc
useGlobalAnnos GlobalAnnos
ga (Doc -> Doc) -> (a -> Doc) -> a -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Doc
forall a. Pretty a => a -> Doc
pretty

instance Pretty IRI where
  pretty :: IRI -> Doc
pretty = [Char] -> Doc
text ([Char] -> Doc) -> (IRI -> [Char]) -> IRI -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IRI -> [Char]
forall a. Show a => a -> [Char]
show