SymbItems.hs revision e9458b1a7a19a63aa4c179f9ab20f4d50681c168
e83ed59502a681713982f25c559aae77a4145734Christian Maeder{-# LANGUAGE DeriveDataTypeable #-}
eb483f2216949400bfef8f6deb5320f071445626Christian MaederDescription : syntactic csp-casl symbols
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuCopyright : (c) Christian Maeder, DFKI GmbH 2011
eb483f2216949400bfef8f6deb5320f071445626Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederMaintainer : Christian.Maeder@dfki.de
eb483f2216949400bfef8f6deb5320f071445626Christian MaederStability : provisional
eb483f2216949400bfef8f6deb5320f071445626Christian MaederPortability : portable
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederimport Common.Doc hiding (braces)
e83ed59502a681713982f25c559aae77a4145734Christian Maederimport qualified Data.Set as Set
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederdata CspSymbItems = CspSymbItems CspSymbKind [CspSymb]
e83ed59502a681713982f25c559aae77a4145734Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederdata CspSymbMapItems = CspSymbMapItems CspSymbKind [CspSymbMap]
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
e83ed59502a681713982f25c559aae77a4145734Christian Maederdata CspSymbKind = CaslKind SYMB_KIND | ProcessKind | ChannelKind
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
e83ed59502a681713982f25c559aae77a4145734Christian Maederdata CspSymb = CspSymb Id (Maybe CspType)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder-- for channels with sorts we may re-use A_type that is ambiguous
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederdata CspType = CaslType TYPE | ProcType ProcProfile
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederdata CspSymbMap = CspSymbMap CspSymb (Maybe CspSymb)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder deriving (Show, Eq, Ord, Typeable, Data)
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederpluralCspSympKind :: CspSymbKind -> [a] -> Doc
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaederpluralCspSympKind k l = case k of
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder CaslKind c -> case c of
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder Implicit -> empty
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder _ -> keyword $ pluralS_symb_list c l
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder ProcessKind -> keyword processS
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder ChannelKind -> keyword $ channelS ++ appendS l
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maederinstance Pretty CspSymbKind where
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder pretty k = pluralCspSympKind k [()]
2eb84fc82d3ffa9116bc471fda3742bd9e5a24bbChristian Maederinstance Pretty CspType where
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder pretty t = case t of
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maeder CaslType c -> colon <> pretty c
2eb84fc82d3ffa9116bc471fda3742bd9e5a24bbChristian Maeder ProcType p -> printProcProfile p
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maederinstance Pretty CspSymb where
10b02b2343246df6773585636fe3ddbefa3b6a1bChristian Maeder pretty (CspSymb i ms) = pretty i <+> pretty ms
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowskiinstance Pretty CspSymbMap where
eb483f2216949400bfef8f6deb5320f071445626Christian Maeder pretty (CspSymbMap s ms) = pretty s <+> case ms of
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder Nothing -> empty
eb483f2216949400bfef8f6deb5320f071445626Christian Maeder Just t -> mapsto <+> pretty t
07b1bf56f3a486f26d69514d05b73100abb25a0eChristian Maederinstance Pretty CspSymbItems where
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder pretty (CspSymbItems k l) = pluralCspSympKind k l <+> ppWithCommas l
eb483f2216949400bfef8f6deb5320f071445626Christian Maederinstance Pretty CspSymbMapItems where
e83ed59502a681713982f25c559aae77a4145734Christian Maeder pretty (CspSymbMapItems k l) = pluralCspSympKind k l <+> ppWithCommas l
eb483f2216949400bfef8f6deb5320f071445626Christian MaedercommAlpha :: AParser st CommAlpha
eb483f2216949400bfef8f6deb5320f071445626Christian MaedercommAlpha = fmap Set.fromList $ single commType <|> bracedList
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder-- | parsing a possibly qualified identifier
083679daeba30fce9d60f7170a2cfd9f9c80bfb2Till MossakowskicspSymb :: AParser st CspSymb
083679daeba30fce9d60f7170a2cfd9f9c80bfb2Till Mossakowski do i <- parseCspId
e83ed59502a681713982f25c559aae77a4145734Christian Maeder t <- fmap CaslType (opOrPredType cspKeywords) <|>
e33e3b425e953236b4617870f995d263ac35b883Christian Maeder fmap (ProcType . ProcProfile []) commAlpha
3a3bbc51abf804d91bc9d8e0f2ce745cfae4c9c7Christian Maeder return $ CspSymb i $ Just t
083679daeba30fce9d60f7170a2cfd9f9c80bfb2Till Mossakowski ts <- parenList cspSortId
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder cs <- commAlpha
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder return $ CspSymb i $ Just $ ProcType $ ProcProfile ts cs
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder <|> return (CspSymb i Nothing)
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder-- | parsing one symbol or a mapping of one to second symbol
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian MaedercspSymbMap :: AParser st CspSymbMap
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian MaedercspSymbMap = liftM2 CspSymbMap cspSymb $ optionMaybe
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder $ asKey mapsTo >> optional cspSymbKind >> cspSymb
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder-- | parse a kind keyword
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian MaedercspSymbKind :: AParser st CspSymbKind
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder fmap (const ChannelKind) (pluralKeyword channelS)
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder <|> fmap (const ProcessKind) (asKey processS)
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder <|> fmap (CaslKind . fst) symbKind
743178d5294deadc2ed15e56b5e58ca0e7101fe4Christian Maeder-- | parse a comma separated list of symbols
72b8c0349a58cf0eb361cb5bb410d95a0372900acmaedercspSymbs :: AParser st [CspSymb]
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder do s <- cspSymb
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder _ <- commaT `followedWith` parseCspId
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder is <- cspSymbs
743178d5294deadc2ed15e56b5e58ca0e7101fe4Christian Maeder return $ s : is
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder <|> return [s]
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder{- | Parse a possible kinded list of comma separated CspCASL symbols.
f30760456a3b6f7d4d54c65323dbc73cceca68fbChristian Maeder The argument is a list of keywords to avoid as identifiers. -}
743178d5294deadc2ed15e56b5e58ca0e7101fe4Christian MaedercspSymbItems :: AParser st CspSymbItems
743178d5294deadc2ed15e56b5e58ca0e7101fe4Christian MaedercspSymbItems = fmap (CspSymbItems $ CaslKind Implicit) cspSymbs <|> do
083679daeba30fce9d60f7170a2cfd9f9c80bfb2Till Mossakowski k <- cspSymbKind
eb483f2216949400bfef8f6deb5320f071445626Christian Maeder fmap (CspSymbItems k) cspSymbs
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder-- | parse a comma separated list of symbols
7e4157a70efe2acab30dbe5079bba6db90923785Christian MaedercspSymbMaps :: AParser st [CspSymbMap]
eb483f2216949400bfef8f6deb5320f071445626Christian Maeder do s <- cspSymbMap
1865083b72c1307e9040d78c2743abd5a54ee260Christian Maeder _ <- commaT `followedWith` parseCspId
eb483f2216949400bfef8f6deb5320f071445626Christian Maeder is <- cspSymbMaps
eb483f2216949400bfef8f6deb5320f071445626Christian Maeder return $ s : is
eb483f2216949400bfef8f6deb5320f071445626Christian Maeder <|> return [s]
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder-- | parse a possible kinded list of CspCASL symbol mappings
c58a5efdb3c9fbc80deb1c69716f09c67292a41dChristian MaedercspSymbMapItems :: AParser st CspSymbMapItems
9929f81562adecc8aafaefb14a0159afcf4a3351Christian MaedercspSymbMapItems = fmap (CspSymbMapItems $ CaslKind Implicit) cspSymbMaps
585094c4284ed39eb8024cc1178c823c403200faChristian Maeder k <- cspSymbKind
9929f81562adecc8aafaefb14a0159afcf4a3351Christian Maeder fmap (CspSymbMapItems k) cspSymbMaps