SortItem.hs revision 2b4130336e941b7d01c78a6da55449a4c6eca609
194cecef338e680beb0a1068820b931a065d2df7Christian MaederModule : $Header$
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerCopyright : (c) Christian Maeder, Uni Bremen 2002-2004
e6d40133bc9f858308654afb1262b8b483ec5922Till MossakowskiLicence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuMaintainer : hets@tzi.de
194cecef338e680beb0a1068820b931a065d2df7Christian MaederStability : provisional
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederPortability : portable
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder parse SORT-ITEM and "sort/sorts SORT-ITEM ; ... ; SORT-ITEM"
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder parse DATATYPE-DECL
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder http://www.cofi.info/Documents/CASL/Summary/
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder from 25 March 2001
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder C.2.1 Basic Specifications with Subsorts
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maedermodule CASL.SortItem (sortItem, datatype) where
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder-- ------------------------------------------------------------------------
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder-- ------------------------------------------------------------------------
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaedercommaSortDecl :: AParsable f => Id -> AParser (SORT_ITEM f)
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaedercommaSortDecl s = do c <- anComma
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder (is, cs) <- sortId `separatedBy` anComma
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder let l = s : is
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder p = map tokPos (c:cs) in
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder subSortDecl (l, p) <|> return (Sort_decl l p)
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaederisoDecl :: AParsable f => Id -> AParser (SORT_ITEM f)
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaederisoDecl s = do e <- equalT
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder subSortDefn (s, tokPos e)
e939fe8b1e6257f1dfa1cf9af5b7cae05a9f1fd3Christian Maeder (do (l, p) <- sortId `separatedBy` equalT
e939fe8b1e6257f1dfa1cf9af5b7cae05a9f1fd3Christian Maeder return (Iso_decl (s:l) (map tokPos (e:p))))
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaedersubSortDefn :: AParsable f => (Id, Pos) -> AParser (SORT_ITEM f)
e939fe8b1e6257f1dfa1cf9af5b7cae05a9f1fd3Christian MaedersubSortDefn (s, e) = do a <- annos
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder d <- dotT -- or bar
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder return $ Subsort_defn s v t (Annoted f [] a [])
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder (e: map tokPos [o, c, d, p])
194cecef338e680beb0a1068820b931a065d2df7Christian MaedersubSortDecl :: AParsable f => ([Id], [Pos]) -> AParser (SORT_ITEM f)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersubSortDecl (l, p) = do t <- lessT
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder return (Subsort_decl l s (p++[tokPos t]))
6bcdf8fc684a7a2d03f41bba002cfeaa0fbe023cChristian MaedersortItem :: AParsable f => AParser (SORT_ITEM f)
194cecef338e680beb0a1068820b931a065d2df7Christian MaedersortItem = do s <- sortId ;
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder subSortDecl ([s],[])
6bcdf8fc684a7a2d03f41bba002cfeaa0fbe023cChristian Maeder commaSortDecl s
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder return (Sort_decl [s] [])
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder-- ------------------------------------------------------------------------
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder-- ------------------------------------------------------------------------
194cecef338e680beb0a1068820b931a065d2df7Christian Maederdatatype :: AParser DATATYPE_DECL
f33851e1c75604b241f6dc576fbe8d80851c1126Christian Maederdatatype = do s <- sortId
e4626e80ac00fcde9413b6c53f81618ff9314cbbChristian Maeder e <- asKey defnS
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder (Annoted v _ _ b:as, ps) <- aAlternative
f33851e1c75604b241f6dc576fbe8d80851c1126Christian Maeder `separatedBy` barT
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder return (Datatype_decl s (Annoted v [] a b:as)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder (map tokPos (e:ps)))
194cecef338e680beb0a1068820b931a065d2df7Christian MaederaAlternative :: AParser (Annoted ALTERNATIVE)
194cecef338e680beb0a1068820b931a065d2df7Christian MaederaAlternative = do a <- alternative
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder return (Annoted a [] [] an)
e4626e80ac00fcde9413b6c53f81618ff9314cbbChristian Maederalternative :: AParser ALTERNATIVE
194cecef338e680beb0a1068820b931a065d2df7Christian Maederalternative = do s <- pluralKeyword sortS
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder (ts, cs) <- sortId `separatedBy` anComma
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder return (Subsorts ts (map tokPos (s:cs)))
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder do i <- consId
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder do o <- oParenT
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder (cs, ps) <- component `separatedBy` anSemi
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder let qs = toPos o ps c in
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder do q <- quMarkT
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder return (Partial_construct i cs
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder (qs++[tokPos q]))
194cecef338e680beb0a1068820b931a065d2df7Christian Maeder <|> return (Total_construct i cs qs)
6bcdf8fc684a7a2d03f41bba002cfeaa0fbe023cChristian Maeder <|> return (Total_construct i [] [])
6bcdf8fc684a7a2d03f41bba002cfeaa0fbe023cChristian MaederisSortId :: Id -> Bool
6bcdf8fc684a7a2d03f41bba002cfeaa0fbe023cChristian MaederisSortId (Id is _ _) = case is of
6bcdf8fc684a7a2d03f41bba002cfeaa0fbe023cChristian Maeder [Token (c:_) _] -> c `elem` caslLetters
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maedercomponent :: AParser COMPONENTS
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maedercomponent = do (is, cs) <- parseId `separatedBy` anComma
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder if isSingle is && isSortId (head is) then
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder compSort is cs
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder <|> return (Sort (head is))
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder else compSort is cs
f1ef1c750f805c1732b01001f2b157c0077b808eChristian MaedercompSort :: [OP_NAME] -> [Token] -> AParser COMPONENTS
f1ef1c750f805c1732b01001f2b157c0077b808eChristian MaedercompSort is cs = do c <- colonST
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder (b, t, _) <- opSort
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder let p = map tokPos (cs++[c]) in
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder return (if b then Partial_select is t p
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder else Total_select is t p)