As.der.hs revision 3d4f336bca521e5cd85ce5fcfc572469c88c942c
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian MaederModule : $Header$
c63ebf815c8a874525cf18670ad74847f7fc7b26Christian MaederDescription : abstract syntax for FPL
c092fcac4b8f5c524c22ca579189c4487c13edf7Christian MaederCopyright : (c) Christian Maeder, DFKI GmbH 2011
54ed6a6b1a6c7d27fadb39ec5b59d0806c81f7c8Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
75a6279dbae159d018ef812185416cf6df386c10Till MossakowskiMaintainer : Christian.Maeder@dfki.de
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederStability : provisional
75a6279dbae159d018ef812185416cf6df386c10Till MossakowskiPortability : portable
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian Maederabstract syntax for FPL, logic for functional programs
c092fcac4b8f5c524c22ca579189c4487c13edf7Christian Maederas CASL extension
dda5ab793f1615c1ba1dcaa97a4346b0878da6b1Christian Maeder-- DrIFT command
dda5ab793f1615c1ba1dcaa97a4346b0878da6b1Christian Maeder{-! global: GetRange !-}
14c89b2d830777bf4db2850f038c9f60acaca486Christian Maederimport Common.Token hiding (innerList)
da333ffa6336cf59a4071fcddad358c5eafd3e61Sonja Gröningimport Data.List (delete)
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanutype FplBasicSpec = BASIC_SPEC FplExt () TermExt
fc1a590cd3ee36797c0a032ff41e07f8e2469341Christian Maedertype FplTerm = TERM TermExt
a2b04db3e156312a8596d8084f7f0f51acf8a96bChristian Maedertype FplForm = FORMULA TermExt
834c2e71b8e390e5b05c8d02bb6eb22621125133Markus Gross FplSortItems [Annoted FplSortItem] Range
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder | FplOpItems [Annoted FplOpItem] Range
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder deriving Show
6e52f1dfc0da4bc4a7701cf856641c9dce08fc7dChristian Maederdata FplSortItem =
923e25bb8c7cf9f2978c7844ad173704482cc3b0Martin Kühl FreeType DATATYPE_DECL
9f85afecbd79b3df5a0bb17bd28cd0b288dc3213Kristina Sojakova | CaslSortItem (SORT_ITEM TermExt)
63da71bfb4226f504944b293fb77177ebcaea7d4Ewaryst Schulz deriving Show
14c89b2d830777bf4db2850f038c9f60acaca486Christian Maederdata FplOpItem =
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder | CaslOpItem (OP_ITEM TermExt)
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder deriving Show
e1ea9a046e9640148ca876dfe47e391559a9fdf3Christian MaederprepPunctBar :: [Doc] -> [Doc]
923e25bb8c7cf9f2978c7844ad173704482cc3b0Martin KühlprepPunctBar = prepPunctuate (bar <> Doc.space)
2b873214c9ab511bbca437c036371ab664aedaceChristian MaederprintDD :: DATATYPE_DECL -> Doc
fe4e6766a6e51cca3f8cc9632c25936af147d8b9Christian MaederprintDD (Datatype_decl s as _) =
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder sep [pretty s <+> keyword freeS <+> keyword withS
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder , sep $ prepPunctBar
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder $ map (printAnnoted printALTERNATIVE) as ]
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus Grossinstance ListCheck FplOpItem where
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus Gross innerList i = case i of
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder FunOp _ -> [()]
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder CaslOpItem oi -> innerList oi
9175e29c044318498a40f323f189f9dfd50378efChristian Maederinstance ListCheck FplSortItem where
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder innerList i = case i of
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder FreeType _ -> [()]
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder CaslSortItem si -> innerList si
9175e29c044318498a40f323f189f9dfd50378efChristian Maederinstance Pretty FplExt where
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder pretty e = case e of
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder FplSortItems ds _ ->
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder topSigKey (sortS ++ pluralS ds) <+> semiAnnos pretty ds
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder FplOpItems ds _ -> topSigKey (opS ++ pluralS ds) <+> semiAnnos pretty ds
9175e29c044318498a40f323f189f9dfd50378efChristian Maederinstance Pretty FplSortItem where
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder pretty e = case e of
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder FreeType d -> printDD d
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder CaslSortItem s -> printSortItem pretty s
ee1c7c5796832536932d7b06cbfb1ca13f9a0d7bMartin Kühlinstance Pretty FplOpItem where
ee1c7c5796832536932d7b06cbfb1ca13f9a0d7bMartin Kühl pretty e = case e of
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder FunOp o -> pretty o
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder CaslOpItem s -> printOpItem pretty s
c0c2380bced8159ff0297ece14eba948bd236471Christian Maederdata FunDef = FunDef OP_NAME [VAR_DECL] SORT (Annoted FplTerm) Range
bdc103981a28a51938de98a956d8a3767f6cf43dAivaras Jakubauskas deriving (Show, Eq, Ord)
e1ea9a046e9640148ca876dfe47e391559a9fdf3Christian Maederinstance Pretty FunDef where
e1ea9a046e9640148ca876dfe47e391559a9fdf3Christian Maeder pretty (FunDef n vs s t _) =
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder fsep [keyword functS
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder , pretty n <>
22b772f8753f0cdb4508ba460356c238de2ee375Jonathan von Schroeder (if null vs then empty else parens (printVarDecls vs))
7bbfb15142ab4286dfc6fcde2fc94a5512297e41Jonathan von Schroeder , colon <+> pretty s
fa388aea9cef5f9734fec346159899a74432ce26Christian Maeder , equals <+> printAnnoted pretty t]
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederdata TermExt =
fc1a590cd3ee36797c0a032ff41e07f8e2469341Christian Maeder FixDef FunDef -- ^ formula
fc1a590cd3ee36797c0a032ff41e07f8e2469341Christian Maeder | Case FplTerm [(FplTerm, FplTerm)] Range
923e25bb8c7cf9f2978c7844ad173704482cc3b0Martin Kühl | Let FunDef FplTerm Range
9f85afecbd79b3df5a0bb17bd28cd0b288dc3213Kristina Sojakova | IfThenElse FplForm FplTerm FplTerm Range
72079df98b3cb7cc1fd82a0a24984893dcd05ecaEwaryst Schulz deriving (Show, Eq, Ord)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederinstance Pretty TermExt where
fbc4f8708092d571a45cb483f37cc6b674da45a7Christian Maeder pretty t = case t of
8a77240a809197c92c0736c431b4b88947a7bac1Christian Maeder FixDef fd -> pretty fd
8a77240a809197c92c0736c431b4b88947a7bac1Christian Maeder Case c l _ ->
fbc4f8708092d571a45cb483f37cc6b674da45a7Christian Maeder sep $ (keyword caseS <+> pretty c <+> keyword ofS)
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus Gross : prepPunctBar
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus Gross (map (\ (p, e) -> fsep [pretty p, implies, pretty e]) l)
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus Gross Let fd i _ -> sep [keyword letS <+> pretty fd <+> keyword inS, pretty i]
d56ece59c372cb887355825901222b9f3377f7e6Thiemo Wiedemeyer IfThenElse i d e _ ->
d56ece59c372cb887355825901222b9f3377f7e6Thiemo Wiedemeyer fsep [ keyword ifS <+> pretty i
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder , keyword thenS <+> pretty d
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder , keyword elseS <+> pretty e ]
f1dec6898638ba1131a9fadbc4d1544c93dfabb0Klaus LuettichfplReservedWords :: [String]
9175e29c044318498a40f323f189f9dfd50378efChristian MaederfplReservedWords = [barS, functS, caseS, ofS, letS]