{- |
Module      :  ./Syntax/Print_AS_Library.hs
Description :  pretty printing of CASL specification libaries
Copyright   :  (c) Klaus Luettich, Uni Bremen 2002-2006
License     :  GPLv2 or higher, see LICENSE.txt
Maintainer  :  Christian.Maeder@dfki.de
Stability   :  provisional
Portability :  non-portable(Grothendieck)

Pretty printing of CASL specification libaries
-}

module Syntax.Print_AS_Library () where

import Data.Maybe (maybeToList)

import Common.AS_Annotation
import Common.IRI
import Common.Doc
import Common.DocUtils
import Common.Keywords
import Common.LibName

import Logic.Grothendieck

import Syntax.AS_Structured
import Syntax.AS_Library

import Syntax.Print_AS_Architecture ()
import Syntax.Print_AS_Structured

instance PrettyLG LIB_DEFN where
    prettyLG :: LogicGraph -> LIB_DEFN -> Doc
prettyLG lg :: LogicGraph
lg (Lib_defn aa :: LibName
aa ab :: [Annoted LIB_ITEM]
ab _ ad :: [Annotation]
ad) =
        let aa' :: Doc
aa' = LibName -> Doc
forall a. Pretty a => a -> Doc
pretty LibName
aa            -- lib name
            ab' :: Doc
ab' = [Doc] -> Doc
vsep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ LogicGraph -> [Annoted LIB_ITEM] -> [Doc]
printLibItems LogicGraph
lg [Annoted LIB_ITEM]
ab -- LIB_ITEMs
            ad' :: Doc
ad' = [Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Annotation -> Doc) -> [Annotation] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Annotation -> Doc
forall a. Pretty a => a -> Doc
pretty [Annotation]
ad -- global ANNOTATIONs
        in (if LibName -> IRI
getLibId LibName
aa IRI -> IRI -> Bool
forall a. Eq a => a -> a -> Bool
== IRI
nullIRI then Doc
empty else
               String -> Doc
keyword String
libraryS Doc -> Doc -> Doc
<+> Doc
aa') Doc -> Doc -> Doc
$++$ Doc
ad' Doc -> Doc -> Doc
$++$ Doc
ab'

printLibItems :: LogicGraph -> [Annoted LIB_ITEM] -> [Doc]
printLibItems :: LogicGraph -> [Annoted LIB_ITEM] -> [Doc]
printLibItems lg :: LogicGraph
lg is :: [Annoted LIB_ITEM]
is = case [Annoted LIB_ITEM]
is of
  [] -> []
  i :: Annoted LIB_ITEM
i : rs :: [Annoted LIB_ITEM]
rs -> LogicGraph -> Annoted LIB_ITEM -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg Annoted LIB_ITEM
i Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: LogicGraph -> [Annoted LIB_ITEM] -> [Doc]
printLibItems (case Annoted LIB_ITEM -> LIB_ITEM
forall a. Annoted a -> a
item Annoted LIB_ITEM
i of
    Logic_decl aa :: LogicDescr
aa _ -> LogicDescr -> LogicGraph -> LogicGraph
setLogicName LogicDescr
aa LogicGraph
lg
    _ -> LogicGraph
lg) [Annoted LIB_ITEM]
rs

instance PrettyLG VIEW_TYPE where
  prettyLG :: LogicGraph -> VIEW_TYPE -> Doc
prettyLG = [Any] -> LogicGraph -> VIEW_TYPE -> Doc
forall a. [a] -> LogicGraph -> VIEW_TYPE -> Doc
prettyViewType []

prettyViewType :: [a] -> LogicGraph -> VIEW_TYPE -> Doc
prettyViewType :: [a] -> LogicGraph -> VIEW_TYPE -> Doc
prettyViewType ad :: [a]
ad lg :: LogicGraph
lg (View_type frm :: Annoted SPEC
frm to :: Annoted SPEC
to _) =
  [Doc] -> Doc
sep [ LogicGraph -> Annoted SPEC -> Doc
printGroupSpec LogicGraph
lg Annoted SPEC
frm Doc -> Doc -> Doc
<+> String -> Doc
keyword String
toS
      , (if [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
ad then Doc -> Doc
forall a. a -> a
id else (Doc -> Doc -> Doc
<+> Doc
equals))
      (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ LogicGraph -> Annoted SPEC -> Doc
printGroupSpec LogicGraph
lg Annoted SPEC
to]

instance PrettyLG LIB_ITEM where
    prettyLG :: LogicGraph -> LIB_ITEM -> Doc
prettyLG lg :: LogicGraph
lg li :: LIB_ITEM
li = case LIB_ITEM
li of
        Spec_defn si :: IRI
si (Genericity aa :: PARAMS
aa@(Params pl :: [Annoted SPEC]
pl) ab :: IMPORTED
ab@(Imported il :: [Annoted SPEC]
il) _) ac' :: Annoted SPEC
ac' _ ->
            let las :: [Annotation]
las = Annoted SPEC -> [Annotation]
forall a. Annoted a -> [Annotation]
l_annos Annoted SPEC
ac'
                (sa :: Doc
sa, ac :: Annoted SPEC
ac) = if [Annotation] -> Bool
startsWithSemanticAnno [Annotation]
las then
                               (Doc
equals Doc -> Doc -> Doc
<+> Annotation -> Doc
annoDoc ([Annotation] -> Annotation
forall a. [a] -> a
head [Annotation]
las),
                                Annoted SPEC
ac' { l_annos :: [Annotation]
l_annos = [Annotation] -> [Annotation]
forall a. [a] -> [a]
tail [Annotation]
las })
                           else (Doc
equals, Annoted SPEC
ac')
                x :: Doc
x : r :: [Doc]
r = case SPEC -> SPEC
skipVoidGroup (SPEC -> SPEC) -> SPEC -> SPEC
forall a b. (a -> b) -> a -> b
$ Annoted SPEC -> SPEC
forall a. Annoted a -> a
item Annoted SPEC
ac of
                          Extension e :: [Annoted SPEC]
e@(_ : _) _ ->
                              LogicGraph -> [Annoted SPEC] -> [Doc]
printExtension LogicGraph
lg ([Annoted SPEC] -> [Doc]) -> [Annoted SPEC] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Annoted SPEC -> [Annoted SPEC] -> [Annoted SPEC]
moveAnnos Annoted SPEC
ac [Annoted SPEC]
e
                          Union u :: [Annoted SPEC]
u@(_ : _) _ ->
                              LogicGraph -> [Annoted SPEC] -> [Doc]
printUnion LogicGraph
lg ([Annoted SPEC] -> [Doc]) -> [Annoted SPEC] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Annoted SPEC -> [Annoted SPEC] -> [Annoted SPEC]
moveAnnos Annoted SPEC
ac [Annoted SPEC]
u
                          _ -> [LogicGraph -> Annoted SPEC -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg Annoted SPEC
ac]
                spid :: Doc
spid = String -> Doc
indexed (IRI -> String
iriToStringShortUnsecure IRI
si)
                sphead :: Doc
sphead = if [Annoted SPEC] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Annoted SPEC]
il then
                             if [Annoted SPEC] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Annoted SPEC]
pl then Doc
spid Doc -> Doc -> Doc
<+> Doc
sa
                             else [Doc] -> Doc
cat [Doc
spid, LogicGraph -> PARAMS -> Doc
printPARAMS LogicGraph
lg PARAMS
aa Doc -> Doc -> Doc
<+> Doc
sa]
                         else [Doc] -> Doc
sep [ [Doc] -> Doc
cat [Doc
spid, LogicGraph -> PARAMS -> Doc
printPARAMS LogicGraph
lg PARAMS
aa]
                                  , LogicGraph -> IMPORTED -> Doc
printIMPORTED LogicGraph
lg IMPORTED
ab Doc -> Doc -> Doc
<+> Doc
sa]
             in if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (IRI -> String
iriToStringShortUnsecure IRI
si) Bool -> Bool -> Bool
&& [Annoted SPEC] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Annoted SPEC]
pl
                then LogicGraph -> Annoted SPEC -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg Annoted SPEC
ac' else
                    [Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (String -> Doc
topKey String
specS Doc -> Doc -> Doc
<+> [Doc] -> Doc
vcat [Doc
sphead, Doc
x]) Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: [Doc]
r
                    [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [String -> Doc
keyword String
endS]
        View_defn si :: IRI
si (Genericity aa :: PARAMS
aa@(Params pl :: [Annoted SPEC]
pl) ab :: IMPORTED
ab@(Imported il :: [Annoted SPEC]
il) _)
                      vt :: VIEW_TYPE
vt ad :: [G_mapping]
ad _ ->
            let spid :: Doc
spid = IRI -> Doc
structIRI IRI
si
                sphead :: Doc
sphead = if [Annoted SPEC] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Annoted SPEC]
il then
                             if [Annoted SPEC] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Annoted SPEC]
pl then Doc
spid Doc -> Doc -> Doc
<+> Doc
colon
                             else [Doc] -> Doc
cat [Doc
spid, LogicGraph -> PARAMS -> Doc
printPARAMS LogicGraph
lg PARAMS
aa Doc -> Doc -> Doc
<+> Doc
colon]
                         else [Doc] -> Doc
sep [ [Doc] -> Doc
cat [Doc
spid, LogicGraph -> PARAMS -> Doc
printPARAMS LogicGraph
lg PARAMS
aa]
                                  , LogicGraph -> IMPORTED -> Doc
printIMPORTED LogicGraph
lg IMPORTED
ab Doc -> Doc -> Doc
<+> Doc
colon]
            in String -> Doc
topKey String
viewS Doc -> Doc -> Doc
<+>
               [Doc] -> Doc
sep [Doc
sphead, [G_mapping] -> LogicGraph -> VIEW_TYPE -> Doc
forall a. [a] -> LogicGraph -> VIEW_TYPE -> Doc
prettyViewType [G_mapping]
ad LogicGraph
lg VIEW_TYPE
vt, [G_mapping] -> Doc
forall a. Pretty a => [a] -> Doc
ppWithCommas [G_mapping]
ad]
               Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
endS
        Entail_defn si :: IRI
si et :: ENTAIL_TYPE
et _ -> String -> Doc
topKey String
entailmentS Doc -> Doc -> Doc
<+>
            [Doc] -> Doc
sep ((IRI -> Doc
structIRI IRI
si Doc -> Doc -> Doc
<+> Doc
equals) Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: case ENTAIL_TYPE
et of
                 Entail_type s1 :: OmsOrNetwork
s1 s2 :: OmsOrNetwork
s2 _ ->
                   [ LogicGraph -> OmsOrNetwork -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg OmsOrNetwork
s1
                   , String -> Doc
keyword String
entailsS
                   , LogicGraph -> OmsOrNetwork -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg OmsOrNetwork
s2 ]
                 OMSInNetwork i :: IRI
i nw :: Network
nw s2 :: SPEC
s2 _ ->
                   [ IRI -> Doc
structIRI IRI
i Doc -> Doc -> Doc
<+> String -> Doc
keyword String
inS
                   , Network -> Doc
forall a. Pretty a => a -> Doc
pretty Network
nw
                   , String -> Doc
keyword String
entailsS
                   , LogicGraph -> SPEC -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg SPEC
s2 ])
            Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
endS
        Equiv_defn si :: IRI
si (Equiv_type as1 :: OmsOrNetwork
as1 as2 :: OmsOrNetwork
as2 _) sp :: OmsOrNetwork
sp _ -> String -> Doc
topKey String
equivalenceS Doc -> Doc -> Doc
<+>
            [Doc] -> Doc
sep [IRI -> Doc
structIRI IRI
si Doc -> Doc -> Doc
<+> Doc
colon, [Doc] -> Doc
sep
                [ LogicGraph -> OmsOrNetwork -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg OmsOrNetwork
as1
                , String -> Doc
text String
equiS
                , LogicGraph -> OmsOrNetwork -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg OmsOrNetwork
as2]
                Doc -> Doc -> Doc
<+> Doc
equals, LogicGraph -> OmsOrNetwork -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg OmsOrNetwork
sp]
            Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
endS
        Align_defn si :: IRI
si ar :: Maybe ALIGN_ARITIES
ar vt :: VIEW_TYPE
vt corresps :: [CORRESPONDENCE]
corresps aSem :: AlignSem
aSem _ ->
            let spid :: Doc
spid = String -> Doc
indexed (IRI -> String
iriToStringShortUnsecure IRI
si)
                sphead :: Doc
sphead = case Maybe ALIGN_ARITIES
ar of
                  Nothing -> Doc
spid Doc -> Doc -> Doc
<+> Doc
colon
                  Just alignArities :: ALIGN_ARITIES
alignArities -> [Doc] -> Doc
sep
                    [Doc
spid, ALIGN_ARITIES -> Doc
printAlignArities ALIGN_ARITIES
alignArities Doc -> Doc -> Doc
<+> Doc
colon ]
            in String -> Doc
topKey String
alignmentS Doc -> Doc -> Doc
<+>
               [Doc] -> Doc
sep ([Doc
sphead, [Any] -> LogicGraph -> VIEW_TYPE -> Doc
forall a. [a] -> LogicGraph -> VIEW_TYPE -> Doc
prettyViewType [] LogicGraph
lg VIEW_TYPE
vt]
                     [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ if [CORRESPONDENCE] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [CORRESPONDENCE]
corresps then []
                        else [ Doc
equals Doc -> Doc -> Doc
<+> [CORRESPONDENCE] -> Doc
printCorrespondences [CORRESPONDENCE]
corresps
                             , String -> Doc
keyword "assuming" Doc -> Doc -> Doc
<+> String -> Doc
keyword (AlignSem -> String
forall a. Show a => a -> String
show AlignSem
aSem)])
               Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
endS
        Module_defn mn :: IRI
mn mt :: MODULE_TYPE
mt rs :: G_symb_items_list
rs _ ->
            let spid :: Doc
spid = String -> Doc
indexed (IRI -> String
iriToStringShortUnsecure IRI
mn)
                sphead :: Doc
sphead = Doc
spid Doc -> Doc -> Doc
<+> Doc
colon
                spmt :: Doc
spmt = case MODULE_TYPE
mt of
                  Module_type sp1 :: Annoted SPEC
sp1 sp2 :: Annoted SPEC
sp2 _ -> [Doc] -> Doc
sep
                    [LogicGraph -> Annoted SPEC -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg Annoted SPEC
sp1, String -> Doc
text String
ofS, LogicGraph -> Annoted SPEC -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg Annoted SPEC
sp2]
            in String -> Doc
topKey String
moduleS Doc -> Doc -> Doc
<+>
               [Doc] -> Doc
sep [Doc
sphead, Doc
spmt, String -> Doc
text String
forS, G_symb_items_list -> Doc
forall a. Pretty a => a -> Doc
pretty G_symb_items_list
rs]
        Query_defn qn :: IRI
qn vs :: G_symb_items_list
vs sen :: G_basic_spec
sen spec :: Annoted SPEC
spec mt :: Maybe IRI
mt _ -> String -> Doc
topKey "query" Doc -> Doc -> Doc
<+>
            [Doc] -> Doc
fsep ([ IRI -> Doc
structIRI IRI
qn Doc -> Doc -> Doc
<+> Doc
equals
                  , String -> Doc
keyword String
selectS Doc -> Doc -> Doc
<+> G_symb_items_list -> Doc
forall a. Pretty a => a -> Doc
pretty G_symb_items_list
vs
                  , String -> Doc
keyword String
whereS Doc -> Doc -> Doc
<+> G_basic_spec -> Doc
forall a. Pretty a => a -> Doc
pretty G_basic_spec
sen
                  , String -> Doc
keyword String
inS Doc -> Doc -> Doc
<+> LogicGraph -> Annoted SPEC -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg Annoted SPEC
spec]
                  [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [Doc] -> (IRI -> [Doc]) -> Maybe IRI -> [Doc]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe []
                  (\ r :: IRI
r -> [String -> Doc
keyword "along" Doc -> Doc -> Doc
<+> IRI -> Doc
forall a. Pretty a => a -> Doc
pretty IRI
r]) Maybe IRI
mt)
            Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
endS
        Subst_defn sn :: IRI
sn vt :: VIEW_TYPE
vt sm :: G_symb_map_items_list
sm _ -> String -> Doc
topKey "substitution" Doc -> Doc -> Doc
<+>
            [Doc] -> Doc
sep [ IRI -> Doc
structIRI IRI
sn Doc -> Doc -> Doc
<+> Doc
colon, [Any] -> LogicGraph -> VIEW_TYPE -> Doc
forall a. [a] -> LogicGraph -> VIEW_TYPE -> Doc
prettyViewType [] LogicGraph
lg VIEW_TYPE
vt
                , Doc
equals Doc -> Doc -> Doc
<+> G_symb_map_items_list -> Doc
forall a. Pretty a => a -> Doc
pretty G_symb_map_items_list
sm]
            Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
endS
        Result_defn rn :: IRI
rn sl :: [IRI]
sl sq :: IRI
sq b :: Bool
b _ -> String -> Doc
topKey String
resultS Doc -> Doc -> Doc
<+>
            [Doc] -> Doc
fsep ([ IRI -> Doc
structIRI IRI
rn , [IRI] -> Doc
forall a. Pretty a => [a] -> Doc
ppWithCommas [IRI]
sl
                  , String -> Doc
keyword String
forS Doc -> Doc -> Doc
<+> IRI -> Doc
forall a. Pretty a => a -> Doc
pretty IRI
sq]
                  [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [String -> Doc
keyword "%complete" | Bool
b])
            Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
endS
        Arch_spec_defn si :: IRI
si ab :: Annoted ARCH_SPEC
ab _ -> String -> Doc
topKey String
archS Doc -> Doc -> Doc
<+>
            [Doc] -> Doc
fsep [String -> Doc
keyword String
specS, IRI -> Doc
structIRI IRI
si Doc -> Doc -> Doc
<+> Doc
equals, LogicGraph -> Annoted ARCH_SPEC -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg Annoted ARCH_SPEC
ab]
            Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
endS
        Unit_spec_defn si :: IRI
si ab :: UNIT_SPEC
ab _ -> String -> Doc
topKey String
unitS Doc -> Doc -> Doc
<+>
            [Doc] -> Doc
fsep [String -> Doc
keyword String
specS, IRI -> Doc
structIRI IRI
si Doc -> Doc -> Doc
<+> Doc
equals, LogicGraph -> UNIT_SPEC -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg UNIT_SPEC
ab]
            Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
endS
        Ref_spec_defn si :: IRI
si ab :: REF_SPEC
ab _ -> String -> Doc
keyword String
refinementS Doc -> Doc -> Doc
<+>
            [Doc] -> Doc
fsep [IRI -> Doc
structIRI IRI
si Doc -> Doc -> Doc
<+> Doc
equals, LogicGraph -> REF_SPEC -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg REF_SPEC
ab]
            Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
endS
        Network_defn si :: IRI
si n :: Network
n _ -> String -> Doc
keyword String
networkS Doc -> Doc -> Doc
<+>
            [Doc] -> Doc
fsep [IRI -> Doc
structIRI IRI
si Doc -> Doc -> Doc
<+> Doc
equals, Network -> Doc
forall a. Pretty a => a -> Doc
pretty Network
n]
            Doc -> Doc -> Doc
$+$ String -> Doc
keyword String
endS
        Download_items l :: LibName
l ab :: DownloadItems
ab _ -> String -> Doc
topKey String
fromS Doc -> Doc -> Doc
<+>
            [Doc] -> Doc
fsep ((LibName -> Doc
forall a. Pretty a => a -> Doc
pretty LibName
l Doc -> Doc -> Doc
<+> String -> Doc
keyword String
getS) Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: DownloadItems -> [Doc]
prettyDownloadItems DownloadItems
ab)
        Logic_decl aa :: LogicDescr
aa _ -> LogicDescr -> Doc
forall a. Pretty a => a -> Doc
pretty LogicDescr
aa
        Newlogic_defn nl :: LogicDef
nl _ -> LogicDef -> Doc
forall a. Pretty a => a -> Doc
pretty LogicDef
nl
        Newcomorphism_defn nc :: ComorphismDef
nc _ -> ComorphismDef -> Doc
forall a. Pretty a => a -> Doc
pretty ComorphismDef
nc

instance PrettyLG OmsOrNetwork where
   prettyLG :: LogicGraph -> OmsOrNetwork -> Doc
prettyLG lg :: LogicGraph
lg s :: OmsOrNetwork
s = case OmsOrNetwork
s of
     MkOms o :: Annoted SPEC
o -> LogicGraph -> Annoted SPEC -> Doc
printGroupSpec LogicGraph
lg Annoted SPEC
o
     MkNetwork n :: Network
n -> Network -> Doc
forall a. Pretty a => a -> Doc
pretty Network
n

prettyDownloadItems :: DownloadItems -> [Doc]
prettyDownloadItems :: DownloadItems -> [Doc]
prettyDownloadItems d :: DownloadItems
d = case DownloadItems
d of
  ItemMaps l :: [ItemNameMap]
l -> Doc -> [Doc] -> [Doc]
punctuate Doc
comma ([Doc] -> [Doc]) -> [Doc] -> [Doc]
forall a b. (a -> b) -> a -> b
$ (ItemNameMap -> Doc) -> [ItemNameMap] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ItemNameMap -> Doc
forall a. Pretty a => a -> Doc
pretty [ItemNameMap]
l
  UniqueItem i :: IRI
i -> [Doc
mapsto, IRI -> Doc
structIRI IRI
i]

instance PrettyLG GENERICITY where
    prettyLG :: LogicGraph -> GENERICITY -> Doc
prettyLG lg :: LogicGraph
lg (Genericity aa :: PARAMS
aa ab :: IMPORTED
ab _) =
        [Doc] -> Doc
sep [LogicGraph -> PARAMS -> Doc
printPARAMS LogicGraph
lg PARAMS
aa, LogicGraph -> IMPORTED -> Doc
printIMPORTED LogicGraph
lg IMPORTED
ab]

printPARAMS :: LogicGraph -> PARAMS -> Doc
printPARAMS :: LogicGraph -> PARAMS -> Doc
printPARAMS lg :: LogicGraph
lg (Params aa :: [Annoted SPEC]
aa) = [Doc] -> Doc
cat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Annoted SPEC -> Doc) -> [Annoted SPEC] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Doc -> Doc
brackets (Doc -> Doc) -> (Annoted SPEC -> Doc) -> Annoted SPEC -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc
rmTopKey (Doc -> Doc) -> (Annoted SPEC -> Doc) -> Annoted SPEC -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LogicGraph -> Annoted SPEC -> Doc
forall a. PrettyLG a => LogicGraph -> a -> Doc
prettyLG LogicGraph
lg ) [Annoted SPEC]
aa

printIMPORTED :: LogicGraph -> IMPORTED -> Doc
printIMPORTED :: LogicGraph -> IMPORTED -> Doc
printIMPORTED lg :: LogicGraph
lg (Imported aa :: [Annoted SPEC]
aa) = case [Annoted SPEC]
aa of
    [] -> Doc
empty
    _ -> [Doc] -> Doc
sep [String -> Doc
keyword String
givenS, [Doc] -> Doc
sepByCommas ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Annoted SPEC -> Doc) -> [Annoted SPEC] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (LogicGraph -> Annoted SPEC -> Doc
printGroupSpec LogicGraph
lg) [Annoted SPEC]
aa]

instance Pretty ALIGN_ARITIES where
  pretty :: ALIGN_ARITIES -> Doc
pretty = ALIGN_ARITIES -> Doc
printAlignArities

printAlignArities :: ALIGN_ARITIES -> Doc
printAlignArities :: ALIGN_ARITIES -> Doc
printAlignArities (Align_arities f :: ALIGN_ARITY
f b :: ALIGN_ARITY
b) =
  [Doc] -> Doc
sep [String -> Doc
text String
alignArityForwardS, ALIGN_ARITY -> Doc
printAlignArity ALIGN_ARITY
f,
       String -> Doc
text String
alignArityBackwardS, ALIGN_ARITY -> Doc
printAlignArity ALIGN_ARITY
b]

printAlignArity :: ALIGN_ARITY -> Doc
printAlignArity :: ALIGN_ARITY -> Doc
printAlignArity = String -> Doc
text (String -> Doc) -> (ALIGN_ARITY -> String) -> ALIGN_ARITY -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ALIGN_ARITY -> String
showAlignArity

printCorrespondences :: [CORRESPONDENCE] -> Doc
printCorrespondences :: [CORRESPONDENCE] -> Doc
printCorrespondences = [Doc] -> Doc
vsep ([Doc] -> Doc)
-> ([CORRESPONDENCE] -> [Doc]) -> [CORRESPONDENCE] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
punctuate Doc
comma ([Doc] -> [Doc])
-> ([CORRESPONDENCE] -> [Doc]) -> [CORRESPONDENCE] -> [Doc]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CORRESPONDENCE -> Doc) -> [CORRESPONDENCE] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map CORRESPONDENCE -> Doc
printCorrespondence

printCorrespondence :: CORRESPONDENCE -> Doc
printCorrespondence :: CORRESPONDENCE -> Doc
printCorrespondence Default_correspondence = String -> Doc
text "*"
printCorrespondence (Correspondence_block mrref :: Maybe RELATION_REF
mrref mconf :: Maybe CONFIDENCE
mconf cs :: [CORRESPONDENCE]
cs) =
  [Doc] -> Doc
sep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ [[Doc]] -> [Doc]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
  [[String -> Doc
text String
relationS],
   (RELATION_REF -> Doc) -> [RELATION_REF] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map RELATION_REF -> Doc
printRelationRef ([RELATION_REF] -> [Doc]) -> [RELATION_REF] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Maybe RELATION_REF -> [RELATION_REF]
forall a. Maybe a -> [a]
maybeToList Maybe RELATION_REF
mrref,
   (CONFIDENCE -> Doc) -> [CONFIDENCE] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map CONFIDENCE -> Doc
printConfidence ([CONFIDENCE] -> [Doc]) -> [CONFIDENCE] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Maybe CONFIDENCE -> [CONFIDENCE]
forall a. Maybe a -> [a]
maybeToList Maybe CONFIDENCE
mconf,
   [String -> Doc
text "{"],
   [[CORRESPONDENCE] -> Doc
printCorrespondences [CORRESPONDENCE]
cs],
   [String -> Doc
text "}"]]

printCorrespondence (Single_correspondence mcid :: Maybe Annotation
mcid eRef :: G_symb_items_list
eRef toer :: G_symb_items_list
toer mrRef :: Maybe RELATION_REF
mrRef mconf :: Maybe CONFIDENCE
mconf) =
  [Doc] -> Doc
sep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ [[Doc]] -> [Doc]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
  [[String -> Doc
indexed (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ G_symb_items_list -> String
forall a. Show a => a -> String
show G_symb_items_list
eRef],
   (RELATION_REF -> Doc) -> [RELATION_REF] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map RELATION_REF -> Doc
printRelationRef ([RELATION_REF] -> [Doc]) -> [RELATION_REF] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Maybe RELATION_REF -> [RELATION_REF]
forall a. Maybe a -> [a]
maybeToList Maybe RELATION_REF
mrRef,
   (CONFIDENCE -> Doc) -> [CONFIDENCE] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map CONFIDENCE -> Doc
printConfidence ([CONFIDENCE] -> [Doc]) -> [CONFIDENCE] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Maybe CONFIDENCE -> [CONFIDENCE]
forall a. Maybe a -> [a]
maybeToList Maybe CONFIDENCE
mconf,
   [G_symb_items_list -> Doc
forall a. Pretty a => a -> Doc
pretty G_symb_items_list
toer],
   (Annotation -> Doc) -> [Annotation] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Annotation -> Doc
forall a. Pretty a => a -> Doc
pretty ([Annotation] -> [Doc]) -> [Annotation] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Maybe Annotation -> [Annotation]
forall a. Maybe a -> [a]
maybeToList Maybe Annotation
mcid]

instance Pretty CORRESPONDENCE where
  pretty :: CORRESPONDENCE -> Doc
pretty = CORRESPONDENCE -> Doc
printCorrespondence

printConfidence :: CONFIDENCE -> Doc
   -- "show" should work in [0,1]
printConfidence :: CONFIDENCE -> Doc
printConfidence = String -> Doc
text (String -> Doc) -> (CONFIDENCE -> String) -> CONFIDENCE -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ('(' Char -> String -> String
forall a. a -> [a] -> [a]
:) (String -> String)
-> (CONFIDENCE -> String) -> CONFIDENCE -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> String -> String
forall a. [a] -> [a] -> [a]
++ ")") (String -> String)
-> (CONFIDENCE -> String) -> CONFIDENCE -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CONFIDENCE -> String
forall a. Show a => a -> String
show

printRelationRef :: RELATION_REF -> Doc
printRelationRef :: RELATION_REF -> Doc
printRelationRef rref :: RELATION_REF
rref = case RELATION_REF
rref of
  Subsumes -> Doc
greater
  IsSubsumed -> Doc
less
  Equivalent -> Doc
equals
  Incompatible -> String -> Doc
text "%"
  HasInstance -> String -> Doc
keyword "ni"
  InstanceOf -> String -> Doc
keyword "in"
  DefaultRelation -> Doc
mapsto
  Iri i :: IRI
i -> IRI -> Doc
structIRI IRI
i

instance Pretty ItemNameMap where
    pretty :: ItemNameMap -> Doc
pretty (ItemNameMap a :: IRI
a m :: Maybe IRI
m) = [Doc] -> Doc
fsep
       ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ IRI -> Doc
structIRI IRI
a Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: case Maybe IRI
m of
          Nothing -> []
          Just b :: IRI
b -> [Doc
mapsto, IRI -> Doc
structIRI IRI
b]