9fc2614f |
1 | (* HCoop Domtool (http://hcoop.sourceforge.net/) |
202d474e |
2 | * Copyright (c) 2006-2007, Adam Chlipala |
9fc2614f |
3 | * |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; either version 2 |
7 | * of the License, or (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
ae3a5b8c |
17 | *) |
9fc2614f |
18 | |
19 | (* Configuration language abstract syntax *) |
20 | |
21 | structure Ast = struct |
22 | |
23 | open DataStructures |
24 | |
25 | (* A description of a predicate on configuration block stacks *) |
7d3ae99f |
26 | datatype pred' = |
9fc2614f |
27 | CRoot |
28 | (* The stack is empty. *) |
29 | | CConst of string |
7d3ae99f |
30 | (* The given pred name is on top of the stack. *) |
31 | | CPrefix of pred |
32 | (* Some prefix of the stack matches the pred. *) |
33 | | CNot of pred |
34 | (* The pred does not match. *) |
35 | | CAnd of pred * pred |
36 | (* Both preds match. *) |
37 | withtype pred = pred' * position |
9fc2614f |
38 | |
39 | datatype typ' = |
40 | TBase of string |
41 | (* Base type *) |
42 | | TList of typ |
43 | (* SML 'a list *) |
44 | | TArrow of typ * typ |
45 | (* SML -> *) |
7d3ae99f |
46 | | TAction of pred * record * record |
9fc2614f |
47 | (* An action that: |
7d3ae99f |
48 | * - Is valid in the given pred |
9fc2614f |
49 | * - Expects an environment compatible with the first record |
50 | * - Modifies it according to the second record *) |
2dc33fa4 |
51 | | TNested of pred * typ |
e680130a |
52 | (* Allow nested configuration, in the form of a function from an action |
53 | * satisfying the first predicate to an action satisfying the second and |
54 | * with the same environment variable IO behavior. *) |
64014a03 |
55 | |
56 | | TError |
57 | (* Marker that something already went wrong, so don't generate further |
58 | * error messages. *) |
59 | | TUnif of string * typ option ref |
60 | (* Unification variable to be determined during type-checking *) |
9fc2614f |
61 | withtype typ = typ' * position |
c342e144 |
62 | and record = (typ' * position) StringMap.map |
9fc2614f |
63 | |
64 | datatype exp' = |
65 | EInt of int |
66 | (* Constant integer *) |
67 | | EString of string |
68 | (* Constant string *) |
69 | | EList of exp list |
70 | (* Basic list constructor *) |
71 | |
64014a03 |
72 | | ELam of string * typ option * exp |
9fc2614f |
73 | (* Function abstraction *) |
ccc91989 |
74 | | EVar of string |
75 | (* Variable bound by a function *) |
9fc2614f |
76 | | EApp of exp * exp |
77 | (* Function application *) |
78 | |
e680130a |
79 | | ESkip |
80 | (* Do-nothing action *) |
9fc2614f |
81 | | ESet of string * exp |
82 | (* Set an environment variable *) |
28cf1be3 |
83 | | EGet of string * typ option * string * exp |
ccc91989 |
84 | (* Get an environment variable *) |
9fc2614f |
85 | | ESeq of exp list |
86 | (* Monad sequencer; execute a number of commands in order *) |
2dc33fa4 |
87 | | ELocal of exp * exp |
88 | (* Local execution; like ESeq, but the writes of the first |
89 | * action are abandoned *) |
e680130a |
90 | | EWith of exp * exp |
91 | (* Apply a TNested to an action *) |
bf9b0bc3 |
92 | | EALam of string * pred * exp |
93 | (* Abstraction for building TNested values *) |
254f7f93 |
94 | | EIf of exp * exp * exp |
95 | (* If..then..else *) |
9fc2614f |
96 | withtype exp = exp' * position |
97 | |
e680130a |
98 | datatype decl' = |
99 | DExternType of string |
100 | | DExternVal of string * typ |
add6f172 |
101 | | DVal of string * typ option * exp |
51c32b45 |
102 | | DContext of string |
e680130a |
103 | type decl = decl' * string option * position |
104 | |
51c32b45 |
105 | type file = string option * decl list * exp option |
9fc2614f |
106 | |
85af7d3e |
107 | fun multiApp (f, loc, args) = |
108 | foldl (fn (arg, e) => (EApp (e, arg), loc)) f args |
109 | |
12ad758b |
110 | datatype unification_error = |
111 | UnifyPred of pred * pred |
112 | | UnifyTyp of typ * typ |
113 | | UnifyOccurs of string * typ |
114 | |
115 | exception Unify of unification_error |
116 | |
117 | datatype type_error = |
118 | WrongType of string * exp * typ * typ * unification_error option |
119 | | WrongForm of string * string * exp * typ * unification_error option |
120 | | UnboundVariable of string |
121 | | WrongPred of string * pred * pred |
122 | |
9fc2614f |
123 | end |