Cross Reference: /hets/CspCASL/SymbItems.hs
SymbItems.hs revision ab0274ab68a174d3e92235b4c4ca865c03901583
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maederimport CASL.AS_Basic_CASL
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport CASL.SymbolParser
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maederimport CASL.ToDoc
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
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
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederparseCspId :: GenParser Char st Id
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederparseCspId = parseId csp_casl_keywords
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSortId :: GenParser Char st SORT
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSortId = sortId csp_casl_keywords
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederplainColon :: GenParser Char st ()
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederplainColon = forget $ pToken $ toKey colonS
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercommType :: GenParser Char st CommType
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercommType = do
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder s <- cspSortId
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder do
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder plainColon
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
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederbracedList :: GenParser Char st [CommType]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederbracedList = braces $ commaSep1 commType
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercommAlpha :: GenParser Char st CommAlpha
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercommAlpha = fmap Set.fromList $ single commType <|> bracedList
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parsing a possibly qualified identifier
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymb :: GenParser Char st CspSymb
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymb =
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder do i <- parseCspId
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder do
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder _ <- colonST
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder t <- fmap CaslType (opOrPredType csp_casl_keywords) <|>
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder fmap (ProcType . ProcProfile []) commAlpha
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder return $ CspSymb i $ Just t
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> do
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder ts <- between oParenT cParenT $ commaSep1 cspSortId
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder plainColon
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
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbMap :: GenParser Char st CspSymbMap
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbMap = liftM2 CspSymbMap cspSymb $ optionMaybe
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder $ pToken (toKey mapsTo) >> cspSymb
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parse a kind keyword
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian MaedercspSymbKind :: GenParser Char st CspSymbKind
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedercspSymbKind =
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder fmap (const ChannelKind) (pluralKeyword channelS)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> fmap (const ProcessKind) (pToken $ toKey processS)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> fmap (CaslKind . fst) symbKind
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | parse a comma separated list of symbols
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbs :: GenParser Char 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. -}
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbItems :: GenParser Char 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
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbMaps :: GenParser Char 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
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbMapItems :: GenParser Char st CspSymbMapItems
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercspSymbMapItems = fmap (CspSymbMapItems $ CaslKind Implicit) cspSymbMaps
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder <|> do
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder k <- cspSymbKind
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder fmap (CspSymbMapItems k) cspSymbMaps