SymbItems.hs revision ab0274ab68a174d3e92235b4c4ca865c03901583
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian MaederModule : $Header$
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian MaederDescription : syntactic csp-casl symbols
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederCopyright : (c) Christian Maeder, DFKI GmbH 2011
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
b4fbc96e05117839ca409f5f20f97b3ac872d1edTill MossakowskiMaintainer : Christian.Maeder@dfki.de
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian MaederStability : provisional
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaederPortability : portable
23a00c966f2aa8da525d7a7c51933c99964426c0Christian Maederimport Common.Doc hiding (braces)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport qualified Data.Set as Set
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata CspSymbItems = CspSymbItems CspSymbKind [CspSymb]
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder deriving (Show, Eq)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata CspSymbMapItems = CspSymbMapItems CspSymbKind [CspSymbMap]
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder deriving (Show, Eq)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata CspSymbKind = CaslKind SYMB_KIND | ProcessKind | ChannelKind
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Show, Eq, Ord)
eab576044505ba1fbc64610323053490fbd9e82cChristian Maederdata CspSymb = CspSymb Id (Maybe CspType)
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder deriving (Show, Eq)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- for channels with sorts we may re-use A_type that is ambiguous
eab576044505ba1fbc64610323053490fbd9e82cChristian Maederdata CspType = CaslType TYPE | ProcType ProcProfile
eab576044505ba1fbc64610323053490fbd9e82cChristian Maeder deriving (Show, Eq)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata CspSymbMap = CspSymbMap CspSymb (Maybe CspSymb)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Show, Eq)
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaederpluralCspSympKind :: CspSymbKind -> [a] -> Doc
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederpluralCspSympKind k l = case k of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder CaslKind c -> case c of
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder Implicit -> empty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> keyword $ pluralS_symb_list c l
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder ProcessKind -> keyword processS
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder ChannelKind -> keyword $ channelS ++ appendS l
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty CspSymbKind where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty k = pluralCspSympKind k [()]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty CspType where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty t = case t of
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder CaslType c -> colon <> pretty c
92aa1b88f02d2a413da60dba78acd34312e6f29aChristian Maeder ProcType p -> printProcProfile p
d92635f998347112e5d5803301c2abfe7832ab65Christian Maederinstance Pretty CspSymb where
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder pretty (CspSymb i ms) = pretty i <+> pretty ms
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty CspSymbMap where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty (CspSymbMap s ms) = pretty s <+> case ms of
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder Nothing -> empty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Just t -> mapsto <+> pretty t
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty CspSymbItems where
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder pretty (CspSymbItems k l) = pluralCspSympKind k l <+> ppWithCommas l
d48085f765fca838c1d972d2123601997174583dChristian Maederinstance Pretty CspSymbMapItems where
d48085f765fca838c1d972d2123601997174583dChristian Maeder pretty (CspSymbMapItems k l) = pluralCspSympKind k l <+> ppWithCommas l
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaederparseCspId :: GenParser Char st Id
d48085f765fca838c1d972d2123601997174583dChristian MaederparseCspId = parseId csp_casl_keywords
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaedercspSortId :: GenParser Char st SORT
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaedercspSortId = sortId csp_casl_keywords
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaederplainColon :: GenParser Char st ()
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaederplainColon = forget $ pToken $ toKey colonS
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaedercommType :: GenParser Char st CommType
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder s <- cspSortId
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder r <- cspSortId
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder if isSimpleId s
ae8052003e1ec7247597f034069db0939a7387e1Christian Maeder then return $ CommTypeChan $ TypedChanName (idToSimpleId s) r
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder else unexpected $ "sort " ++ show s
f875f7eebac7f69bf9da98c93479a542d0a8056fChristian Maeder <|> return (CommTypeSort s)
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaederbracedList :: GenParser Char st [CommType]
d48085f765fca838c1d972d2123601997174583dChristian MaederbracedList = braces $ commaSep1 commType
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaedercommAlpha :: GenParser Char st CommAlpha
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaedercommAlpha = fmap Set.fromList $ single commType <|> bracedList
d48085f765fca838c1d972d2123601997174583dChristian Maeder-- | parsing a possibly qualified identifier
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaedercspSymb :: GenParser Char st CspSymb
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder do i <- parseCspId
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder t <- fmap CaslType (opOrPredType csp_casl_keywords) <|>
d48085f765fca838c1d972d2123601997174583dChristian Maeder fmap (ProcType . ProcProfile []) commAlpha
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder return $ CspSymb i $ Just t
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder ts <- between oParenT cParenT $ commaSep1 cspSortId
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder cs <- commAlpha
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder return $ CspSymb i $ Just $ ProcType $ ProcProfile ts cs
d48085f765fca838c1d972d2123601997174583dChristian Maeder <|> return (CspSymb i Nothing)
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder-- | parsing one symbol or a mapping of one to second symbol
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaedercspSymbMap :: GenParser Char st CspSymbMap
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaedercspSymbMap = liftM2 CspSymbMap cspSymb $ optionMaybe
d48085f765fca838c1d972d2123601997174583dChristian Maeder $ pToken (toKey mapsTo) >> cspSymb
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder-- | parse a kind keyword
d48085f765fca838c1d972d2123601997174583dChristian MaedercspSymbKind :: GenParser Char st CspSymbKind
d48085f765fca838c1d972d2123601997174583dChristian Maeder fmap (const ChannelKind) (pluralKeyword channelS)
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder <|> fmap (const ProcessKind) (pToken $ toKey processS)
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder <|> fmap (CaslKind . fst) symbKind
d48085f765fca838c1d972d2123601997174583dChristian Maeder-- | parse a comma separated list of symbols
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedercspSymbs :: GenParser Char st [CspSymb]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder do s <- cspSymb
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder _ <- commaT `followedWith` parseCspId
eab576044505ba1fbc64610323053490fbd9e82cChristian Maeder is <- cspSymbs
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder return $ s : is
ae8052003e1ec7247597f034069db0939a7387e1Christian Maeder <|> return [s]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder{- | Parse a possible kinded list of comma separated CspCASL symbols.
d48085f765fca838c1d972d2123601997174583dChristian Maeder The argument is a list of keywords to avoid as identifiers. -}
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedercspSymbItems :: GenParser Char st CspSymbItems
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaedercspSymbItems = fmap (CspSymbItems $ CaslKind Implicit) cspSymbs <|> do
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder k <- cspSymbKind
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder fmap (CspSymbItems k) cspSymbs
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | parse a comma separated list of symbols
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaedercspSymbMaps :: GenParser Char st [CspSymbMap]
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maeder do s <- cspSymbMap
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ <- commaT `followedWith` parseCspId
37354e3ed68875fb527338105a610df481f98cb0Christian Maeder is <- cspSymbMaps
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder return $ s : is
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder <|> return [s]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | parse a possible kinded list of CspCASL symbol mappings
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedercspSymbMapItems :: GenParser Char st CspSymbMapItems
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedercspSymbMapItems = fmap (CspSymbMapItems $ CaslKind Implicit) cspSymbMaps
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder k <- cspSymbKind
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder fmap (CspSymbMapItems k) cspSymbMaps