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