adamc@1191
|
1 (* Copyright (c) 2008-2010, Adam Chlipala
|
adamc@1
|
2 * All rights reserved.
|
adamc@1
|
3 *
|
adamc@1
|
4 * Redistribution and use in source and binary forms, with or without
|
adamc@1
|
5 * modification, are permitted provided that the following conditions are met:
|
adamc@1
|
6 *
|
adamc@1
|
7 * - Redistributions of source code must retain the above copyright notice,
|
adamc@1
|
8 * this list of conditions and the following disclaimer.
|
adamc@1
|
9 * - Redistributions in binary form must reproduce the above copyright notice,
|
adamc@1
|
10 * this list of conditions and the following disclaimer in the documentation
|
adamc@1
|
11 * and/or other materials provided with the distribution.
|
adamc@1
|
12 * - The names of contributors may not be used to endorse or promote products
|
adamc@1
|
13 * derived from this software without specific prior written permission.
|
adamc@1
|
14 *
|
adamc@339
|
15 * THIS SOFTARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
adamc@1
|
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
adamc@1
|
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
adamc@1
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
adamc@1
|
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
adamc@1
|
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
adamc@1
|
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
adamc@1
|
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
adamc@1
|
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
adamc@1
|
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
adamc@1
|
25 * POSSIBILITY OF SUCH DAMAGE.
|
adamc@1
|
26 *)
|
adamc@1
|
27
|
adamc@244
|
28 (* Grammar for Ur/Web programs *)
|
adamc@1
|
29
|
adamc@4
|
30 open Source
|
adamc@1
|
31
|
adamc@1
|
32 val s = ErrorMsg.spanOf
|
adamc@230
|
33 val dummy = ErrorMsg.dummySpan
|
adamc@1
|
34
|
adamc@204
|
35 fun capitalize "" = ""
|
adamc@204
|
36 | capitalize s = str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE)
|
adamc@104
|
37
|
adamc@203
|
38 fun entable t =
|
adamc@203
|
39 case #1 t of
|
adamc@203
|
40 TRecord c => c
|
adamc@203
|
41 | _ => t
|
adamc@203
|
42
|
adamc@207
|
43 datatype select_item =
|
adamc@207
|
44 Field of con * con
|
adamc@1194
|
45 | Exp of con option * exp
|
adamc@341
|
46 | Fields of con * con
|
adamc@207
|
47
|
adamc@207
|
48 datatype select =
|
adamc@207
|
49 Star
|
adamc@207
|
50 | Items of select_item list
|
adamc@207
|
51
|
adamc@226
|
52 datatype group_item =
|
adamc@226
|
53 GField of con * con
|
adam@1425
|
54 | GFields of con * con
|
adamc@226
|
55
|
adamc@207
|
56 fun eqTnames ((c1, _), (c2, _)) =
|
adamc@207
|
57 case (c1, c2) of
|
adamc@207
|
58 (CVar (ms1, x1), CVar (ms2, x2)) => ms1 = ms2 andalso x1 = x2
|
adamc@207
|
59 | (CName x1, CName x2) => x1 = x2
|
adamc@207
|
60 | _ => false
|
adamc@207
|
61
|
adam@1424
|
62 fun nameString (c, _) =
|
adam@1424
|
63 case c of
|
adam@1424
|
64 CName s => s
|
adam@1424
|
65 | CVar (_, x) => x
|
adam@1424
|
66 | _ => "?"
|
adam@1424
|
67
|
adamc@1194
|
68 fun amend_select loc (si, (count, tabs, exps)) =
|
adamc@233
|
69 case si of
|
adamc@233
|
70 Field (tx, fx) =>
|
adamc@233
|
71 let
|
adamc@233
|
72 val c = (CRecord ([(fx, (CWild (KType, loc), loc))]), loc)
|
adamc@207
|
73
|
adamc@233
|
74 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
|
adamc@233
|
75 if eqTnames (tx, tx') then
|
adamc@233
|
76 ((tx', (CConcat (c, c'), loc)), true)
|
adamc@233
|
77 else
|
adamc@233
|
78 ((tx', c'), found))
|
adamc@233
|
79 false tabs
|
adamc@233
|
80 in
|
adamc@233
|
81 if found then
|
adamc@233
|
82 ()
|
adamc@233
|
83 else
|
adam@1424
|
84 ErrorMsg.errorAt loc ("Select of field " ^ nameString fx ^ " from unbound table " ^ nameString tx);
|
adamc@233
|
85
|
adamc@1194
|
86 (count, tabs, exps)
|
adamc@233
|
87 end
|
adamc@341
|
88 | Fields (tx, fs) =>
|
adamc@341
|
89 let
|
adamc@341
|
90 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
|
adamc@341
|
91 if eqTnames (tx, tx') then
|
adamc@341
|
92 ((tx', (CConcat (fs, c'), loc)), true)
|
adamc@341
|
93 else
|
adamc@341
|
94 ((tx', c'), found))
|
adamc@341
|
95 false tabs
|
adamc@341
|
96 in
|
adamc@341
|
97 if found then
|
adamc@341
|
98 ()
|
adamc@341
|
99 else
|
adamc@341
|
100 ErrorMsg.errorAt loc "Select of field from unbound table";
|
adamc@341
|
101
|
adamc@1194
|
102 (count, tabs, exps)
|
adamc@341
|
103 end
|
adamc@1194
|
104 | Exp (SOME c, e) => (count, tabs, (c, e) :: exps)
|
adamc@1194
|
105 | Exp (NONE, e) => (count+1, tabs, ((CName (Int.toString count), loc), e) :: exps)
|
adamc@207
|
106
|
adamc@226
|
107 fun amend_group loc (gi, tabs) =
|
adamc@226
|
108 let
|
adamc@226
|
109 val (tx, c) = case gi of
|
adamc@226
|
110 GField (tx, fx) => (tx, (CRecord ([(fx, (CWild (KType, loc), loc))]), loc))
|
adam@1425
|
111 | GFields (tx, fxs) => (tx, fxs)
|
adamc@226
|
112
|
adamc@226
|
113 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
|
adamc@226
|
114 if eqTnames (tx, tx') then
|
adamc@226
|
115 ((tx', (CConcat (c, c'), loc)), true)
|
adamc@226
|
116 else
|
adamc@226
|
117 ((tx', c'), found))
|
adam@1425
|
118 false tabs
|
adamc@226
|
119 in
|
adamc@226
|
120 if found then
|
adamc@226
|
121 ()
|
adamc@226
|
122 else
|
adamc@226
|
123 ErrorMsg.errorAt loc "Select of field from unbound table";
|
adamc@226
|
124
|
adamc@226
|
125 tabs
|
adamc@226
|
126 end
|
adamc@226
|
127
|
adamc@403
|
128 fun sql_inject (v, loc) =
|
adamc@403
|
129 (EApp ((EVar (["Basis"], "sql_inject", Infer), loc), (v, loc)), loc)
|
adamc@209
|
130
|
adamc@220
|
131 fun sql_binary (oper, sqlexp1, sqlexp2, loc) =
|
adamc@220
|
132 let
|
adamc@403
|
133 val e = (EVar (["Basis"], "sql_binary", Infer), loc)
|
adamc@403
|
134 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
|
adamc@220
|
135 val e = (EApp (e, sqlexp1), loc)
|
adamc@220
|
136 in
|
adamc@220
|
137 (EApp (e, sqlexp2), loc)
|
adamc@220
|
138 end
|
adamc@220
|
139
|
adamc@220
|
140 fun sql_unary (oper, sqlexp, loc) =
|
adamc@220
|
141 let
|
adamc@403
|
142 val e = (EVar (["Basis"], "sql_unary", Infer), loc)
|
adamc@403
|
143 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
|
adamc@220
|
144 in
|
adamc@220
|
145 (EApp (e, sqlexp), loc)
|
adamc@219
|
146 end
|
adamc@219
|
147
|
adam@1427
|
148 fun sql_relop (oper, all, sqlexp1, sqlexp2, loc) =
|
adamc@229
|
149 let
|
adamc@403
|
150 val e = (EVar (["Basis"], "sql_relop", Infer), loc)
|
adamc@403
|
151 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
|
adam@1427
|
152 val e = (EApp (e, (EVar (["Basis"], if all then "True" else "False", Infer), loc)), loc)
|
adamc@229
|
153 val e = (EApp (e, sqlexp1), loc)
|
adamc@229
|
154 in
|
adamc@229
|
155 (EApp (e, sqlexp2), loc)
|
adamc@229
|
156 end
|
adamc@229
|
157
|
adamc@441
|
158 fun sql_nfunc (oper, loc) =
|
adamc@441
|
159 let
|
adamc@441
|
160 val e = (EVar (["Basis"], "sql_nfunc", Infer), loc)
|
adamc@441
|
161 in
|
adamc@441
|
162 (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
|
adamc@441
|
163 end
|
adamc@441
|
164
|
adamc@389
|
165 fun native_unop (oper, e1, loc) =
|
adamc@389
|
166 let
|
adamc@403
|
167 val e = (EVar (["Basis"], oper, Infer), loc)
|
adamc@389
|
168 in
|
adamc@389
|
169 (EApp (e, e1), loc)
|
adamc@389
|
170 end
|
adamc@389
|
171
|
adamc@256
|
172 fun native_op (oper, e1, e2, loc) =
|
adamc@256
|
173 let
|
adamc@403
|
174 val e = (EVar (["Basis"], oper, Infer), loc)
|
adamc@256
|
175 val e = (EApp (e, e1), loc)
|
adamc@256
|
176 in
|
adamc@256
|
177 (EApp (e, e2), loc)
|
adamc@256
|
178 end
|
adamc@256
|
179
|
adamc@310
|
180 val inDml = ref false
|
adamc@310
|
181
|
adamc@325
|
182 fun tagIn bt =
|
adamc@325
|
183 case bt of
|
adamc@325
|
184 "table" => "tabl"
|
adamc@325
|
185 | _ => bt
|
adamc@325
|
186
|
adamc@709
|
187 datatype prop_kind = Delete | Update
|
adamc@709
|
188
|
adamc@721
|
189 datatype attr = Class of exp | Normal of con * exp
|
adamc@721
|
190
|
adamc@822
|
191 fun patType loc (p : pat) =
|
adamc@822
|
192 case #1 p of
|
adamc@822
|
193 PAnnot (_, t) => t
|
adamc@822
|
194 | _ => (CWild (KType, loc), loc)
|
adamc@822
|
195
|
adamc@1265
|
196 fun tnamesOf (e, _) =
|
adamc@1265
|
197 case e of
|
adamc@1265
|
198 EApp (e1, e2) => tnamesOf e1 @ tnamesOf e2
|
adamc@1265
|
199 | ECApp (e, c as (CName _, _)) =>
|
adamc@1265
|
200 let
|
adamc@1265
|
201 fun isFt (e, _) =
|
adamc@1265
|
202 case e of
|
adamc@1265
|
203 EVar (["Basis"], "sql_from_table", _) => true
|
adamc@1265
|
204 | EVar ([], "sql_from_table", _) => true
|
adamc@1265
|
205 | ECApp (e, _) => isFt e
|
adamc@1265
|
206 | EApp (e, _) => isFt e
|
adamc@1265
|
207 | EDisjointApp e => isFt e
|
adamc@1265
|
208 | _ => false
|
adamc@1265
|
209 in
|
adamc@1265
|
210 (if isFt e then [c] else []) @ tnamesOf e
|
adamc@1265
|
211 end
|
adamc@1265
|
212 | ECApp (e, _) => tnamesOf e
|
adamc@1265
|
213 | EDisjointApp e => tnamesOf e
|
adamc@1265
|
214 | _ => []
|
adamc@1265
|
215
|
adamc@1
|
216 %%
|
adamc@244
|
217 %header (functor UrwebLrValsFn(structure Token : TOKEN))
|
adamc@1
|
218
|
adamc@1
|
219 %term
|
adamc@1
|
220 EOF
|
adamc@821
|
221 | STRING of string | INT of Int64.int | FLOAT of Real64.real | CHAR of char
|
adamc@1
|
222 | SYMBOL of string | CSYMBOL of string
|
adamc@1
|
223 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
|
adam@1306
|
224 | EQ | COMMA | COLON | DCOLON | DCOLONWILD | TCOLON | TCOLONWILD | DOT | HASH | UNDER | UNDERUNDER | BAR
|
adamc@403
|
225 | PLUS | MINUS | DIVIDE | DOTDOTDOT | MOD | AT
|
adamc@623
|
226 | CON | LTYPE | VAL | REC | AND | FUN | MAP | UNIT | KUNIT | CLASS
|
adamc@156
|
227 | DATATYPE | OF
|
adamc@7
|
228 | TYPE | NAME
|
adamc@629
|
229 | ARROW | LARROW | DARROW | STAR | SEMI | KARROW | DKARROW | BANG
|
adamc@674
|
230 | FN | PLUSPLUS | MINUSMINUS | MINUSMINUSMINUS | DOLLAR | TWIDDLE | CARET
|
adamc@446
|
231 | LET | IN
|
adamc@1071
|
232 | STRUCTURE | SIGNATURE | STRUCT | SIG | END | FUNCTOR | WHERE | EXTERN | SQL | SELECT1
|
adamc@754
|
233 | INCLUDE | OPEN | CONSTRAINT | CONSTRAINTS | EXPORT | TABLE | SEQUENCE | VIEW
|
adamc@1199
|
234 | COOKIE | STYLE | TASK | POLICY
|
adamc@842
|
235 | CASE | IF | THEN | ELSE | ANDALSO | ORELSE
|
adamc@1
|
236
|
adamc@360
|
237 | XML_BEGIN of string | XML_END | XML_BEGIN_END of string
|
adamc@91
|
238 | NOTAGS of string
|
adamc@91
|
239 | BEGIN_TAG of string | END_TAG of string
|
adamc@91
|
240
|
adamc@993
|
241 | SELECT | DISTINCT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING
|
adamc@229
|
242 | UNION | INTERSECT | EXCEPT
|
adamc@232
|
243 | LIMIT | OFFSET | ALL
|
adamc@220
|
244 | TRUE | FALSE | CAND | OR | NOT
|
adamc@236
|
245 | COUNT | AVG | SUM | MIN | MAX
|
adamc@268
|
246 | ASC | DESC
|
adamc@470
|
247 | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS
|
adamc@441
|
248 | CURRENT_TIMESTAMP
|
adamc@219
|
249 | NE | LT | LE | GT | GE
|
adamc@714
|
250 | CCONSTRAINT | UNIQUE | CHECK | PRIMARY | FOREIGN | KEY | ON | NO | ACTION | RESTRICT | CASCADE | REFERENCES
|
adamc@751
|
251 | JOIN | INNER | CROSS | OUTER | LEFT | RIGHT | FULL
|
kkallio@1572
|
252 | CIF | CTHEN | CELSE
|
adamc@204
|
253
|
adamc@30
|
254 %nonterm
|
adamc@1
|
255 file of decl list
|
adamc@1
|
256 | decls of decl list
|
adamc@325
|
257 | decl of decl list
|
adamc@123
|
258 | vali of string * con option * exp
|
adamc@123
|
259 | valis of (string * con option * exp) list
|
adamc@242
|
260 | copt of con option
|
adamc@1
|
261
|
adamc@191
|
262 | dargs of string list
|
adamc@156
|
263 | barOpt of unit
|
adamc@156
|
264 | dcons of (string * con option) list
|
adamc@805
|
265 | dtype of string * string list * (string * con option) list
|
adamc@805
|
266 | dtypes of (string * string list * (string * con option) list) list
|
adamc@156
|
267 | dcon of string * con option
|
adamc@156
|
268
|
adamc@707
|
269 | pkopt of exp
|
adamc@707
|
270 | commaOpt of unit
|
adamc@707
|
271
|
adamc@704
|
272 | cst of exp
|
adamc@704
|
273 | csts of exp
|
adamc@704
|
274 | cstopt of exp
|
adamc@704
|
275
|
adamc@1001
|
276 | ckl of (string * kind option) list
|
adamc@1001
|
277
|
adamc@709
|
278 | pmode of prop_kind * exp
|
adamc@709
|
279 | pkind of prop_kind
|
adamc@709
|
280 | prule of exp
|
adamc@709
|
281 | pmodes of (prop_kind * exp) list
|
adamc@709
|
282
|
adamc@30
|
283 | sgn of sgn
|
adamc@42
|
284 | sgntm of sgn
|
adamc@30
|
285 | sgi of sgn_item
|
adamc@30
|
286 | sgis of sgn_item list
|
adamc@30
|
287
|
adamc@30
|
288 | str of str
|
adamc@30
|
289
|
adamc@1
|
290 | kind of kind
|
adamc@207
|
291 | ktuple of kind list
|
adamc@1
|
292 | kcolon of explicitness
|
adamc@240
|
293 | kopt of kind option
|
adamc@1
|
294
|
adamc@34
|
295 | path of string list * string
|
adamc@156
|
296 | cpath of string list * string
|
adamc@34
|
297 | spath of str
|
adamc@59
|
298 | mpath of string list
|
adamc@34
|
299
|
adamc@1
|
300 | cexp of con
|
adamc@1
|
301 | capps of con
|
adamc@1
|
302 | cterm of con
|
adamc@195
|
303 | ctuple of con list
|
adamc@207
|
304 | ctuplev of con list
|
adamc@1
|
305 | ident of con
|
adamc@200
|
306 | idents of con list
|
adamc@1
|
307 | rcon of (con * con) list
|
adamc@83
|
308 | rconn of (con * con) list
|
adamc@1
|
309 | rcone of (con * con) list
|
adamc@239
|
310 | cargs of con * kind -> con * kind
|
adamc@239
|
311 | cargl of con * kind -> con * kind
|
adamc@240
|
312 | cargl2 of con * kind -> con * kind
|
adamc@239
|
313 | carg of con * kind -> con * kind
|
adamc@239
|
314 | cargp of con * kind -> con * kind
|
adamc@1
|
315
|
adamc@8
|
316 | eexp of exp
|
adamc@8
|
317 | eapps of exp
|
adamc@8
|
318 | eterm of exp
|
adamc@195
|
319 | etuple of exp list
|
adamc@12
|
320 | rexp of (con * exp) list
|
adamc@91
|
321 | xml of exp
|
adamc@91
|
322 | xmlOne of exp
|
adamc@1045
|
323 | xmlOpt of exp
|
adam@1412
|
324 | tag of (string * exp) * exp option * exp
|
adamc@141
|
325 | tagHead of string * exp
|
adamc@434
|
326 | bind of string * con option * exp
|
adamc@446
|
327 | edecl of edecl
|
adamc@446
|
328 | edecls of edecl list
|
adamc@8
|
329
|
adamc@241
|
330 | earg of exp * con -> exp * con
|
adamc@241
|
331 | eargp of exp * con -> exp * con
|
adamc@822
|
332 | earga of exp * con -> exp * con
|
adamc@241
|
333 | eargs of exp * con -> exp * con
|
adamc@241
|
334 | eargl of exp * con -> exp * con
|
adamc@242
|
335 | eargl2 of exp * con -> exp * con
|
adamc@241
|
336
|
adamc@170
|
337 | branch of pat * exp
|
adamc@170
|
338 | branchs of (pat * exp) list
|
adamc@170
|
339 | pat of pat
|
adamc@822
|
340 | patS of pat
|
adamc@170
|
341 | pterm of pat
|
adamc@174
|
342 | rpat of (string * pat) list * bool
|
adamc@195
|
343 | ptuple of pat list
|
adamc@170
|
344
|
adamc@721
|
345 | attrs of exp option * (con * exp) list
|
adamc@721
|
346 | attr of attr
|
adamc@104
|
347 | attrv of exp
|
adamc@104
|
348
|
adamc@204
|
349 | query of exp
|
adamc@226
|
350 | query1 of exp
|
adamc@993
|
351 | dopt of exp
|
adamc@748
|
352 | tables of con list * exp
|
adamc@749
|
353 | fitem of con list * exp
|
adamc@204
|
354 | tname of con
|
adamc@705
|
355 | tnameW of con * con
|
adamc@705
|
356 | tnames of (con * con) * (con * con) list
|
adamc@705
|
357 | tnames' of (con * con) * (con * con) list
|
adamc@204
|
358 | table of con * exp
|
adamc@748
|
359 | table' of con * exp
|
adamc@207
|
360 | tident of con
|
adamc@207
|
361 | fident of con
|
adamc@207
|
362 | seli of select_item
|
adamc@207
|
363 | selis of select_item list
|
adamc@207
|
364 | select of select
|
adamc@209
|
365 | sqlexp of exp
|
adamc@209
|
366 | wopt of exp
|
adamc@226
|
367 | groupi of group_item
|
adamc@226
|
368 | groupis of group_item list
|
adamc@226
|
369 | gopt of group_item list option
|
adamc@227
|
370 | hopt of exp
|
adamc@230
|
371 | obopt of exp
|
adamc@268
|
372 | obitem of exp * exp
|
adamc@230
|
373 | obexps of exp
|
adamc@268
|
374 | diropt of exp
|
adamc@231
|
375 | lopt of exp
|
adamc@232
|
376 | ofopt of exp
|
adamc@231
|
377 | sqlint of exp
|
adamc@236
|
378 | sqlagg of string
|
adamc@746
|
379 | fname of exp
|
adamc@207
|
380
|
adamc@302
|
381 | texp of exp
|
adamc@302
|
382 | fields of con list
|
adamc@302
|
383 | sqlexps of exp list
|
adamc@303
|
384 | fsets of (con * exp) list
|
adamc@310
|
385 | enterDml of unit
|
adamc@310
|
386 | leaveDml of unit
|
adamc@302
|
387
|
adamc@204
|
388
|
adamc@1
|
389 %verbose (* print summary of errors *)
|
adamc@1
|
390 %pos int (* positions *)
|
adamc@1
|
391 %start file
|
adamc@1
|
392 %pure
|
adamc@1
|
393 %eop EOF
|
adamc@1
|
394 %noshift EOF
|
adamc@1
|
395
|
adamc@244
|
396 %name Urweb
|
adamc@1
|
397
|
adamc@623
|
398 %right KARROW
|
adamc@623
|
399 %nonassoc DKARROW
|
adamc@243
|
400 %right SEMI
|
adamc@243
|
401 %nonassoc LARROW
|
adamc@195
|
402 %nonassoc IF THEN ELSE
|
adamc@843
|
403 %nonassoc DARROW
|
adamc@842
|
404 %left ANDALSO
|
adamc@842
|
405 %left ORELSE
|
adamc@1
|
406 %nonassoc COLON
|
adam@1306
|
407 %nonassoc DCOLON TCOLON DCOLONWILD TCOLONWILD
|
adam@1427
|
408 %left UNION INTERSECT EXCEPT ALL
|
adamc@1
|
409 %right COMMA
|
adamc@751
|
410 %right JOIN INNER CROSS OUTER LEFT RIGHT FULL
|
adamc@220
|
411 %right OR
|
adamc@220
|
412 %right CAND
|
adamc@470
|
413 %nonassoc EQ NE LT LE GT GE IS
|
adamc@243
|
414 %right ARROW
|
adamc@837
|
415 %right CARET PLUSPLUS
|
adamc@837
|
416 %left MINUSMINUS MINUSMINUSMINUS
|
adamc@389
|
417 %left PLUS MINUS
|
adamc@389
|
418 %left STAR DIVIDE MOD
|
adamc@220
|
419 %left NOT
|
adamc@84
|
420 %nonassoc TWIDDLE
|
adamc@1
|
421 %nonassoc DOLLAR
|
adamc@1
|
422 %left DOT
|
adamc@221
|
423 %nonassoc LBRACE RBRACE
|
adamc@1
|
424
|
adamc@1
|
425 %%
|
adamc@1
|
426
|
adamc@1
|
427 file : decls (decls)
|
adamc@54
|
428 | SIG sgis ([(DSgn ("?", (SgnConst sgis, s (SIGleft, sgisright))),
|
adamc@54
|
429 s (SIGleft, sgisright))])
|
adamc@1
|
430
|
adamc@1
|
431 decls : ([])
|
adamc@325
|
432 | decl decls (decl @ decls)
|
adamc@1
|
433
|
adamc@240
|
434 decl : CON SYMBOL cargl2 kopt EQ cexp (let
|
adamc@240
|
435 val loc = s (CONleft, cexpright)
|
adamc@240
|
436
|
adamc@240
|
437 val k = Option.getOpt (kopt, (KWild, loc))
|
adamc@240
|
438 val (c, k) = cargl2 (cexp, k)
|
adamc@240
|
439 in
|
adamc@325
|
440 [(DCon (SYMBOL, SOME k, c), loc)]
|
adamc@240
|
441 end)
|
adamc@325
|
442 | LTYPE SYMBOL EQ cexp ([(DCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
|
adamc@325
|
443 s (LTYPEleft, cexpright))])
|
adamc@805
|
444 | DATATYPE dtypes ([(DDatatype dtypes, s (DATATYPEleft, dtypesright))])
|
adamc@191
|
445 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
|
adamc@191
|
446 (case dargs of
|
adamc@325
|
447 [] => [(DDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))]
|
adamc@191
|
448 | _ => raise Fail "Arguments specified for imported datatype")
|
adamc@325
|
449 | VAL vali ([(DVal vali, s (VALleft, valiright))])
|
adamc@325
|
450 | VAL REC valis ([(DValRec valis, s (VALleft, valisright))])
|
adamc@325
|
451 | FUN valis ([(DValRec valis, s (FUNleft, valisright))])
|
adamc@1
|
452
|
adamc@325
|
453 | SIGNATURE CSYMBOL EQ sgn ([(DSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))])
|
adamc@325
|
454 | STRUCTURE CSYMBOL EQ str ([(DStr (CSYMBOL, NONE, str), s (STRUCTUREleft, strright))])
|
adamc@325
|
455 | STRUCTURE CSYMBOL COLON sgn EQ str ([(DStr (CSYMBOL, SOME sgn, str), s (STRUCTUREleft, strright))])
|
adamc@42
|
456 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN EQ str
|
adamc@325
|
457 ([(DStr (CSYMBOL1, NONE,
|
adamc@325
|
458 (StrFun (CSYMBOL2, sgn1, NONE, str), s (FUNCTORleft, strright))),
|
adamc@325
|
459 s (FUNCTORleft, strright))])
|
adamc@42
|
460 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn EQ str
|
adamc@325
|
461 ([(DStr (CSYMBOL1, NONE,
|
adamc@325
|
462 (StrFun (CSYMBOL2, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))),
|
adamc@325
|
463 s (FUNCTORleft, strright))])
|
adamc@325
|
464 | EXTERN STRUCTURE CSYMBOL COLON sgn ([(DFfiStr (CSYMBOL, sgn), s (EXTERNleft, sgnright))])
|
adamc@61
|
465 | OPEN mpath (case mpath of
|
adamc@61
|
466 [] => raise Fail "Impossible mpath parse [1]"
|
adamc@325
|
467 | m :: ms => [(DOpen (m, ms), s (OPENleft, mpathright))])
|
adamc@325
|
468 | OPEN mpath LPAREN str RPAREN (let
|
adamc@325
|
469 val loc = s (OPENleft, RPARENright)
|
adamc@325
|
470
|
adamc@325
|
471 val m = case mpath of
|
adamc@325
|
472 [] => raise Fail "Impossible mpath parse [4]"
|
adamc@325
|
473 | m :: ms =>
|
adamc@325
|
474 foldl (fn (m, str) => (StrProj (str, m), loc))
|
adamc@325
|
475 (StrVar m, loc) ms
|
adamc@325
|
476 in
|
adamc@325
|
477 [(DStr ("anon", NONE, (StrApp (m, str), loc)), loc),
|
adamc@325
|
478 (DOpen ("anon", []), loc)]
|
adamc@325
|
479 end)
|
adamc@88
|
480 | OPEN CONSTRAINTS mpath (case mpath of
|
adamc@88
|
481 [] => raise Fail "Impossible mpath parse [3]"
|
adamc@325
|
482 | m :: ms => [(DOpenConstraints (m, ms), s (OPENleft, mpathright))])
|
adamc@325
|
483 | CONSTRAINT cterm TWIDDLE cterm ([(DConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))])
|
adamc@325
|
484 | EXPORT spath ([(DExport spath, s (EXPORTleft, spathright))])
|
adamc@707
|
485 | TABLE SYMBOL COLON cterm pkopt commaOpt cstopt([(DTable (SYMBOL, entable cterm, pkopt, cstopt),
|
adamc@707
|
486 s (TABLEleft, cstoptright))])
|
adamc@338
|
487 | SEQUENCE SYMBOL ([(DSequence SYMBOL, s (SEQUENCEleft, SYMBOLright))])
|
adamc@754
|
488 | VIEW SYMBOL EQ query ([(DView (SYMBOL, query),
|
adamc@754
|
489 s (VIEWleft, queryright))])
|
adamc@754
|
490 | VIEW SYMBOL EQ LBRACE eexp RBRACE ([(DView (SYMBOL, eexp),
|
adamc@754
|
491 s (VIEWleft, RBRACEright))])
|
adamc@563
|
492 | CLASS SYMBOL EQ cexp (let
|
adamc@563
|
493 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
494 in
|
adamc@563
|
495 [(DClass (SYMBOL, (KWild, loc), cexp), loc)]
|
adamc@563
|
496 end)
|
adamc@563
|
497 | CLASS SYMBOL DCOLON kind EQ cexp ([(DClass (SYMBOL, kind, cexp), s (CLASSleft, cexpright))])
|
adamc@211
|
498 | CLASS SYMBOL SYMBOL EQ cexp (let
|
adamc@211
|
499 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
500 val k = (KWild, loc)
|
adamc@211
|
501 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
|
adamc@211
|
502 in
|
adamc@563
|
503 [(DClass (SYMBOL1, k, c), s (CLASSleft, cexpright))]
|
adamc@563
|
504 end)
|
adamc@563
|
505 | CLASS SYMBOL LPAREN SYMBOL DCOLON kind RPAREN EQ cexp (let
|
adamc@563
|
506 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
507 val c = (CAbs (SYMBOL2, SOME kind, cexp), loc)
|
adamc@563
|
508 in
|
adamc@563
|
509 [(DClass (SYMBOL1, kind, c), s (CLASSleft, cexpright))]
|
adamc@211
|
510 end)
|
adamc@459
|
511 | COOKIE SYMBOL COLON cexp ([(DCookie (SYMBOL, cexp), s (COOKIEleft, cexpright))])
|
adamc@720
|
512 | STYLE SYMBOL ([(DStyle SYMBOL, s (STYLEleft, SYMBOLright))])
|
adamc@1075
|
513 | TASK eapps EQ eexp ([(DTask (eapps, eexp), s (TASKleft, eexpright))])
|
adamc@1199
|
514 | POLICY eexp ([(DPolicy eexp, s (POLICYleft, eexpright))])
|
adamc@30
|
515
|
adamc@805
|
516 dtype : SYMBOL dargs EQ barOpt dcons (SYMBOL, dargs, dcons)
|
adamc@805
|
517
|
adamc@805
|
518 dtypes : dtype ([dtype])
|
adamc@805
|
519 | dtype AND dtypes (dtype :: dtypes)
|
adamc@805
|
520
|
adamc@240
|
521 kopt : (NONE)
|
adamc@240
|
522 | DCOLON kind (SOME kind)
|
adam@1302
|
523 | DCOLONWILD (SOME (KWild, s (DCOLONWILDleft, DCOLONWILDright)))
|
adamc@240
|
524
|
adamc@191
|
525 dargs : ([])
|
adamc@191
|
526 | SYMBOL dargs (SYMBOL :: dargs)
|
adamc@191
|
527
|
adamc@156
|
528 barOpt : ()
|
adamc@156
|
529 | BAR ()
|
adamc@156
|
530
|
adamc@156
|
531 dcons : dcon ([dcon])
|
adamc@156
|
532 | dcon BAR dcons (dcon :: dcons)
|
adamc@156
|
533
|
adamc@156
|
534 dcon : CSYMBOL (CSYMBOL, NONE)
|
adamc@156
|
535 | CSYMBOL OF cexp (CSYMBOL, SOME cexp)
|
adamc@156
|
536
|
adamc@242
|
537 vali : SYMBOL eargl2 copt EQ eexp (let
|
adamc@242
|
538 val loc = s (SYMBOLleft, eexpright)
|
adamc@242
|
539 val t = Option.getOpt (copt, (CWild (KType, loc), loc))
|
adamc@242
|
540
|
adamc@242
|
541 val (e, t) = eargl2 (eexp, t)
|
adamc@242
|
542 in
|
adamc@242
|
543 (SYMBOL, SOME t, e)
|
adamc@242
|
544 end)
|
adamc@242
|
545
|
adamc@242
|
546 copt : (NONE)
|
adamc@242
|
547 | COLON cexp (SOME cexp)
|
adamc@123
|
548
|
adamc@704
|
549 cstopt : (EVar (["Basis"], "no_constraint", Infer), dummy)
|
adamc@704
|
550 | csts (csts)
|
adamc@704
|
551
|
adamc@704
|
552 csts : CCONSTRAINT tname cst (let
|
adamc@704
|
553 val loc = s (CCONSTRAINTleft, cstright)
|
adamc@704
|
554
|
adamc@704
|
555 val e = (EVar (["Basis"], "one_constraint", Infer), loc)
|
adamc@704
|
556 val e = (ECApp (e, tname), loc)
|
adamc@704
|
557 in
|
adamc@704
|
558 (EApp (e, cst), loc)
|
adamc@704
|
559 end)
|
adamc@704
|
560 | csts COMMA csts (let
|
adamc@704
|
561 val loc = s (csts1left, csts2right)
|
adamc@704
|
562
|
adamc@704
|
563 val e = (EVar (["Basis"], "join_constraints", Infer), loc)
|
adamc@704
|
564 val e = (EApp (e, csts1), loc)
|
adamc@704
|
565 in
|
adamc@704
|
566 (EApp (e, csts2), loc)
|
adamc@704
|
567 end)
|
adamc@704
|
568 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
|
adamc@704
|
569
|
adamc@704
|
570 cst : UNIQUE tnames (let
|
adamc@704
|
571 val loc = s (UNIQUEleft, tnamesright)
|
adamc@704
|
572
|
adamc@704
|
573 val e = (EVar (["Basis"], "unique", Infer), loc)
|
adamc@705
|
574 val e = (ECApp (e, #1 (#1 tnames)), loc)
|
adamc@705
|
575 val e = (ECApp (e, (CRecord (#2 tnames), loc)), loc)
|
adamc@704
|
576 in
|
adamc@1093
|
577 e
|
adamc@704
|
578 end)
|
adamc@709
|
579
|
adamc@714
|
580 | CHECK sqlexp (let
|
adamc@714
|
581 val loc = s (CHECKleft, sqlexpright)
|
adamc@714
|
582 in
|
adamc@714
|
583 (EApp ((EVar (["Basis"], "check", Infer), loc),
|
adamc@714
|
584 sqlexp), loc)
|
adamc@714
|
585 end)
|
adamc@714
|
586
|
adamc@709
|
587 | FOREIGN KEY tnames REFERENCES texp LPAREN tnames' RPAREN pmodes
|
adamc@709
|
588 (let
|
adamc@709
|
589 val loc = s (FOREIGNleft, pmodesright)
|
adamc@709
|
590
|
adamc@709
|
591 val mat = ListPair.foldrEq
|
adamc@709
|
592 (fn ((nm1, _), (nm2, _), mat) =>
|
adamc@709
|
593 let
|
adamc@709
|
594 val e = (EVar (["Basis"], "mat_cons", Infer), loc)
|
adamc@709
|
595 val e = (ECApp (e, nm1), loc)
|
adamc@709
|
596 val e = (ECApp (e, nm2), loc)
|
adamc@709
|
597 in
|
adamc@709
|
598 (EApp (e, mat), loc)
|
adamc@709
|
599 end)
|
adamc@709
|
600 (EVar (["Basis"], "mat_nil", Infer), loc)
|
adamc@709
|
601 (#1 tnames :: #2 tnames, #1 tnames' :: #2 tnames')
|
adam@1401
|
602 handle ListPair.UnequalLengths =>
|
adam@1401
|
603 (ErrorMsg.errorAt loc ("Unequal foreign key list lengths ("
|
adam@1401
|
604 ^ Int.toString (1 + length (#2 tnames))
|
adam@1401
|
605 ^ " vs. "
|
adam@1401
|
606 ^ Int.toString (1 + length (#2 tnames'))
|
adam@1401
|
607 ^ ")");
|
adam@1401
|
608 (EVar (["Basis"], "mat_nil", Infer), loc))
|
adamc@709
|
609
|
adamc@709
|
610 fun findMode mode =
|
adamc@709
|
611 let
|
adamc@709
|
612 fun findMode' pmodes =
|
adamc@709
|
613 case pmodes of
|
adamc@709
|
614 [] => (EVar (["Basis"], "no_action", Infer), loc)
|
adamc@709
|
615 | (mode', rule) :: pmodes' =>
|
adamc@709
|
616 if mode' = mode then
|
adamc@709
|
617 (if List.exists (fn (mode', _) => mode' = mode)
|
adamc@709
|
618 pmodes' then
|
adamc@709
|
619 ErrorMsg.errorAt loc "Duplicate propagation rule"
|
adamc@709
|
620 else
|
adamc@709
|
621 ();
|
adamc@709
|
622 rule)
|
adamc@709
|
623 else
|
adamc@709
|
624 findMode' pmodes'
|
adamc@709
|
625 in
|
adamc@709
|
626 findMode' pmodes
|
adamc@709
|
627 end
|
adamc@709
|
628
|
adamc@709
|
629 val e = (EVar (["Basis"], "foreign_key", Infer), loc)
|
adamc@709
|
630 val e = (EApp (e, mat), loc)
|
adamc@709
|
631 val e = (EApp (e, texp), loc)
|
adamc@709
|
632 in
|
adamc@709
|
633 (EApp (e, (ERecord [((CName "OnDelete", loc),
|
adamc@709
|
634 findMode Delete),
|
adamc@709
|
635 ((CName "OnUpdate", loc),
|
adamc@709
|
636 findMode Update)], loc)), loc)
|
adamc@709
|
637 end)
|
adamc@709
|
638
|
adamc@704
|
639 | LBRACE eexp RBRACE (eexp)
|
adamc@704
|
640
|
adamc@704
|
641 tnameW : tname (let
|
adamc@704
|
642 val loc = s (tnameleft, tnameright)
|
adamc@704
|
643 in
|
adamc@704
|
644 (tname, (CWild (KType, loc), loc))
|
adamc@704
|
645 end)
|
adamc@704
|
646
|
adamc@705
|
647 tnames : tnameW (tnameW, [])
|
adamc@705
|
648 | LPAREN tnames' RPAREN (tnames')
|
adamc@704
|
649
|
adamc@705
|
650 tnames': tnameW (tnameW, [])
|
adamc@705
|
651 | tnameW COMMA tnames' (#1 tnames', tnameW :: #2 tnames')
|
adamc@704
|
652
|
adamc@709
|
653 pmode : ON pkind prule (pkind, prule)
|
adamc@709
|
654
|
adamc@709
|
655 pkind : DELETE (Delete)
|
adamc@709
|
656 | UPDATE (Update)
|
adamc@709
|
657
|
adamc@709
|
658 prule : NO ACTION (EVar (["Basis"], "no_action", Infer), s (NOleft, ACTIONright))
|
adamc@709
|
659 | RESTRICT (EVar (["Basis"], "restrict", Infer), s (RESTRICTleft, RESTRICTright))
|
adamc@709
|
660 | CASCADE (EVar (["Basis"], "cascade", Infer), s (CASCADEleft, CASCADEright))
|
adamc@709
|
661 | SET NULL (EVar (["Basis"], "set_null", Infer), s (SETleft, NULLright))
|
adamc@709
|
662
|
adamc@709
|
663 pmodes : ([])
|
adamc@709
|
664 | pmode pmodes (pmode :: pmodes)
|
adamc@709
|
665
|
adamc@707
|
666 commaOpt: ()
|
adamc@707
|
667 | COMMA ()
|
adamc@707
|
668
|
adamc@993
|
669 pkopt : (EVar (["Basis"], "no_primary_key", Infer), dummy)
|
adamc@707
|
670 | PRIMARY KEY tnames (let
|
adamc@707
|
671 val loc = s (PRIMARYleft, tnamesright)
|
adamc@707
|
672
|
adamc@1093
|
673 val e = (EVar (["Basis"], "primary_key", TypesOnly), loc)
|
adamc@707
|
674 val e = (ECApp (e, #1 (#1 tnames)), loc)
|
adamc@707
|
675 val e = (ECApp (e, (CRecord (#2 tnames), loc)), loc)
|
adamc@707
|
676 val e = (EDisjointApp e, loc)
|
adamc@707
|
677 val e = (EDisjointApp e, loc)
|
adamc@707
|
678
|
adamc@707
|
679 val witness = map (fn (c, _) =>
|
adamc@707
|
680 (c, (EWild, loc)))
|
adamc@707
|
681 (#1 tnames :: #2 tnames)
|
adamc@707
|
682 val witness = (ERecord witness, loc)
|
adamc@707
|
683 in
|
adamc@707
|
684 (EApp (e, witness), loc)
|
adamc@707
|
685 end)
|
adamc@707
|
686
|
adamc@123
|
687 valis : vali ([vali])
|
adamc@123
|
688 | vali AND valis (vali :: valis)
|
adamc@123
|
689
|
adamc@42
|
690 sgn : sgntm (sgntm)
|
adamc@40
|
691 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
|
adamc@40
|
692 (SgnFun (CSYMBOL, sgn1, sgn2), s (FUNCTORleft, sgn2right))
|
adamc@30
|
693
|
adamc@42
|
694 sgntm : SIG sgis END (SgnConst sgis, s (SIGleft, ENDright))
|
adamc@59
|
695 | mpath (case mpath of
|
adamc@61
|
696 [] => raise Fail "Impossible mpath parse [2]"
|
adamc@59
|
697 | [x] => SgnVar x
|
adamc@59
|
698 | m :: ms => SgnProj (m,
|
adamc@59
|
699 List.take (ms, length ms - 1),
|
adamc@59
|
700 List.nth (ms, length ms - 1)),
|
adamc@59
|
701 s (mpathleft, mpathright))
|
adamc@42
|
702 | sgntm WHERE CON SYMBOL EQ cexp (SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
|
adamc@42
|
703 | sgntm WHERE LTYPE SYMBOL EQ cexp(SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
|
adamc@42
|
704 | LPAREN sgn RPAREN (sgn)
|
adamc@42
|
705
|
adamc@706
|
706 sgi : CON SYMBOL DCOLON kind ((SgiConAbs (SYMBOL, kind), s (CONleft, kindright)))
|
adamc@706
|
707 | LTYPE SYMBOL ((SgiConAbs (SYMBOL, (KType, s (LTYPEleft, SYMBOLright))),
|
adamc@706
|
708 s (LTYPEleft, SYMBOLright)))
|
adamc@706
|
709 | CON SYMBOL EQ cexp ((SgiCon (SYMBOL, NONE, cexp), s (CONleft, cexpright)))
|
adamc@706
|
710 | CON SYMBOL DCOLON kind EQ cexp ((SgiCon (SYMBOL, SOME kind, cexp), s (CONleft, cexpright)))
|
adamc@706
|
711 | LTYPE SYMBOL EQ cexp ((SgiCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
|
adamc@706
|
712 s (LTYPEleft, cexpright)))
|
adamc@805
|
713 | DATATYPE dtypes ((SgiDatatype dtypes, s (DATATYPEleft, dtypesright)))
|
adamc@191
|
714 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
|
adamc@191
|
715 (case dargs of
|
adamc@191
|
716 [] => (SgiDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
|
adamc@191
|
717 | _ => raise Fail "Arguments specified for imported datatype")
|
adamc@706
|
718 | VAL SYMBOL COLON cexp ((SgiVal (SYMBOL, cexp), s (VALleft, cexpright)))
|
adamc@30
|
719
|
adamc@706
|
720 | STRUCTURE CSYMBOL COLON sgn ((SgiStr (CSYMBOL, sgn), s (STRUCTUREleft, sgnright)))
|
adamc@706
|
721 | SIGNATURE CSYMBOL EQ sgn ((SgiSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright)))
|
adamc@42
|
722 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
|
adamc@706
|
723 ((SgiStr (CSYMBOL1,
|
adamc@706
|
724 (SgnFun (CSYMBOL2, sgn1, sgn2), s (FUNCTORleft, sgn2right))),
|
adamc@706
|
725 s (FUNCTORleft, sgn2right)))
|
adamc@706
|
726 | INCLUDE sgn ((SgiInclude sgn, s (INCLUDEleft, sgnright)))
|
adamc@706
|
727 | CONSTRAINT cterm TWIDDLE cterm ((SgiConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright)))
|
adamc@707
|
728 | TABLE SYMBOL COLON cterm pkopt commaOpt cstopt (let
|
adamc@707
|
729 val loc = s (TABLEleft, ctermright)
|
adamc@707
|
730 in
|
adamc@707
|
731 (SgiTable (SYMBOL, entable cterm, pkopt, cstopt), loc)
|
adamc@707
|
732 end)
|
adamc@460
|
733 | SEQUENCE SYMBOL (let
|
adamc@460
|
734 val loc = s (SEQUENCEleft, SYMBOLright)
|
adamc@460
|
735 val t = (CVar (["Basis"], "sql_sequence"), loc)
|
adamc@460
|
736 in
|
adamc@460
|
737 (SgiVal (SYMBOL, t), loc)
|
adamc@460
|
738 end)
|
adamc@754
|
739 | VIEW SYMBOL COLON cexp (let
|
adamc@754
|
740 val loc = s (VIEWleft, cexpright)
|
adamc@754
|
741 val t = (CVar (["Basis"], "sql_view"), loc)
|
adamc@1076
|
742 val t = (CApp (t, entable cexp), loc)
|
adamc@754
|
743 in
|
adamc@754
|
744 (SgiVal (SYMBOL, t), loc)
|
adamc@754
|
745 end)
|
adamc@563
|
746 | CLASS SYMBOL (let
|
adamc@563
|
747 val loc = s (CLASSleft, SYMBOLright)
|
adamc@711
|
748 val k = (KArrow ((KType, loc), (KType, loc)), loc)
|
adamc@563
|
749 in
|
adamc@711
|
750 (SgiClassAbs (SYMBOL, k), loc)
|
adamc@563
|
751 end)
|
adamc@563
|
752 | CLASS SYMBOL DCOLON kind (let
|
adamc@563
|
753 val loc = s (CLASSleft, kindright)
|
adamc@563
|
754 in
|
adamc@563
|
755 (SgiClassAbs (SYMBOL, kind), loc)
|
adamc@563
|
756 end)
|
adamc@563
|
757 | CLASS SYMBOL EQ cexp (let
|
adamc@563
|
758 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
759 in
|
adamc@563
|
760 (SgiClass (SYMBOL, (KWild, loc), cexp), loc)
|
adamc@563
|
761 end)
|
adamc@563
|
762 | CLASS SYMBOL DCOLON kind EQ cexp (let
|
adamc@563
|
763 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
764 in
|
adamc@563
|
765 (SgiClass (SYMBOL, kind, cexp), loc)
|
adamc@563
|
766 end)
|
adamc@211
|
767 | CLASS SYMBOL SYMBOL EQ cexp (let
|
adamc@211
|
768 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
769 val k = (KWild, loc)
|
adamc@211
|
770 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
|
adamc@211
|
771 in
|
adamc@563
|
772 (SgiClass (SYMBOL1, k, c), s (CLASSleft, cexpright))
|
adamc@563
|
773 end)
|
adamc@563
|
774 | CLASS SYMBOL LPAREN SYMBOL DCOLON kind RPAREN EQ cexp (let
|
adamc@563
|
775 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
776 val c = (CAbs (SYMBOL2, SOME kind, cexp), loc)
|
adamc@563
|
777 in
|
adamc@563
|
778 (SgiClass (SYMBOL1, kind, c), s (CLASSleft, cexpright))
|
adamc@211
|
779 end)
|
adamc@460
|
780 | COOKIE SYMBOL COLON cexp (let
|
adamc@460
|
781 val loc = s (COOKIEleft, cexpright)
|
adamc@460
|
782 val t = (CApp ((CVar (["Basis"], "http_cookie"), loc),
|
adamc@460
|
783 entable cexp), loc)
|
adamc@460
|
784 in
|
adamc@460
|
785 (SgiVal (SYMBOL, t), loc)
|
adamc@460
|
786 end)
|
adamc@720
|
787 | STYLE SYMBOL (let
|
adamc@720
|
788 val loc = s (STYLEleft, SYMBOLright)
|
adamc@720
|
789 val t = (CVar (["Basis"], "css_class"), loc)
|
adamc@718
|
790 in
|
adamc@718
|
791 (SgiVal (SYMBOL, t), loc)
|
adamc@718
|
792 end)
|
adamc@30
|
793
|
adamc@30
|
794 sgis : ([])
|
adamc@30
|
795 | sgi sgis (sgi :: sgis)
|
adamc@30
|
796
|
adamc@30
|
797 str : STRUCT decls END (StrConst decls, s (STRUCTleft, ENDright))
|
adamc@34
|
798 | spath (spath)
|
adamc@40
|
799 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN DARROW str
|
adamc@40
|
800 (StrFun (CSYMBOL, sgn, NONE, str), s (FUNCTORleft, strright))
|
adamc@40
|
801 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn DARROW str
|
adamc@40
|
802 (StrFun (CSYMBOL, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))
|
adamc@44
|
803 | spath LPAREN str RPAREN (StrApp (spath, str), s (spathleft, RPARENright))
|
adamc@34
|
804
|
adamc@34
|
805 spath : CSYMBOL (StrVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@34
|
806 | spath DOT CSYMBOL (StrProj (spath, CSYMBOL), s (spathleft, CSYMBOLright))
|
adamc@30
|
807
|
adamc@1
|
808 kind : TYPE (KType, s (TYPEleft, TYPEright))
|
adamc@1
|
809 | NAME (KName, s (NAMEleft, NAMEright))
|
adamc@1
|
810 | LBRACE kind RBRACE (KRecord kind, s (LBRACEleft, RBRACEright))
|
adamc@1
|
811 | kind ARROW kind (KArrow (kind1, kind2), s (kind1left, kind2right))
|
adamc@1
|
812 | LPAREN kind RPAREN (#1 kind, s (LPARENleft, RPARENright))
|
adamc@82
|
813 | KUNIT (KUnit, s (KUNITleft, KUNITright))
|
adamc@18
|
814 | UNDERUNDER (KWild, s (UNDERUNDERleft, UNDERUNDERright))
|
adamc@207
|
815 | LPAREN ktuple RPAREN (KTuple ktuple, s (LPARENleft, RPARENright))
|
adamc@623
|
816 | CSYMBOL (KVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@623
|
817 | CSYMBOL KARROW kind (KFun (CSYMBOL, kind), s (CSYMBOLleft, kindright))
|
adamc@207
|
818
|
adamc@207
|
819 ktuple : kind STAR kind ([kind1, kind2])
|
adamc@207
|
820 | kind STAR ktuple (kind :: ktuple)
|
adamc@1
|
821
|
adamc@1
|
822 capps : cterm (cterm)
|
adamc@1
|
823 | capps cterm (CApp (capps, cterm), s (cappsleft, ctermright))
|
adamc@1
|
824
|
adamc@1
|
825 cexp : capps (capps)
|
adamc@1
|
826 | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right))
|
adamc@15
|
827 | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright))
|
adamc@623
|
828 | CSYMBOL KARROW cexp (TKFun (CSYMBOL, cexp), s (CSYMBOLleft, cexpright))
|
adamc@1
|
829
|
adamc@1
|
830 | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right))
|
adamc@1
|
831
|
adamc@239
|
832 | FN cargs DARROW cexp (#1 (cargs (cexp, (KWild, s (FNleft, cexpright)))))
|
adamc@628
|
833 | LBRACK cexp TWIDDLE cexp RBRACK DARROW cexp (TDisjoint (cexp1, cexp2, cexp3), s (LBRACKleft, cexp3right))
|
adamc@623
|
834 | CSYMBOL DKARROW cexp (CKAbs (CSYMBOL, cexp), s (CSYMBOLleft, cexpright))
|
adamc@1
|
835
|
adamc@8
|
836 | LPAREN cexp RPAREN DCOLON kind (CAnnot (cexp, kind), s (LPARENleft, kindright))
|
adamc@6
|
837
|
adamc@18
|
838 | UNDER DCOLON kind (CWild kind, s (UNDERleft, UNDERright))
|
adamc@195
|
839 | ctuple (let
|
adamc@195
|
840 val loc = s (ctupleleft, ctupleright)
|
adamc@195
|
841 in
|
adamc@195
|
842 (TRecord (CRecord (ListUtil.mapi (fn (i, c) =>
|
adamc@195
|
843 ((CName (Int.toString (i + 1)), loc),
|
adamc@195
|
844 c)) ctuple),
|
adamc@195
|
845 loc), loc)
|
adamc@195
|
846 end)
|
adamc@18
|
847
|
adamc@1
|
848 kcolon : DCOLON (Explicit)
|
adamc@1
|
849 | TCOLON (Implicit)
|
adamc@1
|
850
|
adamc@239
|
851 cargs : carg (carg)
|
adamc@239
|
852 | cargl (cargl)
|
adamc@239
|
853
|
adamc@239
|
854 cargl : cargp cargp (cargp1 o cargp2)
|
adamc@239
|
855 | cargp cargl (cargp o cargl)
|
adamc@239
|
856
|
adamc@240
|
857 cargl2 : (fn x => x)
|
adamc@240
|
858 | cargp cargl2 (cargp o cargl2)
|
adamc@240
|
859
|
adamc@241
|
860 carg : SYMBOL DCOLON kind (fn (c, k) =>
|
adamc@239
|
861 let
|
adamc@239
|
862 val loc = s (SYMBOLleft, kindright)
|
adamc@239
|
863 in
|
adamc@239
|
864 ((CAbs (SYMBOL, SOME kind, c), loc),
|
adamc@239
|
865 (KArrow (kind, k), loc))
|
adamc@239
|
866 end)
|
adamc@329
|
867 | UNDER DCOLON kind (fn (c, k) =>
|
adamc@329
|
868 let
|
adamc@329
|
869 val loc = s (UNDERleft, kindright)
|
adamc@329
|
870 in
|
adamc@329
|
871 ((CAbs ("_", SOME kind, c), loc),
|
adamc@329
|
872 (KArrow (kind, k), loc))
|
adamc@329
|
873 end)
|
adam@1302
|
874 | SYMBOL DCOLONWILD (fn (c, k) =>
|
adam@1302
|
875 let
|
adam@1302
|
876 val loc = s (SYMBOLleft, DCOLONWILDright)
|
adam@1302
|
877 val kind = (KWild, loc)
|
adam@1302
|
878 in
|
adam@1302
|
879 ((CAbs (SYMBOL, NONE, c), loc),
|
adam@1302
|
880 (KArrow (kind, k), loc))
|
adam@1302
|
881 end)
|
adam@1302
|
882 | UNDER DCOLONWILD (fn (c, k) =>
|
adam@1302
|
883 let
|
adam@1302
|
884 val loc = s (UNDERleft, DCOLONWILDright)
|
adam@1302
|
885 val kind = (KWild, loc)
|
adam@1302
|
886 in
|
adam@1302
|
887 ((CAbs ("_", NONE, c), loc),
|
adam@1302
|
888 (KArrow (kind, k), loc))
|
adam@1302
|
889 end)
|
adamc@241
|
890 | cargp (cargp)
|
adamc@239
|
891
|
adamc@239
|
892 cargp : SYMBOL (fn (c, k) =>
|
adamc@239
|
893 let
|
adamc@239
|
894 val loc = s (SYMBOLleft, SYMBOLright)
|
adamc@239
|
895 in
|
adamc@239
|
896 ((CAbs (SYMBOL, NONE, c), loc),
|
adamc@239
|
897 (KArrow ((KWild, loc), k), loc))
|
adamc@239
|
898 end)
|
adamc@329
|
899 | UNDER (fn (c, k) =>
|
adamc@329
|
900 let
|
adamc@329
|
901 val loc = s (UNDERleft, UNDERright)
|
adamc@329
|
902 in
|
adamc@329
|
903 ((CAbs ("_", NONE, c), loc),
|
adamc@329
|
904 (KArrow ((KWild, loc), k), loc))
|
adamc@329
|
905 end)
|
adamc@1001
|
906 | LPAREN SYMBOL kopt ckl RPAREN (fn (c, k) =>
|
adamc@239
|
907 let
|
adamc@239
|
908 val loc = s (LPARENleft, RPARENright)
|
adamc@1001
|
909 val ckl = (SYMBOL, kopt) :: ckl
|
adamc@1001
|
910 val ckl = map (fn (x, ko) => (x, case ko of
|
adamc@1001
|
911 NONE => (KWild, loc)
|
adamc@1001
|
912 | SOME k => k)) ckl
|
adamc@239
|
913 in
|
adamc@1001
|
914 case ckl of
|
adamc@1001
|
915 [(x, k')] => ((CAbs (SYMBOL, SOME k', c), loc),
|
adamc@1001
|
916 (KArrow (k', k), loc))
|
adamc@1001
|
917 | _ =>
|
adamc@1001
|
918 let
|
adamc@1001
|
919 val k' = (KTuple (map #2 ckl), loc)
|
adamc@1001
|
920
|
adamc@1001
|
921 val c = foldr (fn ((x, k), c) =>
|
adamc@1001
|
922 (CAbs (x, SOME k, c), loc)) c ckl
|
adamc@1001
|
923 val v = (CVar ([], "$x"), loc)
|
adamc@1001
|
924 val c = ListUtil.foldli (fn (i, _, c) =>
|
adamc@1001
|
925 (CApp (c, (CProj (v, i + 1), loc)),
|
adamc@1001
|
926 loc)) c ckl
|
adamc@1001
|
927 in
|
adamc@1001
|
928 ((CAbs ("$x", SOME k', c), loc),
|
adamc@1001
|
929 (KArrow (k', k), loc))
|
adamc@1001
|
930 end
|
adamc@239
|
931 end)
|
adamc@628
|
932
|
adamc@1001
|
933 ckl : ([])
|
adamc@1001
|
934 | COMMA SYMBOL kopt ckl ((SYMBOL, kopt) :: ckl)
|
adamc@239
|
935
|
adamc@34
|
936 path : SYMBOL ([], SYMBOL)
|
adamc@34
|
937 | CSYMBOL DOT path (let val (ms, x) = path in (CSYMBOL :: ms, x) end)
|
adamc@34
|
938
|
adamc@156
|
939 cpath : CSYMBOL ([], CSYMBOL)
|
adamc@156
|
940 | CSYMBOL DOT cpath (let val (ms, x) = cpath in (CSYMBOL :: ms, x) end)
|
adamc@156
|
941
|
adamc@59
|
942 mpath : CSYMBOL ([CSYMBOL])
|
adamc@59
|
943 | CSYMBOL DOT mpath (CSYMBOL :: mpath)
|
adamc@59
|
944
|
adamc@1
|
945 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright))
|
adamc@1
|
946 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright))
|
adamc@83
|
947 | LBRACK rconn RBRACK (CRecord rconn, s (LBRACKleft, RBRACKright))
|
adamc@1
|
948 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)),
|
adamc@1
|
949 s (LBRACEleft, RBRACEright))
|
adamc@1
|
950 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright))
|
adamc@1
|
951 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright))
|
adamc@195
|
952 | HASH INT (CName (Int64.toString INT), s (HASHleft, INTright))
|
adamc@1
|
953
|
adamc@34
|
954 | path (CVar path, s (pathleft, pathright))
|
adamc@207
|
955 | path DOT INT (CProj ((CVar path, s (pathleft, pathright)), Int64.toInt INT),
|
adamc@207
|
956 s (pathleft, INTright))
|
adamc@18
|
957 | UNDER (CWild (KWild, s (UNDERleft, UNDERright)), s (UNDERleft, UNDERright))
|
adamc@621
|
958 | MAP (CMap, s (MAPleft, MAPright))
|
adamc@82
|
959 | UNIT (CUnit, s (UNITleft, UNITright))
|
adamc@207
|
960 | LPAREN ctuplev RPAREN (CTuple ctuplev, s (LPARENleft, RPARENright))
|
adamc@207
|
961
|
adamc@207
|
962 ctuplev: cexp COMMA cexp ([cexp1, cexp2])
|
adamc@207
|
963 | cexp COMMA ctuplev (cexp :: ctuplev)
|
adamc@1
|
964
|
adamc@196
|
965 ctuple : capps STAR capps ([capps1, capps2])
|
adamc@196
|
966 | capps STAR ctuple (capps :: ctuple)
|
adamc@195
|
967
|
adamc@1
|
968 rcon : ([])
|
adamc@1
|
969 | ident EQ cexp ([(ident, cexp)])
|
adamc@1
|
970 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon)
|
adamc@1
|
971
|
adamc@83
|
972 rconn : ident ([(ident, (CUnit, s (identleft, identright)))])
|
adamc@83
|
973 | ident COMMA rconn ((ident, (CUnit, s (identleft, identright))) :: rconn)
|
adamc@83
|
974
|
adamc@1
|
975 rcone : ([])
|
adamc@1
|
976 | ident COLON cexp ([(ident, cexp)])
|
adamc@1
|
977 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone)
|
adamc@1
|
978
|
adamc@1
|
979 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@195
|
980 | INT (CName (Int64.toString INT), s (INTleft, INTright))
|
adamc@200
|
981 | SYMBOL (CVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
|
adamc@8
|
982
|
adamc@8
|
983 eapps : eterm (eterm)
|
adamc@8
|
984 | eapps eterm (EApp (eapps, eterm), s (eappsleft, etermright))
|
adamc@8
|
985 | eapps LBRACK cexp RBRACK (ECApp (eapps, cexp), s (eappsleft, RBRACKright))
|
adamc@629
|
986 | eapps BANG (EDisjointApp eapps, s (eappsleft, BANGright))
|
adamc@8
|
987
|
adamc@8
|
988 eexp : eapps (eapps)
|
adamc@241
|
989 | FN eargs DARROW eexp (let
|
adamc@93
|
990 val loc = s (FNleft, eexpright)
|
adamc@93
|
991 in
|
adamc@241
|
992 #1 (eargs (eexp, (CWild (KType, loc), loc)))
|
adamc@93
|
993 end)
|
adamc@623
|
994 | CSYMBOL DKARROW eexp (EKAbs (CSYMBOL, eexp), s (CSYMBOLleft, eexpright))
|
adamc@196
|
995 | eexp COLON cexp (EAnnot (eexp, cexp), s (eexpleft, cexpright))
|
adamc@149
|
996 | eexp MINUSMINUS cexp (ECut (eexp, cexp), s (eexpleft, cexpright))
|
adamc@493
|
997 | eexp MINUSMINUSMINUS cexp (ECutMulti (eexp, cexp), s (eexpleft, cexpright))
|
adamc@170
|
998 | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
|
adamc@190
|
999 | IF eexp THEN eexp ELSE eexp (let
|
adamc@190
|
1000 val loc = s (IFleft, eexp3right)
|
adamc@190
|
1001 in
|
adamc@190
|
1002 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc), eexp2),
|
adamc@190
|
1003 ((PCon (["Basis"], "False", NONE), loc), eexp3)]), loc)
|
adamc@190
|
1004 end)
|
adamc@434
|
1005 | bind SEMI eexp (let
|
adamc@434
|
1006 val loc = s (bindleft, eexpright)
|
adamc@434
|
1007 val (v, to, e1) = bind
|
adamc@403
|
1008 val e = (EVar (["Basis"], "bind", Infer), loc)
|
adamc@434
|
1009 val e = (EApp (e, e1), loc)
|
adamc@243
|
1010 in
|
adamc@434
|
1011 (EApp (e, (EAbs (v, to, eexp), loc)), loc)
|
adamc@299
|
1012 end)
|
adamc@256
|
1013 | eexp EQ eexp (native_op ("eq", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@257
|
1014 | eexp NE eexp (native_op ("ne", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@389
|
1015 | MINUS eterm (native_unop ("neg", eterm, s (MINUSleft, etermright)))
|
adamc@389
|
1016 | eexp PLUS eexp (native_op ("plus", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@389
|
1017 | eexp MINUS eexp (native_op ("minus", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@1116
|
1018 | eapps STAR eexp (native_op ("times", eapps, eexp, s (eappsleft, eexpright)))
|
adamc@964
|
1019 | eexp DIVIDE eexp (native_op ("divide", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@389
|
1020 | eexp MOD eexp (native_op ("mod", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
1021
|
adamc@391
|
1022 | eexp LT eexp (native_op ("lt", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
1023 | eexp LE eexp (native_op ("le", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
1024 | eexp GT eexp (native_op ("gt", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
1025 | eexp GE eexp (native_op ("ge", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
1026
|
adamc@842
|
1027 | eexp ANDALSO eexp (let
|
adamc@842
|
1028 val loc = s (eexp1left, eexp2right)
|
adamc@842
|
1029 in
|
adamc@842
|
1030 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc),
|
adamc@842
|
1031 eexp2),
|
adamc@842
|
1032 ((PCon (["Basis"], "False", NONE), loc),
|
adamc@842
|
1033 (EVar (["Basis"], "False", Infer), loc))]), loc)
|
adamc@842
|
1034 end)
|
adamc@842
|
1035 | eexp ORELSE eexp (let
|
adamc@842
|
1036 val loc = s (eexp1left, eexp2right)
|
adamc@842
|
1037 in
|
adamc@842
|
1038 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc),
|
adamc@842
|
1039 (EVar (["Basis"], "True", Infer), loc)),
|
adamc@842
|
1040 ((PCon (["Basis"], "False", NONE), loc),
|
adamc@842
|
1041 eexp2)]), loc)
|
adamc@842
|
1042 end)
|
adamc@842
|
1043
|
adamc@445
|
1044 | eexp PLUSPLUS eexp (EConcat (eexp1, eexp2), s (eexp1left, eexp2right))
|
adamc@8
|
1045
|
adamc@674
|
1046 | eexp CARET eexp (native_op ("strcat", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@674
|
1047
|
adamc@794
|
1048 | eapps DCOLON eexp (let
|
adamc@794
|
1049 val loc = s (eappsleft, eexpright)
|
adamc@762
|
1050 in
|
adamc@762
|
1051 (EApp ((EVar (["Basis"], "Cons", Infer), loc),
|
adamc@762
|
1052 (ERecord [((CName "1", loc),
|
adamc@794
|
1053 eapps),
|
adamc@762
|
1054 ((CName "2", loc),
|
adamc@762
|
1055 eexp)], loc)), loc)
|
adamc@762
|
1056 end)
|
adamc@762
|
1057
|
adamc@434
|
1058 bind : SYMBOL LARROW eapps (SYMBOL, NONE, eapps)
|
adamc@434
|
1059 | eapps (let
|
adamc@434
|
1060 val loc = s (eappsleft, eappsright)
|
adamc@434
|
1061 in
|
adamc@434
|
1062 ("_", SOME (TRecord (CRecord [], loc), loc), eapps)
|
adamc@434
|
1063 end)
|
adamc@434
|
1064
|
adamc@241
|
1065 eargs : earg (earg)
|
adamc@241
|
1066 | eargl (eargl)
|
adamc@241
|
1067
|
adamc@241
|
1068 eargl : eargp eargp (eargp1 o eargp2)
|
adamc@241
|
1069 | eargp eargl (eargp o eargl)
|
adamc@241
|
1070
|
adamc@242
|
1071 eargl2 : (fn x => x)
|
adamc@242
|
1072 | eargp eargl2 (eargp o eargl2)
|
adamc@242
|
1073
|
adamc@822
|
1074 earg : patS (fn (e, t) =>
|
adamc@241
|
1075 let
|
adamc@822
|
1076 val loc = s (patSleft, patSright)
|
adamc@822
|
1077 val pt = patType loc patS
|
adamc@822
|
1078
|
adamc@822
|
1079 val e' = case #1 patS of
|
adamc@822
|
1080 PVar x => (EAbs (x, NONE, e), loc)
|
adamc@823
|
1081 | PAnnot ((PVar x, _), t) => (EAbs (x, SOME t, e), loc)
|
adamc@822
|
1082 | _ => (EAbs ("$x", SOME pt,
|
adamc@822
|
1083 (ECase ((EVar ([], "$x", DontInfer),
|
adamc@822
|
1084 loc),
|
adamc@822
|
1085 [(patS, e)]), loc)), loc)
|
adamc@241
|
1086 in
|
adamc@822
|
1087 (e', (TFun (pt, t), loc))
|
adamc@241
|
1088 end)
|
adamc@822
|
1089 | earga (earga)
|
adamc@822
|
1090
|
adamc@822
|
1091 eargp : pterm (fn (e, t) =>
|
adamc@241
|
1092 let
|
adamc@822
|
1093 val loc = s (ptermleft, ptermright)
|
adamc@822
|
1094 val pt = patType loc pterm
|
adamc@822
|
1095
|
adamc@822
|
1096 val e' = case #1 pterm of
|
adamc@822
|
1097 PVar x => (EAbs (x, NONE, e), loc)
|
adamc@823
|
1098 | PAnnot ((PVar x, _), t) => (EAbs (x, SOME t, e), loc)
|
adamc@822
|
1099 | _ => (EAbs ("$x", SOME pt,
|
adamc@822
|
1100 (ECase ((EVar ([], "$x", DontInfer),
|
adamc@822
|
1101 loc),
|
adamc@822
|
1102 [(pterm, e)]), loc)), loc)
|
adamc@241
|
1103 in
|
adamc@822
|
1104 (e', (TFun (pt, t), loc))
|
adamc@241
|
1105 end)
|
adamc@822
|
1106 | earga (earga)
|
adamc@241
|
1107
|
adamc@822
|
1108 earga : LBRACK SYMBOL RBRACK (fn (e, t) =>
|
adamc@241
|
1109 let
|
adamc@822
|
1110 val loc = s (LBRACKleft, RBRACKright)
|
adamc@822
|
1111 val kind = (KWild, loc)
|
adamc@822
|
1112 in
|
adamc@822
|
1113 ((ECAbs (Implicit, SYMBOL, kind, e), loc),
|
adamc@822
|
1114 (TCFun (Implicit, SYMBOL, kind, t), loc))
|
adamc@822
|
1115 end)
|
adam@1302
|
1116 | LBRACK SYMBOL DCOLONWILD RBRACK (fn (e, t) =>
|
adam@1302
|
1117 let
|
adam@1302
|
1118 val loc = s (LBRACKleft, RBRACKright)
|
adam@1302
|
1119 val kind = (KWild, loc)
|
adam@1302
|
1120 in
|
adam@1302
|
1121 ((ECAbs (Explicit, SYMBOL, kind, e), loc),
|
adam@1302
|
1122 (TCFun (Explicit, SYMBOL, kind, t), loc))
|
adam@1302
|
1123 end)
|
adamc@822
|
1124 | LBRACK SYMBOL kcolon kind RBRACK(fn (e, t) =>
|
adamc@822
|
1125 let
|
adamc@822
|
1126 val loc = s (LBRACKleft, RBRACKright)
|
adamc@241
|
1127 in
|
adamc@241
|
1128 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
|
adamc@241
|
1129 (TCFun (kcolon, SYMBOL, kind, t), loc))
|
adamc@241
|
1130 end)
|
adam@1306
|
1131 | LBRACK SYMBOL TCOLONWILD RBRACK (fn (e, t) =>
|
adam@1306
|
1132 let
|
adam@1306
|
1133 val loc = s (LBRACKleft, RBRACKright)
|
adam@1306
|
1134 val kind = (KWild, loc)
|
adam@1306
|
1135 in
|
adam@1306
|
1136 ((ECAbs (Implicit, SYMBOL, kind, e), loc),
|
adam@1306
|
1137 (TCFun (Implicit, SYMBOL, kind, t), loc))
|
adam@1306
|
1138 end)
|
adamc@478
|
1139 | LBRACK cexp TWIDDLE cexp RBRACK(fn (e, t) =>
|
adamc@356
|
1140 let
|
adamc@356
|
1141 val loc = s (LBRACKleft, RBRACKright)
|
adamc@356
|
1142 in
|
adamc@478
|
1143 ((EDisjoint (cexp1, cexp2, e), loc),
|
adamc@628
|
1144 (TDisjoint (cexp1, cexp2, t), loc))
|
adamc@356
|
1145 end)
|
adamc@822
|
1146 | LBRACK CSYMBOL RBRACK (fn (e, t) =>
|
adamc@623
|
1147 let
|
adamc@623
|
1148 val loc = s (CSYMBOLleft, CSYMBOLright)
|
adamc@623
|
1149 in
|
adamc@623
|
1150 ((EKAbs (CSYMBOL, e), loc),
|
adamc@623
|
1151 (TKFun (CSYMBOL, t), loc))
|
adamc@623
|
1152 end)
|
adamc@241
|
1153
|
adamc@8
|
1154 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
|
adamc@195
|
1155 | LPAREN etuple RPAREN (let
|
adamc@195
|
1156 val loc = s (LPARENleft, RPARENright)
|
adamc@195
|
1157 in
|
adamc@195
|
1158 (ERecord (ListUtil.mapi (fn (i, e) =>
|
adamc@195
|
1159 ((CName (Int.toString (i + 1)), loc),
|
adamc@195
|
1160 e)) etuple), loc)
|
adamc@195
|
1161 end)
|
adamc@8
|
1162
|
adamc@403
|
1163 | path (EVar (#1 path, #2 path, Infer), s (pathleft, pathright))
|
adamc@403
|
1164 | cpath (EVar (#1 cpath, #2 cpath, Infer), s (cpathleft, cpathright))
|
adamc@403
|
1165 | AT path (EVar (#1 path, #2 path, TypesOnly), s (ATleft, pathright))
|
adamc@403
|
1166 | AT AT path (EVar (#1 path, #2 path, DontInfer), s (AT1left, pathright))
|
adamc@403
|
1167 | AT cpath (EVar (#1 cpath, #2 cpath, TypesOnly), s (ATleft, cpathright))
|
adamc@403
|
1168 | AT AT cpath (EVar (#1 cpath, #2 cpath, DontInfer), s (AT1left, cpathright))
|
adamc@12
|
1169 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
|
adamc@110
|
1170 | UNIT (ERecord [], s (UNITleft, UNITright))
|
adamc@12
|
1171
|
adamc@14
|
1172 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@14
|
1173 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
|
adamc@14
|
1174 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@821
|
1175 | CHAR (EPrim (Prim.Char CHAR), s (CHARleft, CHARright))
|
adamc@14
|
1176
|
adamc@200
|
1177 | path DOT idents (let
|
adamc@200
|
1178 val loc = s (pathleft, identsright)
|
adamc@200
|
1179 in
|
adamc@200
|
1180 foldl (fn (ident, e) =>
|
adamc@200
|
1181 (EField (e, ident), loc))
|
adamc@403
|
1182 (EVar (#1 path, #2 path, Infer), s (pathleft, pathright)) idents
|
adamc@403
|
1183 end)
|
adamc@910
|
1184 | LPAREN eexp RPAREN DOT idents (let
|
adamc@910
|
1185 val loc = s (LPARENleft, identsright)
|
adamc@910
|
1186 in
|
adamc@910
|
1187 foldl (fn (ident, e) =>
|
adamc@910
|
1188 (EField (e, ident), loc))
|
adamc@910
|
1189 eexp idents
|
adamc@910
|
1190 end)
|
adamc@403
|
1191 | AT path DOT idents (let
|
adamc@403
|
1192 val loc = s (ATleft, identsright)
|
adamc@403
|
1193 in
|
adamc@403
|
1194 foldl (fn (ident, e) =>
|
adamc@403
|
1195 (EField (e, ident), loc))
|
adamc@403
|
1196 (EVar (#1 path, #2 path, TypesOnly), s (pathleft, pathright)) idents
|
adamc@403
|
1197 end)
|
adamc@403
|
1198 | AT AT path DOT idents (let
|
adamc@403
|
1199 val loc = s (AT1left, identsright)
|
adamc@403
|
1200 in
|
adamc@403
|
1201 foldl (fn (ident, e) =>
|
adamc@403
|
1202 (EField (e, ident), loc))
|
adamc@403
|
1203 (EVar (#1 path, #2 path, DontInfer), s (pathleft, pathright)) idents
|
adamc@200
|
1204 end)
|
adamc@71
|
1205
|
adamc@360
|
1206 | XML_BEGIN xml XML_END (let
|
adamc@360
|
1207 val loc = s (XML_BEGINleft, XML_ENDright)
|
adamc@360
|
1208 in
|
adamc@360
|
1209 if XML_BEGIN = "xml" then
|
adamc@360
|
1210 ()
|
adamc@360
|
1211 else
|
adamc@360
|
1212 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
|
adamc@360
|
1213 xml
|
adamc@360
|
1214 end)
|
adamc@360
|
1215 | XML_BEGIN XML_END (let
|
adamc@360
|
1216 val loc = s (XML_BEGINleft, XML_ENDright)
|
adamc@360
|
1217 in
|
adamc@360
|
1218 if XML_BEGIN = "xml" then
|
adamc@360
|
1219 ()
|
adamc@360
|
1220 else
|
adamc@360
|
1221 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
|
adamc@403
|
1222 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
|
adamc@360
|
1223 (EPrim (Prim.String ""), loc)),
|
adamc@360
|
1224 loc)
|
adamc@360
|
1225 end)
|
adamc@360
|
1226 | XML_BEGIN_END (let
|
adamc@360
|
1227 val loc = s (XML_BEGIN_ENDleft, XML_BEGIN_ENDright)
|
adamc@360
|
1228 in
|
adamc@360
|
1229 if XML_BEGIN_END = "xml" then
|
adamc@360
|
1230 ()
|
adamc@360
|
1231 else
|
adamc@360
|
1232 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
|
adamc@403
|
1233 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
|
adamc@360
|
1234 (EPrim (Prim.String ""), loc)),
|
adamc@360
|
1235 loc)
|
adamc@360
|
1236 end)
|
adamc@302
|
1237
|
adamc@204
|
1238 | LPAREN query RPAREN (query)
|
adamc@300
|
1239 | LPAREN CWHERE sqlexp RPAREN (sqlexp)
|
adamc@339
|
1240 | LPAREN SQL sqlexp RPAREN (sqlexp)
|
adamc@1070
|
1241 | LPAREN FROM tables RPAREN (#2 tables)
|
adamc@1071
|
1242 | LPAREN SELECT1 query1 RPAREN (query1)
|
adamc@302
|
1243
|
adamc@302
|
1244 | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN
|
adamc@302
|
1245 (let
|
adamc@302
|
1246 val loc = s (LPAREN1left, RPAREN3right)
|
adamc@302
|
1247
|
adamc@403
|
1248 val e = (EVar (["Basis"], "insert", Infer), loc)
|
adamc@302
|
1249 val e = (EApp (e, texp), loc)
|
adamc@302
|
1250 in
|
adamc@302
|
1251 if length fields <> length sqlexps then
|
adam@1360
|
1252 ErrorMsg.errorAt loc ("Length mismatch in INSERT field specification ("
|
adam@1360
|
1253 ^ Int.toString (length fields)
|
adam@1360
|
1254 ^ " vs. " ^ Int.toString (length sqlexps) ^ ")")
|
adamc@302
|
1255 else
|
adamc@302
|
1256 ();
|
adamc@302
|
1257 (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
|
adamc@302
|
1258 end)
|
adamc@310
|
1259 | LPAREN enterDml UPDATE texp SET fsets CWHERE sqlexp leaveDml RPAREN
|
adamc@303
|
1260 (let
|
adamc@303
|
1261 val loc = s (LPARENleft, RPARENright)
|
adamc@303
|
1262
|
adamc@403
|
1263 val e = (EVar (["Basis"], "update", Infer), loc)
|
adamc@342
|
1264 val e = (ECApp (e, (CWild (KRecord (KType, loc), loc), loc)), loc)
|
adamc@306
|
1265 val e = (EApp (e, (ERecord fsets, loc)), loc)
|
adamc@305
|
1266 val e = (EApp (e, texp), loc)
|
adamc@303
|
1267 in
|
adamc@303
|
1268 (EApp (e, sqlexp), loc)
|
adamc@303
|
1269 end)
|
adamc@310
|
1270 | LPAREN enterDml DELETE FROM texp CWHERE sqlexp leaveDml RPAREN
|
adamc@304
|
1271 (let
|
adamc@304
|
1272 val loc = s (LPARENleft, RPARENright)
|
adamc@304
|
1273
|
adamc@403
|
1274 val e = (EVar (["Basis"], "delete", Infer), loc)
|
adamc@304
|
1275 val e = (EApp (e, texp), loc)
|
adamc@304
|
1276 in
|
adamc@304
|
1277 (EApp (e, sqlexp), loc)
|
adamc@304
|
1278 end)
|
adamc@302
|
1279
|
adamc@211
|
1280 | UNDER (EWild, s (UNDERleft, UNDERright))
|
adamc@91
|
1281
|
adamc@446
|
1282 | LET edecls IN eexp END (ELet (edecls, eexp), s (LETleft, ENDright))
|
adamc@446
|
1283
|
adamc@762
|
1284 | LBRACK RBRACK (EVar (["Basis"], "Nil", Infer), s (LBRACKleft, RBRACKright))
|
adamc@762
|
1285
|
adamc@446
|
1286 edecls : ([])
|
adamc@446
|
1287 | edecl edecls (edecl :: edecls)
|
adamc@446
|
1288
|
adamc@825
|
1289 edecl : VAL pat EQ eexp ((EDVal (pat, eexp), s (VALleft, eexpright)))
|
adamc@446
|
1290 | VAL REC valis ((EDValRec valis, s (VALleft, valisright)))
|
adamc@446
|
1291 | FUN valis ((EDValRec valis, s (FUNleft, valisright)))
|
adamc@446
|
1292
|
adamc@310
|
1293 enterDml : (inDml := true)
|
adamc@310
|
1294 leaveDml : (inDml := false)
|
adamc@310
|
1295
|
adamc@403
|
1296 texp : SYMBOL (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
|
adamc@302
|
1297 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
|
adamc@302
|
1298
|
adamc@302
|
1299 fields : fident ([fident])
|
adamc@302
|
1300 | fident COMMA fields (fident :: fields)
|
adamc@302
|
1301
|
adamc@302
|
1302 sqlexps: sqlexp ([sqlexp])
|
adamc@302
|
1303 | sqlexp COMMA sqlexps (sqlexp :: sqlexps)
|
adamc@302
|
1304
|
adamc@303
|
1305 fsets : fident EQ sqlexp ([(fident, sqlexp)])
|
adamc@303
|
1306 | fident EQ sqlexp COMMA fsets ((fident, sqlexp) :: fsets)
|
adamc@303
|
1307
|
adamc@200
|
1308 idents : ident ([ident])
|
adamc@200
|
1309 | ident DOT idents (ident :: idents)
|
adamc@200
|
1310
|
adamc@195
|
1311 etuple : eexp COMMA eexp ([eexp1, eexp2])
|
adamc@195
|
1312 | eexp COMMA etuple (eexp :: etuple)
|
adamc@195
|
1313
|
adamc@170
|
1314 branch : pat DARROW eexp (pat, eexp)
|
adamc@170
|
1315
|
adamc@170
|
1316 branchs: ([])
|
adamc@170
|
1317 | BAR branch branchs (branch :: branchs)
|
adamc@170
|
1318
|
adamc@822
|
1319 patS : pterm (pterm)
|
adamc@822
|
1320 | pterm DCOLON patS (let
|
adamc@822
|
1321 val loc = s (ptermleft, patSright)
|
adamc@762
|
1322 in
|
adamc@762
|
1323 (PCon (["Basis"], "Cons", SOME (PRecord ([("1", pterm),
|
adamc@822
|
1324 ("2", patS)], false), loc)),
|
adamc@762
|
1325 loc)
|
adamc@762
|
1326 end)
|
adamc@822
|
1327 | patS COLON cexp (PAnnot (patS, cexp), s (patSleft, cexpright))
|
adamc@822
|
1328
|
adamc@822
|
1329 pat : patS (patS)
|
adamc@822
|
1330 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
|
adamc@170
|
1331
|
adamc@170
|
1332 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
|
adamc@170
|
1333 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
|
adamc@170
|
1334 | UNDER (PWild, s (UNDERleft, UNDERright))
|
adamc@173
|
1335 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
|
adam@1420
|
1336 | MINUS INT (PPrim (Prim.Int (~INT)), s (MINUSleft, INTright))
|
adamc@173
|
1337 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@821
|
1338 | CHAR (PPrim (Prim.Char CHAR), s (CHARleft, CHARright))
|
adamc@170
|
1339 | LPAREN pat RPAREN (pat)
|
adamc@174
|
1340 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
|
adamc@174
|
1341 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
|
adamc@174
|
1342 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
|
adamc@195
|
1343 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
|
adamc@195
|
1344 false),
|
adamc@195
|
1345 s (LPARENleft, RPARENright))
|
adamc@762
|
1346 | LBRACK RBRACK (PCon (["Basis"], "Nil", NONE), s (LBRACKleft, RBRACKright))
|
adamc@174
|
1347
|
adamc@175
|
1348 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
|
adamc@243
|
1349 | INT EQ pat ([(Int64.toString INT, pat)], false)
|
adamc@174
|
1350 | DOTDOTDOT ([], true)
|
adamc@175
|
1351 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
|
adamc@243
|
1352 | INT EQ pat COMMA rpat ((Int64.toString INT, pat) :: #1 rpat, #2 rpat)
|
adamc@170
|
1353
|
adamc@195
|
1354 ptuple : pat COMMA pat ([pat1, pat2])
|
adamc@195
|
1355 | pat COMMA ptuple (pat :: ptuple)
|
adamc@195
|
1356
|
adamc@12
|
1357 rexp : ([])
|
adamc@12
|
1358 | ident EQ eexp ([(ident, eexp)])
|
adamc@12
|
1359 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
|
adamc@91
|
1360
|
adamc@141
|
1361 xml : xmlOne xml (let
|
adamc@141
|
1362 val pos = s (xmlOneleft, xmlright)
|
adamc@141
|
1363 in
|
adamc@720
|
1364 (EApp ((EApp (
|
adamc@720
|
1365 (EVar (["Basis"], "join", Infer), pos),
|
adamc@720
|
1366 xmlOne), pos),
|
adamc@720
|
1367 xml), pos)
|
adamc@141
|
1368 end)
|
adamc@141
|
1369 | xmlOne (xmlOne)
|
adamc@91
|
1370
|
adamc@1045
|
1371 xmlOpt : xml (xml)
|
adamc@1045
|
1372 | (EApp ((EVar (["Basis"], "cdata", Infer), dummy),
|
adamc@1045
|
1373 (EPrim (Prim.String ""), dummy)),
|
adamc@1045
|
1374 dummy)
|
adamc@1045
|
1375
|
adamc@403
|
1376 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata", Infer), s (NOTAGSleft, NOTAGSright)),
|
adamc@141
|
1377 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
|
adamc@141
|
1378 s (NOTAGSleft, NOTAGSright))
|
adamc@141
|
1379 | tag DIVIDE GT (let
|
adamc@141
|
1380 val pos = s (tagleft, GTright)
|
adamc@710
|
1381
|
adamc@710
|
1382 val cdata =
|
adamc@756
|
1383 if #1 (#1 tag) = "submit" orelse #1 (#1 tag) = "dyn" then
|
adamc@710
|
1384 let
|
adamc@710
|
1385 val e = (EVar (["Basis"], "cdata", DontInfer), pos)
|
adamc@710
|
1386 val e = (ECApp (e, (CWild (KWild, pos), pos)), pos)
|
adamc@710
|
1387 in
|
adamc@710
|
1388 (ECApp (e, (CRecord [], pos)), pos)
|
adamc@710
|
1389 end
|
adamc@710
|
1390 else
|
adamc@710
|
1391 (EVar (["Basis"], "cdata", Infer), pos)
|
adamc@710
|
1392
|
adamc@710
|
1393 val cdata = (EApp (cdata,
|
adamc@710
|
1394 (EPrim (Prim.String ""), pos)),
|
adamc@710
|
1395 pos)
|
adamc@141
|
1396 in
|
adam@1412
|
1397 (EApp (#3 tag, cdata), pos)
|
adamc@141
|
1398 end)
|
adamc@141
|
1399
|
adamc@1045
|
1400 | tag GT xmlOpt END_TAG (let
|
adam@1563
|
1401 fun tagOut s =
|
adam@1563
|
1402 case s of
|
adam@1563
|
1403 "tabl" => "table"
|
adam@1563
|
1404 | _ => s
|
adam@1563
|
1405
|
adamc@141
|
1406 val pos = s (tagleft, GTright)
|
adamc@325
|
1407 val et = tagIn END_TAG
|
adamc@141
|
1408 in
|
adamc@756
|
1409 if #1 (#1 tag) = et then
|
adamc@361
|
1410 if et = "form" then
|
adam@1412
|
1411 let
|
adam@1412
|
1412 val e = (EVar (["Basis"], "form", Infer), pos)
|
adam@1412
|
1413 val e = (EApp (e, case #2 tag of
|
adam@1412
|
1414 NONE => (EVar (["Basis"], "None", Infer), pos)
|
adam@1412
|
1415 | SOME c => (EApp ((EVar (["Basis"], "Some", Infer), pos), c), pos)), pos)
|
adam@1412
|
1416 in
|
adam@1412
|
1417 (EApp (e, xmlOpt), pos)
|
adam@1412
|
1418 end
|
adamc@1093
|
1419 else if et = "subform" orelse et = "subforms" then
|
adamc@1093
|
1420 (EApp (#2 (#1 tag),
|
adamc@1045
|
1421 xmlOpt), pos)
|
adamc@758
|
1422 else if et = "entry" then
|
adamc@758
|
1423 (EApp ((EVar (["Basis"], "entry", Infer), pos),
|
adamc@1045
|
1424 xmlOpt), pos)
|
adamc@141
|
1425 else
|
adam@1412
|
1426 (EApp (#3 tag, xmlOpt), pos)
|
adamc@141
|
1427 else
|
adamc@325
|
1428 (if ErrorMsg.anyErrors () then
|
adamc@325
|
1429 ()
|
adamc@325
|
1430 else
|
adamc@1189
|
1431 ErrorMsg.errorAt pos ("Begin tag <"
|
adam@1563
|
1432 ^ tagOut (#1 (#1 tag))
|
adamc@1189
|
1433 ^ "> and end tag </"
|
adam@1563
|
1434 ^ tagOut et
|
adamc@1189
|
1435 ^ "> don't match.");
|
adamc@623
|
1436 (EWild, pos))
|
adamc@141
|
1437 end)
|
adamc@141
|
1438 | LBRACE eexp RBRACE (eexp)
|
adamc@391
|
1439 | LBRACE LBRACK eexp RBRACK RBRACE (let
|
adamc@391
|
1440 val loc = s (LBRACEleft, RBRACEright)
|
adamc@403
|
1441 val e = (EVar (["Top"], "txt", Infer), loc)
|
adamc@391
|
1442 in
|
adamc@391
|
1443 (EApp (e, eexp), loc)
|
adamc@391
|
1444 end)
|
adamc@92
|
1445
|
adamc@141
|
1446 tag : tagHead attrs (let
|
adamc@141
|
1447 val pos = s (tagHeadleft, attrsright)
|
adamc@721
|
1448
|
adamc@721
|
1449 val e = (EVar (["Basis"], "tag", Infer), pos)
|
adamc@721
|
1450 val eo = case #1 attrs of
|
adamc@721
|
1451 NONE => (EVar (["Basis"], "None", Infer), pos)
|
adamc@721
|
1452 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos),
|
adamc@721
|
1453 e), pos)
|
adamc@721
|
1454 val e = (EApp (e, eo), pos)
|
adamc@721
|
1455 val e = (EApp (e, (ERecord (#2 attrs), pos)), pos)
|
adamc@721
|
1456 val e = (EApp (e, (EApp (#2 tagHead,
|
adamc@721
|
1457 (ERecord [], pos)), pos)), pos)
|
adamc@141
|
1458 in
|
adam@1412
|
1459 (tagHead, #1 attrs, e)
|
adamc@141
|
1460 end)
|
adamc@141
|
1461
|
adamc@141
|
1462 tagHead: BEGIN_TAG (let
|
adamc@325
|
1463 val bt = tagIn BEGIN_TAG
|
adamc@141
|
1464 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
|
adamc@141
|
1465 in
|
adamc@325
|
1466 (bt,
|
adamc@473
|
1467 (EVar (["Basis"], bt, Infer), pos))
|
adamc@141
|
1468 end)
|
adamc@141
|
1469 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
|
adamc@92
|
1470
|
adamc@721
|
1471 attrs : (NONE, [])
|
adamc@721
|
1472 | attr attrs (let
|
adamc@721
|
1473 val loc = s (attrleft, attrsright)
|
adamc@721
|
1474 in
|
adamc@721
|
1475 case attr of
|
adamc@721
|
1476 Class e =>
|
adamc@721
|
1477 (case #1 attrs of
|
adamc@721
|
1478 NONE => ()
|
adamc@721
|
1479 | SOME _ => ErrorMsg.errorAt loc "Multiple classes specified for tag";
|
adamc@721
|
1480 (SOME e, #2 attrs))
|
adamc@721
|
1481 | Normal xe =>
|
adamc@721
|
1482 (#1 attrs, xe :: #2 attrs)
|
adamc@721
|
1483 end)
|
adamc@104
|
1484
|
adamc@721
|
1485 attr : SYMBOL EQ attrv (if SYMBOL = "class" then
|
adamc@721
|
1486 Class attrv
|
adamc@717
|
1487 else
|
adamc@724
|
1488 let
|
adamc@724
|
1489 val sym =
|
adamc@724
|
1490 case SYMBOL of
|
adamc@724
|
1491 "type" => "Typ"
|
adamc@724
|
1492 | x => capitalize x
|
adamc@724
|
1493 in
|
adamc@724
|
1494 Normal ((CName sym, s (SYMBOLleft, SYMBOLright)),
|
adamc@724
|
1495 if (sym = "Href" orelse sym = "Src")
|
adamc@724
|
1496 andalso (case #1 attrv of
|
adamc@724
|
1497 EPrim _ => true
|
adamc@724
|
1498 | _ => false) then
|
adamc@724
|
1499 let
|
adamc@724
|
1500 val loc = s (attrvleft, attrvright)
|
adamc@724
|
1501 in
|
adamc@724
|
1502 (EApp ((EVar (["Basis"], "bless", Infer), loc),
|
adamc@724
|
1503 attrv), loc)
|
adamc@724
|
1504 end
|
adamc@724
|
1505 else
|
adamc@724
|
1506 attrv)
|
adamc@724
|
1507 end)
|
adamc@204
|
1508
|
adamc@104
|
1509 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@104
|
1510 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
|
adamc@104
|
1511 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@110
|
1512 | LBRACE eexp RBRACE (eexp)
|
adamc@226
|
1513
|
adamc@232
|
1514 query : query1 obopt lopt ofopt (let
|
adamc@229
|
1515 val loc = s (query1left, query1right)
|
adamc@230
|
1516
|
adamc@230
|
1517 val re = (ERecord [((CName "Rows", loc),
|
adamc@230
|
1518 query1),
|
adamc@230
|
1519 ((CName "OrderBy", loc),
|
adamc@231
|
1520 obopt),
|
adamc@231
|
1521 ((CName "Limit", loc),
|
adamc@232
|
1522 lopt),
|
adamc@232
|
1523 ((CName "Offset", loc),
|
adamc@232
|
1524 ofopt)], loc)
|
adamc@229
|
1525 in
|
adamc@403
|
1526 (EApp ((EVar (["Basis"], "sql_query", Infer), loc), re), loc)
|
adamc@229
|
1527 end)
|
adamc@993
|
1528
|
adamc@993
|
1529 dopt : (EVar (["Basis"], "False", Infer), dummy)
|
adamc@993
|
1530 | DISTINCT (EVar (["Basis"], "True", Infer),
|
adamc@993
|
1531 s (DISTINCTleft, DISTINCTright))
|
adamc@993
|
1532
|
adamc@993
|
1533 query1 : SELECT dopt select FROM tables wopt gopt hopt
|
adamc@209
|
1534 (let
|
adamc@204
|
1535 val loc = s (SELECTleft, tablesright)
|
adamc@207
|
1536
|
adamc@1070
|
1537 val (empties, sel, exps) =
|
adamc@207
|
1538 case select of
|
adamc@1070
|
1539 Star => ([],
|
adamc@1070
|
1540 map (fn nm =>
|
adamc@233
|
1541 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
|
adamc@233
|
1542 loc),
|
adamc@233
|
1543 (CRecord [], loc)],
|
adamc@748
|
1544 loc))) (#1 tables),
|
adamc@233
|
1545 [])
|
adamc@207
|
1546 | Items sis =>
|
adamc@207
|
1547 let
|
adamc@748
|
1548 val tabs = map (fn nm => (nm, (CRecord [], loc))) (#1 tables)
|
adamc@1194
|
1549 val (_, tabs, exps) = foldl (amend_select loc)
|
adamc@1194
|
1550 (1, tabs, []) sis
|
adamc@1070
|
1551 val empties = List.mapPartial (fn (nm, (CRecord [], _)) =>
|
adamc@1070
|
1552 SOME nm
|
adamc@1070
|
1553 | _ => NONE) tabs
|
adamc@207
|
1554 in
|
adamc@1070
|
1555 (empties,
|
adamc@1070
|
1556 map (fn (nm, c) => (nm,
|
adamc@233
|
1557 (CTuple [c,
|
adamc@233
|
1558 (CWild (KRecord (KType, loc), loc),
|
adamc@233
|
1559 loc)], loc))) tabs,
|
adamc@233
|
1560 exps)
|
adamc@207
|
1561 end
|
adamc@207
|
1562
|
adamc@207
|
1563 val sel = (CRecord sel, loc)
|
adamc@207
|
1564
|
adamc@226
|
1565 val grp = case gopt of
|
adamc@403
|
1566 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all",
|
adamc@403
|
1567 Infer), loc),
|
adamc@226
|
1568 (CWild (KRecord (KRecord (KType, loc), loc),
|
adamc@226
|
1569 loc), loc)), loc)
|
adamc@226
|
1570 | SOME gis =>
|
adamc@226
|
1571 let
|
adamc@748
|
1572 val tabs = map (fn nm =>
|
adamc@748
|
1573 (nm, (CRecord [], loc))) (#1 tables)
|
adamc@226
|
1574 val tabs = foldl (amend_group loc) tabs gis
|
adamc@226
|
1575
|
adamc@226
|
1576 val tabs = map (fn (nm, c) =>
|
adamc@226
|
1577 (nm,
|
adamc@226
|
1578 (CTuple [c,
|
adamc@226
|
1579 (CWild (KRecord (KType, loc),
|
adamc@226
|
1580 loc),
|
adamc@226
|
1581 loc)], loc))) tabs
|
adamc@226
|
1582 in
|
adamc@403
|
1583 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
|
adamc@226
|
1584 (CRecord tabs, loc)), loc)
|
adamc@226
|
1585 end
|
adamc@226
|
1586
|
adamc@403
|
1587 val e = (EVar (["Basis"], "sql_query1", Infer), loc)
|
adamc@1070
|
1588 val e = (ECApp (e, (CRecord (map (fn nm => (nm, (CUnit, loc))) empties),
|
adamc@1070
|
1589 loc)), loc)
|
adamc@993
|
1590 val re = (ERecord [((CName "Distinct", loc),
|
adamc@993
|
1591 dopt),
|
adamc@993
|
1592 ((CName "From", loc),
|
adamc@748
|
1593 #2 tables),
|
adamc@209
|
1594 ((CName "Where", loc),
|
adamc@223
|
1595 wopt),
|
adamc@224
|
1596 ((CName "GroupBy", loc),
|
adamc@226
|
1597 grp),
|
adamc@224
|
1598 ((CName "Having", loc),
|
adamc@224
|
1599 hopt),
|
adamc@223
|
1600 ((CName "SelectFields", loc),
|
adamc@403
|
1601 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
|
adamc@233
|
1602 sel), loc)),
|
adamc@233
|
1603 ((CName "SelectExps", loc),
|
adamc@233
|
1604 (ERecord exps, loc))], loc)
|
adamc@223
|
1605
|
adamc@209
|
1606 val e = (EApp (e, re), loc)
|
adamc@204
|
1607 in
|
adamc@207
|
1608 e
|
adamc@204
|
1609 end)
|
adam@1427
|
1610 | query1 UNION query1 (sql_relop ("union", false, query11, query12, s (query11left, query12right)))
|
adam@1427
|
1611 | query1 INTERSECT query1 (sql_relop ("intersect", false, query11, query12, s (query11left, query12right)))
|
adam@1427
|
1612 | query1 EXCEPT query1 (sql_relop ("except", false, query11, query12, s (query11left, query12right)))
|
adam@1427
|
1613 | query1 UNION ALL query1 (sql_relop ("union", true, query11, query12, s (query11left, query12right)))
|
adam@1427
|
1614 | query1 INTERSECT ALL query1 (sql_relop ("intersect", true, query11, query12, s (query11left, query12right)))
|
adam@1427
|
1615 | query1 EXCEPT ALL query1 (sql_relop ("except", true, query11, query12, s (query11left, query12right)))
|
adamc@1070
|
1616 | LBRACE LBRACE LBRACE eexp RBRACE RBRACE RBRACE (eexp)
|
adamc@204
|
1617
|
adamc@749
|
1618 tables : fitem (fitem)
|
adamc@749
|
1619 | fitem COMMA tables (let
|
adamc@749
|
1620 val loc = s (fitemleft, tablesright)
|
adamc@748
|
1621
|
adamc@748
|
1622 val e = (EVar (["Basis"], "sql_from_comma", Infer), loc)
|
adamc@749
|
1623 val e = (EApp (e, #2 fitem), loc)
|
adamc@748
|
1624 in
|
adamc@749
|
1625 (#1 fitem @ #1 tables,
|
adamc@748
|
1626 (EApp (e, #2 tables), loc))
|
adamc@748
|
1627 end)
|
adamc@204
|
1628
|
adamc@749
|
1629 fitem : table' ([#1 table'], #2 table')
|
adamc@1265
|
1630 | LBRACE LBRACE eexp RBRACE RBRACE (tnamesOf eexp, eexp)
|
adamc@749
|
1631 | fitem JOIN fitem ON sqlexp (let
|
adamc@749
|
1632 val loc = s (fitem1left, sqlexpright)
|
adamc@749
|
1633
|
adamc@749
|
1634 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
|
adamc@749
|
1635 val e = (EApp (e, #2 fitem1), loc)
|
adamc@749
|
1636 val e = (EApp (e, #2 fitem2), loc)
|
adamc@749
|
1637 in
|
adamc@749
|
1638 (#1 fitem1 @ #1 fitem2,
|
adamc@749
|
1639 (EApp (e, sqlexp), loc))
|
adamc@749
|
1640 end)
|
adamc@749
|
1641 | fitem INNER JOIN fitem ON sqlexp (let
|
adamc@749
|
1642 val loc = s (fitem1left, sqlexpright)
|
adamc@749
|
1643
|
adamc@749
|
1644 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
|
adamc@749
|
1645 val e = (EApp (e, #2 fitem1), loc)
|
adamc@749
|
1646 val e = (EApp (e, #2 fitem2), loc)
|
adamc@749
|
1647 in
|
adamc@749
|
1648 (#1 fitem1 @ #1 fitem2,
|
adamc@749
|
1649 (EApp (e, sqlexp), loc))
|
adamc@749
|
1650 end)
|
adamc@749
|
1651 | fitem CROSS JOIN fitem (let
|
adamc@749
|
1652 val loc = s (fitem1left, fitem2right)
|
adamc@749
|
1653
|
adamc@749
|
1654 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
|
adamc@749
|
1655 val e = (EApp (e, #2 fitem1), loc)
|
adamc@749
|
1656 val e = (EApp (e, #2 fitem2), loc)
|
adamc@749
|
1657 val tru = sql_inject (EVar (["Basis"], "True", Infer), loc)
|
adamc@749
|
1658 in
|
adamc@749
|
1659 (#1 fitem1 @ #1 fitem2,
|
adamc@749
|
1660 (EApp (e, tru), loc))
|
adamc@749
|
1661 end)
|
adamc@750
|
1662 | fitem LEFT JOIN fitem ON sqlexp (let
|
adamc@750
|
1663 val loc = s (fitem1left, sqlexpright)
|
adamc@750
|
1664
|
adamc@750
|
1665 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
|
adamc@750
|
1666 val e = (EApp (e, #2 fitem1), loc)
|
adamc@750
|
1667 val e = (EApp (e, #2 fitem2), loc)
|
adamc@750
|
1668 in
|
adamc@750
|
1669 (#1 fitem1 @ #1 fitem2,
|
adamc@750
|
1670 (EApp (e, sqlexp), loc))
|
adamc@750
|
1671 end)
|
adamc@751
|
1672 | fitem LEFT OUTER JOIN fitem ON sqlexp (let
|
adamc@751
|
1673 val loc = s (fitem1left, sqlexpright)
|
adamc@751
|
1674
|
adamc@751
|
1675 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
|
adamc@751
|
1676 val e = (EApp (e, #2 fitem1), loc)
|
adamc@751
|
1677 val e = (EApp (e, #2 fitem2), loc)
|
adamc@751
|
1678 in
|
adamc@751
|
1679 (#1 fitem1 @ #1 fitem2,
|
adamc@751
|
1680 (EApp (e, sqlexp), loc))
|
adamc@751
|
1681 end)
|
adamc@751
|
1682 | fitem RIGHT JOIN fitem ON sqlexp (let
|
adamc@751
|
1683 val loc = s (fitem1left, sqlexpright)
|
adamc@751
|
1684
|
adamc@751
|
1685 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
|
adamc@751
|
1686 val e = (EApp (e, #2 fitem1), loc)
|
adamc@751
|
1687 val e = (EApp (e, #2 fitem2), loc)
|
adamc@751
|
1688 in
|
adamc@751
|
1689 (#1 fitem1 @ #1 fitem2,
|
adamc@751
|
1690 (EApp (e, sqlexp), loc))
|
adamc@751
|
1691 end)
|
adamc@751
|
1692 | fitem RIGHT OUTER JOIN fitem ON sqlexp (let
|
adamc@751
|
1693 val loc = s (fitem1left, sqlexpright)
|
adamc@751
|
1694
|
adamc@751
|
1695 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
|
adamc@751
|
1696 val e = (EApp (e, #2 fitem1), loc)
|
adamc@751
|
1697 val e = (EApp (e, #2 fitem2), loc)
|
adamc@751
|
1698 in
|
adamc@751
|
1699 (#1 fitem1 @ #1 fitem2,
|
adamc@751
|
1700 (EApp (e, sqlexp), loc))
|
adamc@751
|
1701 end)
|
adamc@751
|
1702 | fitem FULL JOIN fitem ON sqlexp (let
|
adamc@751
|
1703 val loc = s (fitem1left, sqlexpright)
|
adamc@751
|
1704
|
adamc@751
|
1705 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
|
adamc@751
|
1706 val e = (EApp (e, #2 fitem1), loc)
|
adamc@751
|
1707 val e = (EApp (e, #2 fitem2), loc)
|
adamc@751
|
1708 in
|
adamc@751
|
1709 (#1 fitem1 @ #1 fitem2,
|
adamc@751
|
1710 (EApp (e, sqlexp), loc))
|
adamc@751
|
1711 end)
|
adamc@751
|
1712 | fitem FULL OUTER JOIN fitem ON sqlexp (let
|
adamc@751
|
1713 val loc = s (fitem1left, sqlexpright)
|
adamc@751
|
1714
|
adamc@751
|
1715 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
|
adamc@751
|
1716 val e = (EApp (e, #2 fitem1), loc)
|
adamc@751
|
1717 val e = (EApp (e, #2 fitem2), loc)
|
adamc@751
|
1718 in
|
adamc@751
|
1719 (#1 fitem1 @ #1 fitem2,
|
adamc@751
|
1720 (EApp (e, sqlexp), loc))
|
adamc@751
|
1721 end)
|
adamc@1192
|
1722 | LPAREN query RPAREN AS tname (let
|
adamc@1192
|
1723 val loc = s (LPARENleft, RPARENright)
|
adamc@1192
|
1724
|
adamc@1192
|
1725 val e = (EVar (["Basis"], "sql_from_query", Infer), loc)
|
adamc@1192
|
1726 val e = (ECApp (e, tname), loc)
|
adamc@1192
|
1727 in
|
adamc@1192
|
1728 ([tname], (EApp (e, query), loc))
|
adamc@1192
|
1729 end)
|
adamc@749
|
1730
|
adamc@204
|
1731 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@204
|
1732 | LBRACE cexp RBRACE (cexp)
|
adamc@204
|
1733
|
adamc@243
|
1734 table : SYMBOL ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)),
|
adamc@403
|
1735 (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
|
adamc@403
|
1736 | SYMBOL AS tname (tname, (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
|
adamc@221
|
1737 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
|
adamc@207
|
1738
|
adamc@748
|
1739 table' : table (let
|
adamc@748
|
1740 val loc = s (tableleft, tableright)
|
adamc@748
|
1741 val e = (EVar (["Basis"], "sql_from_table", Infer), loc)
|
adamc@748
|
1742 val e = (ECApp (e, #1 table), loc)
|
adamc@748
|
1743 in
|
adamc@748
|
1744 (#1 table, (EApp (e, #2 table), loc))
|
adamc@748
|
1745 end)
|
adamc@748
|
1746
|
adamc@243
|
1747 tident : SYMBOL (CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright))
|
adamc@207
|
1748 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@221
|
1749 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
|
adamc@207
|
1750
|
adamc@207
|
1751 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@207
|
1752 | LBRACE cexp RBRACE (cexp)
|
adamc@207
|
1753
|
adamc@207
|
1754 seli : tident DOT fident (Field (tident, fident))
|
adamc@1194
|
1755 | sqlexp (Exp (NONE, sqlexp))
|
adamc@1194
|
1756 | sqlexp AS fident (Exp (SOME fident, sqlexp))
|
adamc@341
|
1757 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (Fields (tident, cexp))
|
adamc@207
|
1758
|
adamc@207
|
1759 selis : seli ([seli])
|
adamc@207
|
1760 | seli COMMA selis (seli :: selis)
|
adamc@207
|
1761
|
adamc@207
|
1762 select : STAR (Star)
|
adamc@207
|
1763 | selis (Items selis)
|
adamc@209
|
1764
|
adamc@403
|
1765 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", Infer),
|
adamc@209
|
1766 s (TRUEleft, TRUEright)))
|
adamc@403
|
1767 | FALSE (sql_inject (EVar (["Basis"], "False", Infer),
|
adamc@209
|
1768 s (FALSEleft, FALSEright)))
|
adamc@209
|
1769
|
adamc@222
|
1770 | INT (sql_inject (EPrim (Prim.Int INT),
|
adamc@222
|
1771 s (INTleft, INTright)))
|
adamc@222
|
1772 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
|
adamc@222
|
1773 s (FLOATleft, FLOATright)))
|
adamc@229
|
1774 | STRING (sql_inject (EPrim (Prim.String STRING),
|
adamc@229
|
1775 s (STRINGleft, STRINGright)))
|
adamc@441
|
1776 | CURRENT_TIMESTAMP (sql_nfunc ("current_timestamp",
|
adamc@441
|
1777 s (CURRENT_TIMESTAMPleft, CURRENT_TIMESTAMPright)))
|
adamc@222
|
1778
|
adamc@221
|
1779 | tident DOT fident (let
|
adamc@221
|
1780 val loc = s (tidentleft, fidentright)
|
adamc@403
|
1781 val e = (EVar (["Basis"], "sql_field", Infer), loc)
|
adamc@221
|
1782 val e = (ECApp (e, tident), loc)
|
adamc@221
|
1783 in
|
adamc@221
|
1784 (ECApp (e, fident), loc)
|
adamc@221
|
1785 end)
|
adamc@234
|
1786 | CSYMBOL (let
|
adamc@234
|
1787 val loc = s (CSYMBOLleft, CSYMBOLright)
|
adamc@310
|
1788 in
|
adamc@310
|
1789 if !inDml then
|
adamc@310
|
1790 let
|
adamc@403
|
1791 val e = (EVar (["Basis"], "sql_field", Infer), loc)
|
adamc@310
|
1792 val e = (ECApp (e, (CName "T", loc)), loc)
|
adamc@310
|
1793 in
|
adamc@310
|
1794 (ECApp (e, (CName CSYMBOL, loc)), loc)
|
adamc@310
|
1795 end
|
adamc@310
|
1796 else
|
adamc@310
|
1797 let
|
adamc@403
|
1798 val e = (EVar (["Basis"], "sql_exp", Infer), loc)
|
adamc@310
|
1799 in
|
adamc@310
|
1800 (ECApp (e, (CName CSYMBOL, loc)), loc)
|
adamc@310
|
1801 end
|
adamc@310
|
1802 end)
|
adamc@221
|
1803
|
adamc@471
|
1804 | LBRACE eexp RBRACE (eexp)
|
adamc@470
|
1805
|
adamc@559
|
1806 | sqlexp EQ sqlexp (sql_binary ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
1807 | sqlexp NE sqlexp (sql_binary ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
1808 | sqlexp LT sqlexp (sql_binary ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
1809 | sqlexp LE sqlexp (sql_binary ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
1810 | sqlexp GT sqlexp (sql_binary ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
1811 | sqlexp GE sqlexp (sql_binary ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
1812
|
adamc@559
|
1813 | sqlexp PLUS sqlexp (sql_binary ("plus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
1814 | sqlexp MINUS sqlexp (sql_binary ("minus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
1815 | sqlexp STAR sqlexp (sql_binary ("times", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
1816 | sqlexp DIVIDE sqlexp (sql_binary ("div", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
1817 | sqlexp MOD sqlexp (sql_binary ("mod", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1818
|
adamc@220
|
1819 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@220
|
1820 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
1821
|
adamc@220
|
1822 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
|
adamc@559
|
1823 | MINUS sqlexp (sql_unary ("neg", sqlexp, s (MINUSleft, sqlexpright)))
|
adamc@220
|
1824
|
adamc@470
|
1825 | sqlexp IS NULL (let
|
adamc@470
|
1826 val loc = s (sqlexpleft, NULLright)
|
adamc@470
|
1827 in
|
adamc@470
|
1828 (EApp ((EVar (["Basis"], "sql_is_null", Infer), loc),
|
adamc@470
|
1829 sqlexp), loc)
|
adamc@470
|
1830 end)
|
adamc@470
|
1831
|
kkallio@1572
|
1832 | CIF sqlexp CTHEN sqlexp CELSE sqlexp (let
|
kkallio@1572
|
1833 val loc = s (CIFleft, sqlexp3right)
|
kkallio@1572
|
1834 val e = (EVar (["Basis"], "sql_if_then_else", Infer), loc)
|
kkallio@1572
|
1835 in
|
kkallio@1572
|
1836 (EApp ((EApp ((EApp (e, sqlexp1), loc), sqlexp2), loc), sqlexp3), loc)
|
kkallio@1572
|
1837 end)
|
kkallio@1572
|
1838
|
adamc@471
|
1839 | LBRACE LBRACK eexp RBRACK RBRACE (sql_inject (#1 eexp,
|
adamc@471
|
1840 s (LBRACEleft, RBRACEright)))
|
adamc@220
|
1841 | LPAREN sqlexp RPAREN (sqlexp)
|
adamc@210
|
1842
|
adamc@467
|
1843 | NULL (sql_inject ((EVar (["Basis"], "None", Infer),
|
adamc@467
|
1844 s (NULLleft, NULLright))))
|
adamc@467
|
1845
|
adamc@235
|
1846 | COUNT LPAREN STAR RPAREN (let
|
adamc@235
|
1847 val loc = s (COUNTleft, RPARENright)
|
adamc@235
|
1848 in
|
adamc@544
|
1849 (EVar (["Basis"], "sql_count", Infer), loc)
|
adamc@235
|
1850 end)
|
adamc@1187
|
1851 | COUNT LPAREN sqlexp RPAREN (let
|
adamc@1187
|
1852 val loc = s (COUNTleft, RPARENright)
|
adamc@1187
|
1853
|
adamc@1187
|
1854 val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
|
adamc@1187
|
1855 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
|
adamc@1187
|
1856 e), loc)
|
adamc@1187
|
1857 in
|
adamc@1187
|
1858 (EApp (e, sqlexp), loc)
|
adamc@1187
|
1859 end)
|
adamc@236
|
1860 | sqlagg LPAREN sqlexp RPAREN (let
|
adamc@236
|
1861 val loc = s (sqlaggleft, RPARENright)
|
adamc@236
|
1862
|
adamc@403
|
1863 val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
|
adamc@403
|
1864 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
|
adamc@236
|
1865 e), loc)
|
adamc@236
|
1866 in
|
adamc@236
|
1867 (EApp (e, sqlexp), loc)
|
adamc@236
|
1868 end)
|
adamc@746
|
1869 | fname LPAREN sqlexp RPAREN (let
|
adamc@746
|
1870 val loc = s (fnameleft, RPARENright)
|
adamc@746
|
1871
|
adamc@746
|
1872 val e = (EVar (["Basis"], "sql_ufunc", Infer), loc)
|
adamc@746
|
1873 val e = (EApp (e, fname), loc)
|
adamc@746
|
1874 in
|
adamc@746
|
1875 (EApp (e, sqlexp), loc)
|
adamc@746
|
1876 end)
|
adamc@1191
|
1877 | LPAREN query RPAREN (let
|
adamc@1191
|
1878 val loc = s (LPARENleft, RPARENright)
|
adamc@1191
|
1879
|
adamc@1191
|
1880 val e = (EVar (["Basis"], "sql_subquery", Infer), loc)
|
adamc@1191
|
1881 in
|
adamc@1191
|
1882 (EApp (e, query), loc)
|
adamc@1191
|
1883 end)
|
adamc@746
|
1884
|
adamc@746
|
1885 fname : SYMBOL (EVar (["Basis"], "sql_" ^ SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
|
adamc@746
|
1886 | LBRACE eexp RBRACE (eexp)
|
adamc@235
|
1887
|
adamc@403
|
1888 wopt : (sql_inject (EVar (["Basis"], "True", Infer),
|
adamc@230
|
1889 dummy))
|
adamc@209
|
1890 | CWHERE sqlexp (sqlexp)
|
adamc@226
|
1891
|
adamc@226
|
1892 groupi : tident DOT fident (GField (tident, fident))
|
adam@1425
|
1893 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (GFields (tident, cexp))
|
adamc@226
|
1894
|
adamc@226
|
1895 groupis: groupi ([groupi])
|
adamc@226
|
1896 | groupi COMMA groupis (groupi :: groupis)
|
adamc@226
|
1897
|
adamc@226
|
1898 gopt : (NONE)
|
adamc@226
|
1899 | GROUP BY groupis (SOME groupis)
|
adamc@227
|
1900
|
adamc@403
|
1901 hopt : (sql_inject (EVar (["Basis"], "True", Infer),
|
adamc@230
|
1902 dummy))
|
adamc@227
|
1903 | HAVING sqlexp (sqlexp)
|
adamc@230
|
1904
|
adamc@403
|
1905 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
|
adamc@234
|
1906 (CWild (KRecord (KType, dummy), dummy), dummy)),
|
adamc@230
|
1907 dummy)
|
adamc@230
|
1908 | ORDER BY obexps (obexps)
|
adamc@230
|
1909
|
adamc@268
|
1910 obitem : sqlexp diropt (sqlexp, diropt)
|
adamc@268
|
1911
|
adamc@268
|
1912 obexps : obitem (let
|
adamc@268
|
1913 val loc = s (obitemleft, obitemright)
|
adamc@230
|
1914
|
adamc@403
|
1915 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), loc),
|
adamc@234
|
1916 (CWild (KRecord (KType, loc), loc), loc)),
|
adamc@230
|
1917 loc)
|
adamc@403
|
1918 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
|
adamc@268
|
1919 #1 obitem), loc)
|
adamc@268
|
1920 val e = (EApp (e, #2 obitem), loc)
|
adamc@230
|
1921 in
|
adamc@230
|
1922 (EApp (e, e'), loc)
|
adamc@230
|
1923 end)
|
adamc@268
|
1924 | obitem COMMA obexps (let
|
adamc@268
|
1925 val loc = s (obitemleft, obexpsright)
|
adamc@230
|
1926
|
adamc@403
|
1927 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
|
adamc@268
|
1928 #1 obitem), loc)
|
adamc@268
|
1929 val e = (EApp (e, #2 obitem), loc)
|
adamc@230
|
1930 in
|
adamc@230
|
1931 (EApp (e, obexps), loc)
|
adamc@230
|
1932 end)
|
adamc@231
|
1933
|
adamc@403
|
1934 diropt : (EVar (["Basis"], "sql_asc", Infer), dummy)
|
adamc@403
|
1935 | ASC (EVar (["Basis"], "sql_asc", Infer), s (ASCleft, ASCright))
|
adamc@403
|
1936 | DESC (EVar (["Basis"], "sql_desc", Infer), s (DESCleft, DESCright))
|
adam@1543
|
1937 | LBRACE eexp RBRACE (eexp)
|
adamc@268
|
1938
|
adamc@403
|
1939 lopt : (EVar (["Basis"], "sql_no_limit", Infer), dummy)
|
adamc@403
|
1940 | LIMIT ALL (EVar (["Basis"], "sql_no_limit", Infer), dummy)
|
adamc@231
|
1941 | LIMIT sqlint (let
|
adamc@231
|
1942 val loc = s (LIMITleft, sqlintright)
|
adamc@231
|
1943 in
|
adamc@403
|
1944 (EApp ((EVar (["Basis"], "sql_limit", Infer), loc), sqlint), loc)
|
adamc@231
|
1945 end)
|
adamc@231
|
1946
|
adamc@403
|
1947 ofopt : (EVar (["Basis"], "sql_no_offset", Infer), dummy)
|
adamc@232
|
1948 | OFFSET sqlint (let
|
adamc@232
|
1949 val loc = s (OFFSETleft, sqlintright)
|
adamc@232
|
1950 in
|
adamc@403
|
1951 (EApp ((EVar (["Basis"], "sql_offset", Infer), loc), sqlint), loc)
|
adamc@232
|
1952 end)
|
adamc@232
|
1953
|
adamc@231
|
1954 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@231
|
1955 | LBRACE eexp RBRACE (eexp)
|
adamc@236
|
1956
|
adamc@236
|
1957 sqlagg : AVG ("avg")
|
adamc@236
|
1958 | SUM ("sum")
|
adamc@236
|
1959 | MIN ("min")
|
adamc@236
|
1960 | MAX ("max")
|