SymbItems.hs revision 38504dc968167ba2e82dd568edeae8d6af4dc145
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian Maeder{- |
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederModule : $Header$
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederDescription : syntactic csp-casl symbols
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederCopyright : (c) Christian Maeder, DFKI GmbH 2011
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederMaintainer : Christian.Maeder@dfki.de
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederStability : provisional
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederPortability : portable
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian Maeder
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian Maeder-}
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian Maeder
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maedermodule CspCASL.SymbItems where
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maederimport CspCASL.AS_CspCASL_Process
9f93b2a8b552789cd939d599504d39732672dc84Christian Maederimport CspCASL.CspCASL_Keywords
9f93b2a8b552789cd939d599504d39732672dc84Christian Maederimport CspCASL.Print_CspCASL
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maederimport CspCASL.Parse_CspCASL_Process
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maederimport CASL.AS_Basic_CASL
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport CASL.SymbolParser
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maederimport CASL.ToDoc
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
d3f192025f2836285d9705a959542350e057f281Christian Maederimport Common.AnnoState
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport Common.Doc hiding (braces)
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian Maederimport Common.DocUtils
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maederimport Common.Id
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport Common.Keywords
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport Common.Lexer
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport Common.Parsec
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport Common.Token
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport Text.ParserCombinators.Parsec
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport Control.Monad
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport qualified Data.Set as Set
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspSymbItems = CspSymbItems CspSymbKind [CspSymb]
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder deriving (Show, Eq)
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspSymbMapItems = CspSymbMapItems CspSymbKind [CspSymbMap]
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder deriving (Show, Eq)
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspSymbKind = CaslKind SYMB_KIND | ProcessKind | ChannelKind
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder deriving (Show, Eq, Ord)
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspSymb = CspSymb Id (Maybe CspType)
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder deriving (Show, Eq)
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder-- for channels with sorts we may re-use A_type that is ambiguous
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspType = CaslType TYPE | ProcType ProcProfile
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder deriving (Show, Eq)
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederdata CspSymbMap = CspSymbMap CspSymb (Maybe CspSymb)
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder deriving (Show, Eq)
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian Maeder
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaederpluralCspSympKind :: CspSymbKind -> [a] -> Doc
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaederpluralCspSympKind k l = case k of
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder CaslKind c -> case c of
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder Implicit -> empty
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder _ -> keyword $ pluralS_symb_list c l
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder ProcessKind -> keyword processS
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder ChannelKind -> keyword $ channelS ++ appendS l
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maederinstance Pretty CspSymbKind where
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder pretty k = pluralCspSympKind k [()]
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian Maeder
9f93b2a8b552789cd939d599504d39732672dc84Christian Maederinstance Pretty CspType where
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder pretty t = case t of
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder CaslType c -> colon <> pretty c
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder ProcType p -> printProcProfile p
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Pretty CspSymb where
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder pretty (CspSymb i ms) = pretty i <+> pretty ms
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Pretty CspSymbMap where
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder pretty (CspSymbMap s ms) = pretty s <+> case ms of
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder Nothing -> empty
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder Just t -> mapsto <+> pretty t
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Pretty CspSymbItems where
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder pretty (CspSymbItems k l) = pluralCspSympKind k l <+> ppWithCommas l
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Pretty CspSymbMapItems where
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder pretty (CspSymbMapItems k l) = pluralCspSympKind k l <+> ppWithCommas l
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
d3f192025f2836285d9705a959542350e057f281Christian MaedercommType :: AParser st CommType
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercommType = do
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder s <- cspSortId
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder do
d3f192025f2836285d9705a959542350e057f281Christian Maeder colonT
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder r <- cspSortId
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder if isSimpleId s
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder then return $ CommTypeChan $ TypedChanName (idToSimpleId s) r
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder else unexpected $ "sort " ++ show s
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder <|> return (CommTypeSort s)
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder
d3f192025f2836285d9705a959542350e057f281Christian MaederbracedList :: AParser st [CommType]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederbracedList = braces $ commaSep1 commType
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder
d3f192025f2836285d9705a959542350e057f281Christian MaedercommAlpha :: AParser st CommAlpha
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercommAlpha = fmap Set.fromList $ single commType <|> bracedList
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parsing a possibly qualified identifier
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymb :: AParser st CspSymb
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymb =
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder do i <- parseCspId
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder do
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder _ <- colonST
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder t <- fmap CaslType (opOrPredType cspKeywords) <|>
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder fmap (ProcType . ProcProfile []) commAlpha
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder return $ CspSymb i $ Just t
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> do
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder ts <- between oParenT cParenT $ commaSep1 cspSortId
d3f192025f2836285d9705a959542350e057f281Christian Maeder colonT
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder cs <- commAlpha
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder return $ CspSymb i $ Just $ ProcType $ ProcProfile ts cs
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> return (CspSymb i Nothing)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parsing one symbol or a mapping of one to second symbol
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbMap :: AParser st CspSymbMap
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbMap = liftM2 CspSymbMap cspSymb $ optionMaybe
499b6cb3ab95a336a324545123e18f387ee4d2a3Christian Maeder $ asKey mapsTo >> optional cspSymbKind >> cspSymb
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parse a kind keyword
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbKind :: AParser st CspSymbKind
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedercspSymbKind =
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder fmap (const ChannelKind) (pluralKeyword channelS)
d3f192025f2836285d9705a959542350e057f281Christian Maeder <|> fmap (const ProcessKind) (asKey processS)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> fmap (CaslKind . fst) symbKind
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parse a comma separated list of symbols
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbs :: AParser st [CspSymb]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbs =
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder do s <- cspSymb
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder do
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder _ <- commaT `followedWith` parseCspId
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder is <- cspSymbs
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder return $ s : is
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> return [s]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder{- | Parse a possible kinded list of comma separated CspCASL symbols.
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder The argument is a list of keywords to avoid as identifiers. -}
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbItems :: AParser st CspSymbItems
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbItems = fmap (CspSymbItems $ CaslKind Implicit) cspSymbs <|> do
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder k <- cspSymbKind
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder fmap (CspSymbItems k) cspSymbs
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parse a comma separated list of symbols
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbMaps :: AParser st [CspSymbMap]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbMaps =
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder do s <- cspSymbMap
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder do
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder _ <- commaT `followedWith` parseCspId
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder is <- cspSymbMaps
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder return $ s : is
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> return [s]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parse a possible kinded list of CspCASL symbol mappings
d3f192025f2836285d9705a959542350e057f281Christian MaedercspSymbMapItems :: AParser st CspSymbMapItems
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbMapItems = fmap (CspSymbMapItems $ CaslKind Implicit) cspSymbMaps
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> do
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder k <- cspSymbKind
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder fmap (CspSymbMapItems k) cspSymbMaps