Print_AS_Structured.hs revision d0916b96ca9f90822c0bb6062b13d5de83bf410a
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian MaederModule : $Header$
c63ebf815c8a874525cf18670ad74847f7fc7b26Christian MaederDescription : pretty printing of CASL structured specifications
c092fcac4b8f5c524c22ca579189c4487c13edf7Christian MaederCopyright : (c) Klaus Luettich, Uni Bremen 2002-2006
54ed6a6b1a6c7d27fadb39ec5b59d0806c81f7c8Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
75a6279dbae159d018ef812185416cf6df386c10Till MossakowskiMaintainer : Christian.Maeder@dfki.de
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederStability : provisional
75a6279dbae159d018ef812185416cf6df386c10Till MossakowskiPortability : non-portable(Grothendieck)
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian MaederPretty printing of CASL structured specifications
da955132262baab309a50fdffe228c9efe68251dCui Jian , printGroupSpec
dda5ab793f1615c1ba1dcaa97a4346b0878da6b1Christian Maeder , skipVoidGroup
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian Maeder , printExtension
0799b5dc3f06d2640e66e9ab54b8b217348fd719Christian Maeder , PrettyLG (..)
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian MaedersublogicId :: SIMPLE_ID -> Doc
c0c2380bced8159ff0297ece14eba948bd236471Christian MaedersublogicId = structId . tokStr
c0c2380bced8159ff0297ece14eba948bd236471Christian MaederstructIRI :: IRI -> Doc
6352f3c31da3043783a13be6594aacb2147378baRazvan PascanustructIRI = structId . iriToStringShortUnsecure -- also print user information
fc1a590cd3ee36797c0a032ff41e07f8e2469341Christian Maederclass PrettyLG a where
a2b04db3e156312a8596d8084f7f0f51acf8a96bChristian Maeder prettyLG :: LogicGraph -> a -> Doc
66a774f13272fde036481edd2298081ab3d04678Razvan Pascanuinstance PrettyLG a => PrettyLG (Annoted a) where
834c2e71b8e390e5b05c8d02bb6eb22621125133Markus Gross prettyLG lg = printAnnoted $ prettyLG lg
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maederinstance PrettyLG SPEC where
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder prettyLG = printSPEC
923e25bb8c7cf9f2978c7844ad173704482cc3b0Martin KühlprintUnion :: LogicGraph -> [Annoted SPEC] -> [Doc]
9f85afecbd79b3df5a0bb17bd28cd0b288dc3213Kristina SojakovaprintUnion lg = prepPunctuate (topKey andS <> space) . map (condBracesAnd lg)
e1ea9a046e9640148ca876dfe47e391559a9fdf3Christian MaedermoveAnnos :: Annoted SPEC -> [Annoted SPEC] -> [Annoted SPEC]
14c89b2d830777bf4db2850f038c9f60acaca486Christian MaedermoveAnnos x l = appAnno $ case l of
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder [] -> error "moveAnnos"
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder h : r -> h { l_annos = l_annos x ++ l_annos h } : r
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder where appAnno a = case a of
e1ea9a046e9640148ca876dfe47e391559a9fdf3Christian Maeder [h] -> [appendAnno h (r_annos x)]
923e25bb8c7cf9f2978c7844ad173704482cc3b0Martin Kühl h : r -> h : appAnno r
2b873214c9ab511bbca437c036371ab664aedaceChristian MaederprintOptUnion :: LogicGraph -> Annoted SPEC -> [Doc]
fe4e6766a6e51cca3f8cc9632c25936af147d8b9Christian MaederprintOptUnion lg x = case skipVoidGroup $ item x of
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Union e@(_ : _) _ -> printUnion lg $ moveAnnos x e
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Extension e@(_ : _) _ -> printExtension lg $ moveAnnos x e
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder _ -> [prettyLG lg x]
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus GrossprintExtension :: LogicGraph -> [Annoted SPEC] -> [Doc]
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus GrossprintExtension lg l = case l of
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder x : r -> printOptUnion lg x ++
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder concatMap ((\ u -> case u of
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder d : s -> (topKey thenS <+> d) : s) .
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder printOptUnion lg) r
9175e29c044318498a40f323f189f9dfd50378efChristian MaederprintSPEC :: LogicGraph -> SPEC -> Doc
9175e29c044318498a40f323f189f9dfd50378efChristian MaederprintSPEC lg spec = case spec of
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder Basic_spec (G_basic_spec lid basic_spec) _ ->
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder case lookupCurrentSyntax "" lg of
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder Just (Logic lid2, sm) -> if language_name lid2 /= language_name lid
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder then error "printSPEC: logic mismatch"
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder else case basicSpecPrinter sm lid of
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder Just p -> p basic_spec
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder _ -> error $ "printSPEC: no basic spec printer for "
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder ++ showSyntax lid sm
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder _ -> error "printSPEC: incomplete logic graph"
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder EmptySpec _ -> specBraces empty
ee1c7c5796832536932d7b06cbfb1ca13f9a0d7bMartin Kühl Translation aa ab -> sep [condBracesTransReduct lg aa, printRENAMING ab]
ee1c7c5796832536932d7b06cbfb1ca13f9a0d7bMartin Kühl Reduction aa ab -> sep [condBracesTransReduct lg aa, printRESTRICTION ab]
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder Union aa _ -> sep $ printUnion lg aa
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder Extension aa _ -> sep $ printExtension lg aa
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder Free_spec aa _ -> sep [keyword freeS, printGroupSpec lg aa]
c0c2380bced8159ff0297ece14eba948bd236471Christian Maeder Cofree_spec aa _ -> sep [keyword cofreeS, printGroupSpec lg aa]
bdc103981a28a51938de98a956d8a3767f6cf43dAivaras Jakubauskas Local_spec aa ab _ -> fsep
c0c2380bced8159ff0297ece14eba948bd236471Christian Maeder [keyword localS, prettyLG lg aa, keyword withinS, condBracesWithin lg ab]
e1ea9a046e9640148ca876dfe47e391559a9fdf3Christian Maeder Closed_spec aa _ -> sep [keyword closedS, printGroupSpec lg aa]
e1ea9a046e9640148ca876dfe47e391559a9fdf3Christian Maeder Group aa _ -> prettyLG lg aa
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder Spec_inst aa ab _ -> cat [structIRI aa, print_fit_arg_list lg ab]
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder Qualified_spec ln asp _ -> printLogicEncoding ln <> colon
22b772f8753f0cdb4508ba460356c238de2ee375Jonathan von Schroeder $+$ prettyLG (setLogicName ln lg) asp
7bbfb15142ab4286dfc6fcde2fc94a5512297e41Jonathan von Schroeder Data ld _ s1 s2 _ -> keyword dataS
fa388aea9cef5f9734fec346159899a74432ce26Christian Maeder <+> printGroupSpec (setCurLogic (show ld) lg) s1
63719301448519453f66383f4e583d9fd5b89ecbChristian Maeder $+$ prettyLG lg s2
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder Combination cs es _ -> fsep $ keyword combineS : ppWithCommas cs
fc1a590cd3ee36797c0a032ff41e07f8e2469341Christian Maeder : if null es then [] else [keyword excludingS, ppWithCommas es]
923e25bb8c7cf9f2978c7844ad173704482cc3b0Martin Kühlinstance Pretty RENAMING where
9f85afecbd79b3df5a0bb17bd28cd0b288dc3213Kristina Sojakova pretty = printRENAMING
a461314c811f4187dff85c8be079a41b2f13f176Christian MaederprintRENAMING :: RENAMING -> Doc
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian MaederprintRENAMING (Renaming aa _) =
fbc4f8708092d571a45cb483f37cc6b674da45a7Christian Maeder keyword withS <+> ppWithCommas aa
8a77240a809197c92c0736c431b4b88947a7bac1Christian Maederinstance Pretty RESTRICTION where
fbc4f8708092d571a45cb483f37cc6b674da45a7Christian Maeder pretty = printRESTRICTION
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus GrossprintRESTRICTION :: RESTRICTION -> Doc
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus GrossprintRESTRICTION rest = case rest of
d56ece59c372cb887355825901222b9f3377f7e6Thiemo Wiedemeyer Hidden aa _ -> keyword hideS <+> ppWithCommas aa
d56ece59c372cb887355825901222b9f3377f7e6Thiemo Wiedemeyer Revealed aa _ -> keyword revealS <+> pretty aa
9175e29c044318498a40f323f189f9dfd50378efChristian MaederprintLogicEncoding :: (Pretty a) => a -> Doc
9175e29c044318498a40f323f189f9dfd50378efChristian MaederprintLogicEncoding enc = keyword logicS <+> pretty enc
9175e29c044318498a40f323f189f9dfd50378efChristian Maederinstance Pretty G_mapping where
f77f29e84b3f6e791c82e61b13fbf76582bedd2fChristian Maeder pretty = printG_mapping