-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathAS_Maude.hs
231 lines (180 loc) · 6.3 KB
/
AS_Maude.hs
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
{-# LANGUAGE DeriveDataTypeable #-}
{- |
Module : ./Maude/AS_Maude.hs
Description : Abstract Maude Syntax
Copyright : (c) DFKI GmbH 2009
License : GPLv2 or higher, see LICENSE.txt
Maintainer : ariesco@fdi.ucm.es
Stability : experimental
Portability : portable
The abstract syntax of maude. Basic specs are a list of statements excluding
imports. Sentences are equations, membership axioms, and rules. Sort, subsort
and operations should be converted to signature.
Because maude parses and typechecks an input string in one go, basic specs for
the logic instance are just a wrapped string that is created by a simple
parser.
-}
module Maude.AS_Maude where
import Common.Id hiding (Id)
import Common.Doc (specBraces, text)
import Common.DocUtils (Pretty (..))
import Data.Data
-- * Types
newtype MaudeText = MaudeText String deriving (Show, Typeable)
instance Pretty MaudeText where
pretty (MaudeText s) = specBraces $ text s
instance GetRange MaudeText
type Qid = Token
data Spec = SpecMod Module
| SpecTh Module
| SpecView View
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Module = Module ModId [Parameter] [Statement]
deriving (Show, Read, Ord, Eq, Typeable, Data)
data View = View ModId ModExp ModExp [Renaming]
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Parameter = Parameter Sort ModExp
deriving (Show, Read, Ord, Eq, Typeable, Data)
data ModExp = ModExp ModId
| SummationModExp ModExp ModExp
| RenamingModExp ModExp [Renaming]
| InstantiationModExp ModExp [ViewId]
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Renaming = SortRenaming Sort Sort
| LabelRenaming LabelId LabelId
| OpRenaming1 OpId ToPartRenaming
| OpRenaming2 OpId [Type] Type ToPartRenaming
| TermMap Term Term
deriving (Show, Read, Ord, Eq, Typeable, Data)
data ToPartRenaming = To OpId [Attr]
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Statement = ImportStmnt Import
| SortStmnt Sort
| SubsortStmnt SubsortDecl
| OpStmnt Operator
| EqStmnt Equation
| MbStmnt Membership
| RlStmnt Rule
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Import = Including ModExp
| Extending ModExp
| Protecting ModExp
deriving (Show, Read, Ord, Eq, Typeable, Data)
data SubsortDecl = Subsort Sort Sort
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Operator = Op OpId [Type] Type [Attr]
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Membership = Mb Term Sort [Condition] [StmntAttr]
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Equation = Eq Term Term [Condition] [StmntAttr]
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Rule = Rl Term Term [Condition] [StmntAttr]
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Condition = EqCond Term Term
| MbCond Term Sort
| MatchCond Term Term
| RwCond Term Term
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Attr = Assoc
| Comm
| Idem
| Iter
| Id Term
| LeftId Term
| RightId Term
| Strat [Int]
| Memo
| Prec Int
| Gather [Qid]
| Format [Qid]
| Ctor
| Config
| Object
| Msg
| Frozen [Int]
| Poly [Int]
| Special [Hook]
deriving (Show, Read, Ord, Eq, Typeable, Data)
data StmntAttr = Label Qid
| Metadata String
| Owise
| Nonexec
| Print [Qid]
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Hook = IdHook Qid [Qid]
| OpHook Qid Qid [Qid] Qid
| TermHook Qid Term
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Term = Const Qid Type
| Var Qid Type
| Apply Qid [Term] Type
deriving (Show, Read, Ord, Eq, Typeable, Data)
data Type = TypeSort Sort
| TypeKind Kind
deriving (Show, Read, Ord, Eq, Typeable, Data)
newtype Sort = SortId Qid
deriving (Show, Read, Ord, Eq, Typeable, Data)
newtype Kind = KindId Qid
deriving (Show, Read, Ord, Eq, Typeable, Data)
newtype ParamId = ParamId Qid
deriving (Show, Read, Ord, Eq, Typeable, Data)
newtype ViewId = ViewId Qid
deriving (Show, Read, Ord, Eq, Typeable, Data)
newtype ModId = ModId Qid
deriving (Show, Read, Ord, Eq, Typeable, Data)
newtype LabelId = LabelId Qid
deriving (Show, Read, Ord, Eq, Typeable, Data)
newtype OpId = OpId Qid
deriving (Show, Read, Ord, Eq, Typeable, Data)
-- * Construction
-- | Create a 'Var' 'Term' from the given arguments.
mkVar :: String -> Type -> Term
mkVar = Var . mkSimpleId
-- * Information Extraction
-- | Extract the 'Type' from the given 'Term'.
getTermType :: Term -> Type
getTermType term = case term of
Const _ typ -> typ
Var _ typ -> typ
Apply _ _ typ -> typ
-- * Attribute Classification
-- | True iff the argument is the @assoc@ attribute.
assoc :: Attr -> Bool
assoc attr = case attr of
Assoc -> True
_ -> False
-- | True iff the argument is the @comm@ attribute.
comm :: Attr -> Bool
comm attr = case attr of
Comm -> True
_ -> False
-- | True iff the argument is the @idem@ attribute.
idem :: Attr -> Bool
idem attr = case attr of
Idem -> True
_ -> False
-- | True iff the argument is the identity attribute.
idtty :: Attr -> Bool
idtty attr = case attr of
Id _ -> True
_ -> False
-- | True iff the argument is the left identity attribute.
leftId :: Attr -> Bool
leftId attr = case attr of
LeftId _ -> True
_ -> False
-- | True iff the argument is the right identity attribute.
rightId :: Attr -> Bool
rightId attr = case attr of
RightId _ -> True
_ -> False
-- | True iff the argument is the @ctor@ attribute.
ctor :: Attr -> Bool
ctor attr = case attr of
Ctor -> True
_ -> False
-- | True iff the argument is the @owise@ attribute.
owise :: StmntAttr -> Bool
owise attr = case attr of
Owise -> True
_ -> False