SymbItems.hs revision ab0274ab68a174d3e92235b4c4ca865c03901583
abd8dd44106c507dd2cb64359b63d7d56fa0a9c8Christian Maeder{- |
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
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder-}
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maedermodule CspCASL.SymbItems where
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maederimport CspCASL.AS_CspCASL_Process
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport CspCASL.CspCASL_Keywords
d48085f765fca838c1d972d2123601997174583dChristian Maederimport CspCASL.Print_CspCASL
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport CASL.AS_Basic_CASL
0df692ce8b9293499b2e1768458613a63e7b5cd0Christian Maederimport CASL.SymbolParser
d48085f765fca838c1d972d2123601997174583dChristian Maederimport CASL.ToDoc
47d6bc7bc9a708427f96be8d805f712697ad3d9eChristian Maeder
23a00c966f2aa8da525d7a7c51933c99964426c0Christian Maederimport Common.Doc hiding (braces)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport Common.DocUtils
8a6b503b50c0be589f12eb0d4ebeb4b4312fd491Christian Maederimport Common.Id
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maederimport Common.Keywords
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian Maederimport Common.Lexer
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian Maederimport Common.Parsec
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian Maederimport Common.Token
3c5cc698b0c061209ff83eb8de027daef5ae922aChristian Maeder
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maederimport Text.ParserCombinators.Parsec
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maederimport Control.Monad
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport qualified Data.Set as Set
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata CspSymbItems = CspSymbItems CspSymbKind [CspSymb]
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian Maeder deriving (Show, Eq)
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata CspSymbMapItems = CspSymbMapItems CspSymbKind [CspSymbMap]
ce3928e71520030ad0275b72050a8f4377f9313cChristian Maeder deriving (Show, Eq)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata CspSymbKind = CaslKind SYMB_KIND | ProcessKind | ChannelKind
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Show, Eq, Ord)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
eab576044505ba1fbc64610323053490fbd9e82cChristian Maederdata CspSymb = CspSymb Id (Maybe CspType)
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder deriving (Show, Eq)
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maeder
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 Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata CspSymbMap = CspSymbMap CspSymb (Maybe CspSymb)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Show, Eq)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
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
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty CspSymbKind where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder pretty k = pluralCspSympKind k [()]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
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
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
d92635f998347112e5d5803301c2abfe7832ab65Christian Maederinstance Pretty CspSymb where
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder pretty (CspSymb i ms) = pretty i <+> pretty ms
81946e2b3f6dde6167f48769bd02c7a634736856Christian Maeder
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
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Pretty CspSymbItems where
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder pretty (CspSymbItems k l) = pluralCspSympKind k l <+> ppWithCommas l
024621f43239cfe9629e35d35a8669fad7acbba2Christian Maeder
d48085f765fca838c1d972d2123601997174583dChristian Maederinstance Pretty CspSymbMapItems where
d48085f765fca838c1d972d2123601997174583dChristian Maeder pretty (CspSymbMapItems k l) = pluralCspSympKind k l <+> ppWithCommas l
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaederparseCspId :: GenParser Char st Id
d48085f765fca838c1d972d2123601997174583dChristian MaederparseCspId = parseId csp_casl_keywords
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaedercspSortId :: GenParser Char st SORT
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaedercspSortId = sortId csp_casl_keywords
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaederplainColon :: GenParser Char st ()
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaederplainColon = forget $ pToken $ toKey colonS
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder
8452387b4c54b8dd36c012b216e0b0c5004ca6f1Christian MaedercommType :: GenParser Char st CommType
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian MaedercommType = do
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder s <- cspSortId
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder do
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder plainColon
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 Maeder
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaederbracedList :: GenParser Char st [CommType]
d48085f765fca838c1d972d2123601997174583dChristian MaederbracedList = braces $ commaSep1 commType
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaedercommAlpha :: GenParser Char st CommAlpha
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaedercommAlpha = fmap Set.fromList $ single commType <|> bracedList
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder
d48085f765fca838c1d972d2123601997174583dChristian Maeder-- | parsing a possibly qualified identifier
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaedercspSymb :: GenParser Char st CspSymb
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaedercspSymb =
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder do i <- parseCspId
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder do
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder _ <- colonST
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder t <- fmap CaslType (opOrPredType csp_casl_keywords) <|>
d48085f765fca838c1d972d2123601997174583dChristian Maeder fmap (ProcType . ProcProfile []) commAlpha
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder return $ CspSymb i $ Just t
d48085f765fca838c1d972d2123601997174583dChristian Maeder <|> do
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder ts <- between oParenT cParenT $ commaSep1 cspSortId
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder plainColon
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder cs <- commAlpha
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder return $ CspSymb i $ Just $ ProcType $ ProcProfile ts cs
d48085f765fca838c1d972d2123601997174583dChristian Maeder <|> return (CspSymb i Nothing)
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder
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
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder-- | parse a kind keyword
d48085f765fca838c1d972d2123601997174583dChristian MaedercspSymbKind :: GenParser Char st CspSymbKind
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian MaedercspSymbKind =
d48085f765fca838c1d972d2123601997174583dChristian Maeder fmap (const ChannelKind) (pluralKeyword channelS)
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder <|> fmap (const ProcessKind) (pToken $ toKey processS)
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder <|> fmap (CaslKind . fst) symbKind
d48085f765fca838c1d972d2123601997174583dChristian Maeder
d48085f765fca838c1d972d2123601997174583dChristian Maeder-- | parse a comma separated list of symbols
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedercspSymbs :: GenParser Char st [CspSymb]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedercspSymbs =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder do s <- cspSymb
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder do
68485f7bfab1b4c6f963ce6837cba5fb148ed625Christian Maeder _ <- commaT `followedWith` parseCspId
eab576044505ba1fbc64610323053490fbd9e82cChristian Maeder is <- cspSymbs
a59f2017dfc311ece7afcea3e8a3ceceac77ba5aChristian Maeder return $ s : is
ae8052003e1ec7247597f034069db0939a7387e1Christian Maeder <|> return [s]
eab576044505ba1fbc64610323053490fbd9e82cChristian Maeder
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
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | parse a comma separated list of symbols
413db961f13e112716509b6d61d7a7bbf50c98b2Christian MaedercspSymbMaps :: GenParser Char st [CspSymbMap]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedercspSymbMaps =
48c4688439e0aade4faeebf25ca8b16d661e47afChristian Maeder do s <- cspSymbMap
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder do
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ <- commaT `followedWith` parseCspId
37354e3ed68875fb527338105a610df481f98cb0Christian Maeder is <- cspSymbMaps
413db961f13e112716509b6d61d7a7bbf50c98b2Christian Maeder return $ s : is
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder <|> return [s]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
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 <|> do
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder k <- cspSymbKind
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder fmap (CspSymbMapItems k) cspSymbMaps
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder