BasicItem.hs revision 06f705bf47fb35616a414843a7b754b8d319d7bd
2b873214c9ab511bbca437c036371ab664aedaceChristian Maedermodule BasicItem where
54ed6a6b1a6c7d27fadb39ec5b59d0806c81f7c8Christian Maederimport LocalEnv
75a6279dbae159d018ef812185416cf6df386c10Till Mossakowskiimport ParseTerm
75a6279dbae159d018ef812185416cf6df386c10Till Mossakowskiimport ParseType
dda5ab793f1615c1ba1dcaa97a4346b0878da6b1Christian MaederisSigStartKeyword s = s `elem` (words "sort sorts op ops pred preds type types var vars axiom axioms forall free generated .")
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian Maedermapf :: (Functor f) => f a -> (a -> b) -> f b
0799b5dc3f06d2640e66e9ab54b8b217348fd719Christian Maedermapf = flip fmap
52d922076b89f12234f721974e82531bc69a6f69Christian MaederpluralKeyword s = makeToken (string s <++> option "" (string "s"))
43b4c41fbb07705c9df321221ab9cb9832460407Christian MaedersortId = parseId
4c8d3c5a9e938633f6147b5a595b9b93bfca99e6Christian MaederopId = parseId
fbc4f8708092d571a45cb483f37cc6b674da45a7Christian MaederoptSemi = bind (\ x y -> (x, y)) (option Nothing (fmap Just semi)) ann
fbc4f8708092d571a45cb483f37cc6b674da45a7Christian MaedertopVarDecls t = do { l <- varDecl t
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski ; (m, an) <- optSemi
f77f29e84b3f6e791c82e61b13fbf76582bedd2fChristian Maeder ; let h:t = reverse l
dda5ab793f1615c1ba1dcaa97a4346b0878da6b1Christian Maeder h2 = h {declAn = an}
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder l2 = reverse (h2:t)
f66fcd981f556c238df7dd6dfa42123745e3b1d2Christian Maeder case m of Nothing -> return l2
c0c2380bced8159ff0297ece14eba948bd236471Christian Maeder Just key -> do { r <- option [] (try (topVarDecls key))
da333ffa6336cf59a4071fcddad358c5eafd3e61Sonja Gröning ; return (l2 ++ r)
fc1a590cd3ee36797c0a032ff41e07f8e2469341Christian Maederdata ParsedSortItems = AllLess [(Token, Id)] (Maybe (Token, Id))
a2b04db3e156312a8596d8084f7f0f51acf8a96bChristian Maeder | AllEqual [(Token, Id)]
0c885f1348fd58f7cb706472a3ff20b52dbef0a7Jonathan von Schroeder | SubType (Token, Id) Type Term
fc1a590cd3ee36797c0a032ff41e07f8e2469341Christian Maeder deriving (Show)
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian MaedercommaSortDecl :: [(Token, Id)] -> Parser ParsedSortItems
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian MaedercommaSortDecl l = do { c <- comma
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder ; s <- sortId
6e52f1dfc0da4bc4a7701cf856641c9dce08fc7dChristian Maeder ; let l2 = (c, s) : l in
923e25bb8c7cf9f2978c7844ad173704482cc3b0Martin Kühl commaSortDecl l2
9f85afecbd79b3df5a0bb17bd28cd0b288dc3213Kristina Sojakova <|> subSortDecl l2
63da71bfb4226f504944b293fb77177ebcaea7d4Ewaryst Schulz <|> return (AllLess l2 Nothing)
14c89b2d830777bf4db2850f038c9f60acaca486Christian MaederequalSortDecl :: Token -> [(Token, Id)] -> Parser [(Token, Id)]
57026bc09337d158b89775048a9bcc9c17d825caChristian MaederequalSortDecl e l = do { s2 <- sortId
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder ; let l2 = (e, s2):l in
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder option l2 (do { e2 <- equal
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder ; equalSortDecl e2 l2
2b873214c9ab511bbca437c036371ab664aedaceChristian Maederequal = skipChar '='
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian MaederisoDecl :: Token -> Id -> Parser ParsedSortItems
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian MaederisoDecl key s1 = do { e <- equal
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder ; subSortDefn key s1
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus Gross (do { l <- equalSortDecl e [(key, s1)]
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus Gross ; return (AllEqual l)
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maederbar = skipChar '|'
a31430de8b0632d29f42634d6395e982bf31b14dChristian MaedersubSortDefn :: Token -> Id -> Parser ParsedSortItems
a31430de8b0632d29f42634d6395e982bf31b14dChristian MaedersubSortDefn key s = do { o <- oBrace
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder ; t <- funType c
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder ; e <- mixTerm
a31430de8b0632d29f42634d6395e982bf31b14dChristian Maeder ; let f = Binding SupersortVar [Decl (Symb v t) o []] e
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder in return (SubType (key, s) t f)
9175e29c044318498a40f323f189f9dfd50378efChristian MaedersubSortDecl :: [(Token, Id)] -> Parser ParsedSortItems
9175e29c044318498a40f323f189f9dfd50378efChristian MaedersubSortDecl l = do { t <- skipChar '<'
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder ; s <- sortId
ee1c7c5796832536932d7b06cbfb1ca13f9a0d7bMartin Kühl ; return (AllLess l (Just (t, s)))
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian MaedersortItem :: Token -> Parser ParsedSortItems
f63e7684d8db7503c22e5d8d499c94a9405f8f9eChristian MaedersortItem key = do { s1 <- sortId
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ; subSortDecl [(key, s1)]
bdc103981a28a51938de98a956d8a3767f6cf43dAivaras Jakubauskas commaSortDecl [(key, s1)]
e1ea9a046e9640148ca876dfe47e391559a9fdf3Christian Maeder isoDecl key s1
57026bc09337d158b89775048a9bcc9c17d825caChristian Maeder return (AllLess [(key, s1)] Nothing)
7bbfb15142ab4286dfc6fcde2fc94a5512297e41Jonathan von SchroedertoSymb s = Symb s Sort
fa388aea9cef5f9734fec346159899a74432ce26Christian MaedermkItem :: [Type] -> [Type] -> (Token, Id) -> SortItem
63719301448519453f66383f4e583d9fd5b89ecbChristian MaedermkItem subs supers (key, id) =
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder SortItem (Decl (toSymb id) key []) (SortRels subs supers) Nothing []
52d922076b89f12234f721974e82531bc69a6f69Christian MaederasSortItems :: ParsedSortItems -> [SortItem]
52d922076b89f12234f721974e82531bc69a6f69Christian MaederasSortItems (AllLess l m) =
923e25bb8c7cf9f2978c7844ad173704482cc3b0Martin Kühl let p = maybeToList m
9f85afecbd79b3df5a0bb17bd28cd0b288dc3213Kristina Sojakova f = map (asType . snd)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder sis = map (mkItem [] super) l
fbc4f8708092d571a45cb483f37cc6b674da45a7Christian Maeder subs = reverse (f l)
8a77240a809197c92c0736c431b4b88947a7bac1Christian Maeder supers = map (mkItem subs []) p
8a77240a809197c92c0736c431b4b88947a7bac1Christian Maeder in supers ++ sis
bb63f684c4f5f33ffcd1dcc02c58d6a703900fafJonathan von SchroederasSortItems (AllEqual l) =
b0234f0a84fcd3587073fbc11d38759108997c3cChristian Maeder let types = reverse (map (asType . snd) l)
b0234f0a84fcd3587073fbc11d38759108997c3cChristian Maeder sorts = map (mkItem types types) l
8ef91a173e69219fc2ebd45c76a35891c7785abdMarkus Gross in sorts -- maybe delete self
d56ece59c372cb887355825901222b9f3377f7e6Thiemo WiedemeyerasSortItems (SubType p t e) =
d56ece59c372cb887355825901222b9f3377f7e6Thiemo Wiedemeyer [(mkItem [] [t] p) {sortDef = Just (SubsortDefn e)}]
9175e29c044318498a40f323f189f9dfd50378efChristian MaedersortItemsAux sig key = do { si <- sortItem key;
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder (m, an) <- optSemi;
f1dec6898638ba1131a9fadbc4d1544c93dfabb0Klaus Luettich let (l:li) = asSortItems si
9175e29c044318498a40f323f189f9dfd50378efChristian Maeder li2 = (l {sortAn = an}) : li
f77f29e84b3f6e791c82e61b13fbf76582bedd2fChristian Maeder sig2 = sig {sorts = li2 ++ sorts sig}