adamc@1
|
1 (* Copyright (c) 2008, 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@219
|
122 fun sql_compare (oper, sqlexp1, sqlexp2, loc) =
|
adamc@219
|
123 let
|
adamc@403
|
124 val e = (EVar (["Basis"], "sql_comparison", Infer), loc)
|
adamc@403
|
125 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
|
adamc@219
|
126 val e = (EApp (e, sqlexp1), loc)
|
adamc@219
|
127 in
|
adamc@234
|
128 (EApp (e, sqlexp2), loc)
|
adamc@220
|
129 end
|
adamc@220
|
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
|
adamc@229
|
148 fun sql_relop (oper, 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)
|
adamc@229
|
152 val e = (EApp (e, sqlexp1), loc)
|
adamc@229
|
153 in
|
adamc@229
|
154 (EApp (e, sqlexp2), loc)
|
adamc@229
|
155 end
|
adamc@229
|
156
|
adamc@441
|
157 fun sql_nfunc (oper, loc) =
|
adamc@441
|
158 let
|
adamc@441
|
159 val e = (EVar (["Basis"], "sql_nfunc", Infer), loc)
|
adamc@441
|
160 in
|
adamc@441
|
161 (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
|
adamc@441
|
162 end
|
adamc@441
|
163
|
adamc@389
|
164 fun native_unop (oper, e1, loc) =
|
adamc@389
|
165 let
|
adamc@403
|
166 val e = (EVar (["Basis"], oper, Infer), loc)
|
adamc@389
|
167 in
|
adamc@389
|
168 (EApp (e, e1), loc)
|
adamc@389
|
169 end
|
adamc@389
|
170
|
adamc@256
|
171 fun native_op (oper, e1, e2, loc) =
|
adamc@256
|
172 let
|
adamc@403
|
173 val e = (EVar (["Basis"], oper, Infer), loc)
|
adamc@256
|
174 val e = (EApp (e, e1), loc)
|
adamc@256
|
175 in
|
adamc@256
|
176 (EApp (e, e2), loc)
|
adamc@256
|
177 end
|
adamc@256
|
178
|
adamc@310
|
179 val inDml = ref false
|
adamc@310
|
180
|
adamc@325
|
181 fun tagIn bt =
|
adamc@325
|
182 case bt of
|
adamc@325
|
183 "table" => "tabl"
|
adamc@325
|
184 | _ => bt
|
adamc@325
|
185
|
adamc@1
|
186 %%
|
adamc@244
|
187 %header (functor UrwebLrValsFn(structure Token : TOKEN))
|
adamc@1
|
188
|
adamc@1
|
189 %term
|
adamc@1
|
190 EOF
|
adamc@14
|
191 | STRING of string | INT of Int64.int | FLOAT of Real64.real
|
adamc@1
|
192 | SYMBOL of string | CSYMBOL of string
|
adamc@1
|
193 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
|
adamc@156
|
194 | EQ | COMMA | COLON | DCOLON | TCOLON | DOT | HASH | UNDER | UNDERUNDER | BAR
|
adamc@403
|
195 | PLUS | MINUS | DIVIDE | DOTDOTDOT | MOD | AT
|
adamc@242
|
196 | CON | LTYPE | VAL | REC | AND | FUN | FOLD | UNIT | KUNIT | CLASS
|
adamc@156
|
197 | DATATYPE | OF
|
adamc@7
|
198 | TYPE | NAME
|
adamc@243
|
199 | ARROW | LARROW | DARROW | STAR | SEMI
|
adamc@493
|
200 | FN | PLUSPLUS | MINUSMINUS | MINUSMINUSMINUS | DOLLAR | TWIDDLE
|
adamc@446
|
201 | LET | IN
|
adamc@445
|
202 | STRUCTURE | SIGNATURE | STRUCT | SIG | END | FUNCTOR | WHERE | EXTERN | SQL
|
adamc@338
|
203 | INCLUDE | OPEN | CONSTRAINT | CONSTRAINTS | EXPORT | TABLE | SEQUENCE
|
adamc@459
|
204 | COOKIE
|
adamc@190
|
205 | CASE | IF | THEN | ELSE
|
adamc@1
|
206
|
adamc@360
|
207 | XML_BEGIN of string | XML_END | XML_BEGIN_END of string
|
adamc@91
|
208 | NOTAGS of string
|
adamc@91
|
209 | BEGIN_TAG of string | END_TAG of string
|
adamc@91
|
210
|
adamc@230
|
211 | SELECT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING
|
adamc@229
|
212 | UNION | INTERSECT | EXCEPT
|
adamc@232
|
213 | LIMIT | OFFSET | ALL
|
adamc@220
|
214 | TRUE | FALSE | CAND | OR | NOT
|
adamc@236
|
215 | COUNT | AVG | SUM | MIN | MAX
|
adamc@268
|
216 | ASC | DESC
|
adamc@470
|
217 | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS
|
adamc@441
|
218 | CURRENT_TIMESTAMP
|
adamc@219
|
219 | NE | LT | LE | GT | GE
|
adamc@204
|
220
|
adamc@30
|
221 %nonterm
|
adamc@1
|
222 file of decl list
|
adamc@1
|
223 | decls of decl list
|
adamc@325
|
224 | decl of decl list
|
adamc@123
|
225 | vali of string * con option * exp
|
adamc@123
|
226 | valis of (string * con option * exp) list
|
adamc@242
|
227 | copt of con option
|
adamc@1
|
228
|
adamc@191
|
229 | dargs of string list
|
adamc@156
|
230 | barOpt of unit
|
adamc@156
|
231 | dcons of (string * con option) list
|
adamc@156
|
232 | dcon of string * con option
|
adamc@156
|
233
|
adamc@30
|
234 | sgn of sgn
|
adamc@42
|
235 | sgntm of sgn
|
adamc@30
|
236 | sgi of sgn_item
|
adamc@30
|
237 | sgis of sgn_item list
|
adamc@30
|
238
|
adamc@30
|
239 | str of str
|
adamc@30
|
240
|
adamc@1
|
241 | kind of kind
|
adamc@207
|
242 | ktuple of kind list
|
adamc@1
|
243 | kcolon of explicitness
|
adamc@240
|
244 | kopt of kind option
|
adamc@1
|
245
|
adamc@34
|
246 | path of string list * string
|
adamc@156
|
247 | cpath of string list * string
|
adamc@34
|
248 | spath of str
|
adamc@59
|
249 | mpath of string list
|
adamc@34
|
250
|
adamc@1
|
251 | cexp of con
|
adamc@1
|
252 | capps of con
|
adamc@1
|
253 | cterm of con
|
adamc@195
|
254 | ctuple of con list
|
adamc@207
|
255 | ctuplev of con list
|
adamc@1
|
256 | ident of con
|
adamc@200
|
257 | idents of con list
|
adamc@1
|
258 | rcon of (con * con) list
|
adamc@83
|
259 | rconn of (con * con) list
|
adamc@1
|
260 | rcone of (con * con) list
|
adamc@239
|
261 | cargs of con * kind -> con * kind
|
adamc@239
|
262 | cargl of con * kind -> con * kind
|
adamc@240
|
263 | cargl2 of con * kind -> con * kind
|
adamc@239
|
264 | carg of con * kind -> con * kind
|
adamc@239
|
265 | cargp of con * kind -> con * kind
|
adamc@1
|
266
|
adamc@8
|
267 | eexp of exp
|
adamc@8
|
268 | eapps of exp
|
adamc@8
|
269 | eterm of exp
|
adamc@195
|
270 | etuple of exp list
|
adamc@12
|
271 | rexp of (con * exp) list
|
adamc@91
|
272 | xml of exp
|
adamc@91
|
273 | xmlOne of exp
|
adamc@141
|
274 | tag of string * exp
|
adamc@141
|
275 | tagHead of string * exp
|
adamc@434
|
276 | bind of string * con option * exp
|
adamc@446
|
277 | edecl of edecl
|
adamc@446
|
278 | edecls of edecl list
|
adamc@8
|
279
|
adamc@241
|
280 | earg of exp * con -> exp * con
|
adamc@241
|
281 | eargp of exp * con -> exp * con
|
adamc@241
|
282 | eargs of exp * con -> exp * con
|
adamc@241
|
283 | eargl of exp * con -> exp * con
|
adamc@242
|
284 | eargl2 of exp * con -> exp * con
|
adamc@241
|
285
|
adamc@170
|
286 | branch of pat * exp
|
adamc@170
|
287 | branchs of (pat * exp) list
|
adamc@170
|
288 | pat of pat
|
adamc@170
|
289 | pterm of pat
|
adamc@174
|
290 | rpat of (string * pat) list * bool
|
adamc@195
|
291 | ptuple of pat list
|
adamc@170
|
292
|
adamc@104
|
293 | attrs of (con * exp) list
|
adamc@104
|
294 | attr of con * exp
|
adamc@104
|
295 | attrv of exp
|
adamc@104
|
296
|
adamc@204
|
297 | query of exp
|
adamc@226
|
298 | query1 of exp
|
adamc@204
|
299 | tables of (con * exp) list
|
adamc@204
|
300 | tname of con
|
adamc@204
|
301 | table of con * exp
|
adamc@207
|
302 | tident of con
|
adamc@207
|
303 | fident of con
|
adamc@207
|
304 | seli of select_item
|
adamc@207
|
305 | selis of select_item list
|
adamc@207
|
306 | select of select
|
adamc@209
|
307 | sqlexp of exp
|
adamc@209
|
308 | wopt of exp
|
adamc@226
|
309 | groupi of group_item
|
adamc@226
|
310 | groupis of group_item list
|
adamc@226
|
311 | gopt of group_item list option
|
adamc@227
|
312 | hopt of exp
|
adamc@230
|
313 | obopt of exp
|
adamc@268
|
314 | obitem of exp * exp
|
adamc@230
|
315 | obexps of exp
|
adamc@268
|
316 | diropt of exp
|
adamc@231
|
317 | lopt of exp
|
adamc@232
|
318 | ofopt of exp
|
adamc@231
|
319 | sqlint of exp
|
adamc@236
|
320 | sqlagg of string
|
adamc@207
|
321
|
adamc@302
|
322 | texp of exp
|
adamc@302
|
323 | fields of con list
|
adamc@302
|
324 | sqlexps of exp list
|
adamc@303
|
325 | fsets of (con * exp) list
|
adamc@310
|
326 | enterDml of unit
|
adamc@310
|
327 | leaveDml of unit
|
adamc@302
|
328
|
adamc@204
|
329
|
adamc@1
|
330 %verbose (* print summary of errors *)
|
adamc@1
|
331 %pos int (* positions *)
|
adamc@1
|
332 %start file
|
adamc@1
|
333 %pure
|
adamc@1
|
334 %eop EOF
|
adamc@1
|
335 %noshift EOF
|
adamc@1
|
336
|
adamc@244
|
337 %name Urweb
|
adamc@1
|
338
|
adamc@243
|
339 %right SEMI
|
adamc@243
|
340 %nonassoc LARROW
|
adamc@195
|
341 %nonassoc IF THEN ELSE
|
adamc@1
|
342 %nonassoc DARROW
|
adamc@1
|
343 %nonassoc COLON
|
adamc@6
|
344 %nonassoc DCOLON TCOLON
|
adamc@229
|
345 %left UNION INTERSECT EXCEPT
|
adamc@1
|
346 %right COMMA
|
adamc@220
|
347 %right OR
|
adamc@220
|
348 %right CAND
|
adamc@470
|
349 %nonassoc EQ NE LT LE GT GE IS
|
adamc@243
|
350 %right ARROW
|
adamc@493
|
351 %right PLUSPLUS MINUSMINUS MINUSMINUSMINUS
|
adamc@389
|
352 %left PLUS MINUS
|
adamc@389
|
353 %left STAR DIVIDE MOD
|
adamc@220
|
354 %left NOT
|
adamc@84
|
355 %nonassoc TWIDDLE
|
adamc@1
|
356 %nonassoc DOLLAR
|
adamc@1
|
357 %left DOT
|
adamc@221
|
358 %nonassoc LBRACE RBRACE
|
adamc@1
|
359
|
adamc@1
|
360 %%
|
adamc@1
|
361
|
adamc@1
|
362 file : decls (decls)
|
adamc@54
|
363 | SIG sgis ([(DSgn ("?", (SgnConst sgis, s (SIGleft, sgisright))),
|
adamc@54
|
364 s (SIGleft, sgisright))])
|
adamc@1
|
365
|
adamc@1
|
366 decls : ([])
|
adamc@325
|
367 | decl decls (decl @ decls)
|
adamc@1
|
368
|
adamc@240
|
369 decl : CON SYMBOL cargl2 kopt EQ cexp (let
|
adamc@240
|
370 val loc = s (CONleft, cexpright)
|
adamc@240
|
371
|
adamc@240
|
372 val k = Option.getOpt (kopt, (KWild, loc))
|
adamc@240
|
373 val (c, k) = cargl2 (cexp, k)
|
adamc@240
|
374 in
|
adamc@325
|
375 [(DCon (SYMBOL, SOME k, c), loc)]
|
adamc@240
|
376 end)
|
adamc@325
|
377 | LTYPE SYMBOL EQ cexp ([(DCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
|
adamc@325
|
378 s (LTYPEleft, cexpright))])
|
adamc@325
|
379 | DATATYPE SYMBOL dargs EQ barOpt dcons([(DDatatype (SYMBOL, dargs, dcons), s (DATATYPEleft, dconsright))])
|
adamc@191
|
380 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
|
adamc@191
|
381 (case dargs of
|
adamc@325
|
382 [] => [(DDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))]
|
adamc@191
|
383 | _ => raise Fail "Arguments specified for imported datatype")
|
adamc@325
|
384 | VAL vali ([(DVal vali, s (VALleft, valiright))])
|
adamc@325
|
385 | VAL REC valis ([(DValRec valis, s (VALleft, valisright))])
|
adamc@325
|
386 | FUN valis ([(DValRec valis, s (FUNleft, valisright))])
|
adamc@1
|
387
|
adamc@325
|
388 | SIGNATURE CSYMBOL EQ sgn ([(DSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))])
|
adamc@325
|
389 | STRUCTURE CSYMBOL EQ str ([(DStr (CSYMBOL, NONE, str), s (STRUCTUREleft, strright))])
|
adamc@325
|
390 | STRUCTURE CSYMBOL COLON sgn EQ str ([(DStr (CSYMBOL, SOME sgn, str), s (STRUCTUREleft, strright))])
|
adamc@42
|
391 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN EQ str
|
adamc@325
|
392 ([(DStr (CSYMBOL1, NONE,
|
adamc@325
|
393 (StrFun (CSYMBOL2, sgn1, NONE, str), s (FUNCTORleft, strright))),
|
adamc@325
|
394 s (FUNCTORleft, strright))])
|
adamc@42
|
395 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn EQ str
|
adamc@325
|
396 ([(DStr (CSYMBOL1, NONE,
|
adamc@325
|
397 (StrFun (CSYMBOL2, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))),
|
adamc@325
|
398 s (FUNCTORleft, strright))])
|
adamc@325
|
399 | EXTERN STRUCTURE CSYMBOL COLON sgn ([(DFfiStr (CSYMBOL, sgn), s (EXTERNleft, sgnright))])
|
adamc@61
|
400 | OPEN mpath (case mpath of
|
adamc@61
|
401 [] => raise Fail "Impossible mpath parse [1]"
|
adamc@325
|
402 | m :: ms => [(DOpen (m, ms), s (OPENleft, mpathright))])
|
adamc@325
|
403 | OPEN mpath LPAREN str RPAREN (let
|
adamc@325
|
404 val loc = s (OPENleft, RPARENright)
|
adamc@325
|
405
|
adamc@325
|
406 val m = case mpath of
|
adamc@325
|
407 [] => raise Fail "Impossible mpath parse [4]"
|
adamc@325
|
408 | m :: ms =>
|
adamc@325
|
409 foldl (fn (m, str) => (StrProj (str, m), loc))
|
adamc@325
|
410 (StrVar m, loc) ms
|
adamc@325
|
411 in
|
adamc@325
|
412 [(DStr ("anon", NONE, (StrApp (m, str), loc)), loc),
|
adamc@325
|
413 (DOpen ("anon", []), loc)]
|
adamc@325
|
414 end)
|
adamc@88
|
415 | OPEN CONSTRAINTS mpath (case mpath of
|
adamc@88
|
416 [] => raise Fail "Impossible mpath parse [3]"
|
adamc@325
|
417 | m :: ms => [(DOpenConstraints (m, ms), s (OPENleft, mpathright))])
|
adamc@325
|
418 | CONSTRAINT cterm TWIDDLE cterm ([(DConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))])
|
adamc@325
|
419 | EXPORT spath ([(DExport spath, s (EXPORTleft, spathright))])
|
adamc@325
|
420 | TABLE SYMBOL COLON cexp ([(DTable (SYMBOL, entable cexp), s (TABLEleft, cexpright))])
|
adamc@338
|
421 | SEQUENCE SYMBOL ([(DSequence SYMBOL, s (SEQUENCEleft, SYMBOLright))])
|
adamc@325
|
422 | CLASS SYMBOL EQ cexp ([(DClass (SYMBOL, cexp), s (CLASSleft, cexpright))])
|
adamc@211
|
423 | CLASS SYMBOL SYMBOL EQ cexp (let
|
adamc@211
|
424 val loc = s (CLASSleft, cexpright)
|
adamc@211
|
425 val k = (KType, loc)
|
adamc@211
|
426 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
|
adamc@211
|
427 in
|
adamc@325
|
428 [(DClass (SYMBOL1, c), s (CLASSleft, cexpright))]
|
adamc@211
|
429 end)
|
adamc@459
|
430 | COOKIE SYMBOL COLON cexp ([(DCookie (SYMBOL, cexp), s (COOKIEleft, cexpright))])
|
adamc@30
|
431
|
adamc@240
|
432 kopt : (NONE)
|
adamc@240
|
433 | DCOLON kind (SOME kind)
|
adamc@240
|
434
|
adamc@191
|
435 dargs : ([])
|
adamc@191
|
436 | SYMBOL dargs (SYMBOL :: dargs)
|
adamc@191
|
437
|
adamc@156
|
438 barOpt : ()
|
adamc@156
|
439 | BAR ()
|
adamc@156
|
440
|
adamc@156
|
441 dcons : dcon ([dcon])
|
adamc@156
|
442 | dcon BAR dcons (dcon :: dcons)
|
adamc@156
|
443
|
adamc@156
|
444 dcon : CSYMBOL (CSYMBOL, NONE)
|
adamc@156
|
445 | CSYMBOL OF cexp (CSYMBOL, SOME cexp)
|
adamc@156
|
446
|
adamc@242
|
447 vali : SYMBOL eargl2 copt EQ eexp (let
|
adamc@242
|
448 val loc = s (SYMBOLleft, eexpright)
|
adamc@242
|
449 val t = Option.getOpt (copt, (CWild (KType, loc), loc))
|
adamc@242
|
450
|
adamc@242
|
451 val (e, t) = eargl2 (eexp, t)
|
adamc@242
|
452 in
|
adamc@242
|
453 (SYMBOL, SOME t, e)
|
adamc@242
|
454 end)
|
adamc@242
|
455
|
adamc@242
|
456 copt : (NONE)
|
adamc@242
|
457 | COLON cexp (SOME cexp)
|
adamc@123
|
458
|
adamc@123
|
459 valis : vali ([vali])
|
adamc@123
|
460 | vali AND valis (vali :: valis)
|
adamc@123
|
461
|
adamc@42
|
462 sgn : sgntm (sgntm)
|
adamc@40
|
463 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
|
adamc@40
|
464 (SgnFun (CSYMBOL, sgn1, sgn2), s (FUNCTORleft, sgn2right))
|
adamc@30
|
465
|
adamc@42
|
466 sgntm : SIG sgis END (SgnConst sgis, s (SIGleft, ENDright))
|
adamc@59
|
467 | mpath (case mpath of
|
adamc@61
|
468 [] => raise Fail "Impossible mpath parse [2]"
|
adamc@59
|
469 | [x] => SgnVar x
|
adamc@59
|
470 | m :: ms => SgnProj (m,
|
adamc@59
|
471 List.take (ms, length ms - 1),
|
adamc@59
|
472 List.nth (ms, length ms - 1)),
|
adamc@59
|
473 s (mpathleft, mpathright))
|
adamc@42
|
474 | sgntm WHERE CON SYMBOL EQ cexp (SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
|
adamc@42
|
475 | sgntm WHERE LTYPE SYMBOL EQ cexp(SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
|
adamc@42
|
476 | LPAREN sgn RPAREN (sgn)
|
adamc@42
|
477
|
adamc@30
|
478 sgi : CON SYMBOL DCOLON kind (SgiConAbs (SYMBOL, kind), s (CONleft, kindright))
|
adamc@30
|
479 | LTYPE SYMBOL (SgiConAbs (SYMBOL, (KType, s (LTYPEleft, SYMBOLright))),
|
adamc@30
|
480 s (LTYPEleft, SYMBOLright))
|
adamc@30
|
481 | CON SYMBOL EQ cexp (SgiCon (SYMBOL, NONE, cexp), s (CONleft, cexpright))
|
adamc@30
|
482 | CON SYMBOL DCOLON kind EQ cexp (SgiCon (SYMBOL, SOME kind, cexp), s (CONleft, cexpright))
|
adamc@30
|
483 | LTYPE SYMBOL EQ cexp (SgiCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
|
adamc@30
|
484 s (LTYPEleft, cexpright))
|
adamc@191
|
485 | DATATYPE SYMBOL dargs EQ barOpt dcons(SgiDatatype (SYMBOL, dargs, dcons), s (DATATYPEleft, dconsright))
|
adamc@191
|
486 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
|
adamc@191
|
487 (case dargs of
|
adamc@191
|
488 [] => (SgiDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
|
adamc@191
|
489 | _ => raise Fail "Arguments specified for imported datatype")
|
adamc@30
|
490 | VAL SYMBOL COLON cexp (SgiVal (SYMBOL, cexp), s (VALleft, cexpright))
|
adamc@30
|
491
|
adamc@30
|
492 | STRUCTURE CSYMBOL COLON sgn (SgiStr (CSYMBOL, sgn), s (STRUCTUREleft, sgnright))
|
adamc@59
|
493 | SIGNATURE CSYMBOL EQ sgn (SgiSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))
|
adamc@42
|
494 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
|
adamc@42
|
495 (SgiStr (CSYMBOL1,
|
adamc@42
|
496 (SgnFun (CSYMBOL2, sgn1, sgn2), s (FUNCTORleft, sgn2right))),
|
adamc@42
|
497 s (FUNCTORleft, sgn2right))
|
adamc@58
|
498 | INCLUDE sgn (SgiInclude sgn, s (INCLUDEleft, sgnright))
|
adamc@88
|
499 | CONSTRAINT cterm TWIDDLE cterm (SgiConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))
|
adamc@460
|
500 | TABLE SYMBOL COLON cexp (let
|
adamc@460
|
501 val loc = s (TABLEleft, cexpright)
|
adamc@460
|
502 val t = (CApp ((CVar (["Basis"], "sql_table"), loc),
|
adamc@460
|
503 entable cexp), loc)
|
adamc@460
|
504 in
|
adamc@460
|
505 (SgiVal (SYMBOL, t), loc)
|
adamc@460
|
506 end)
|
adamc@460
|
507 | SEQUENCE SYMBOL (let
|
adamc@460
|
508 val loc = s (SEQUENCEleft, SYMBOLright)
|
adamc@460
|
509 val t = (CVar (["Basis"], "sql_sequence"), loc)
|
adamc@460
|
510 in
|
adamc@460
|
511 (SgiVal (SYMBOL, t), loc)
|
adamc@460
|
512 end)
|
adamc@211
|
513 | CLASS SYMBOL (SgiClassAbs SYMBOL, s (CLASSleft, SYMBOLright))
|
adamc@211
|
514 | CLASS SYMBOL EQ cexp (SgiClass (SYMBOL, cexp), s (CLASSleft, cexpright))
|
adamc@211
|
515 | CLASS SYMBOL SYMBOL EQ cexp (let
|
adamc@211
|
516 val loc = s (CLASSleft, cexpright)
|
adamc@211
|
517 val k = (KType, loc)
|
adamc@211
|
518 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
|
adamc@211
|
519 in
|
adamc@211
|
520 (SgiClass (SYMBOL1, c), s (CLASSleft, cexpright))
|
adamc@211
|
521 end)
|
adamc@460
|
522 | COOKIE SYMBOL COLON cexp (let
|
adamc@460
|
523 val loc = s (COOKIEleft, cexpright)
|
adamc@460
|
524 val t = (CApp ((CVar (["Basis"], "http_cookie"), loc),
|
adamc@460
|
525 entable cexp), loc)
|
adamc@460
|
526 in
|
adamc@460
|
527 (SgiVal (SYMBOL, t), loc)
|
adamc@460
|
528 end)
|
adamc@30
|
529
|
adamc@30
|
530 sgis : ([])
|
adamc@30
|
531 | sgi sgis (sgi :: sgis)
|
adamc@30
|
532
|
adamc@30
|
533 str : STRUCT decls END (StrConst decls, s (STRUCTleft, ENDright))
|
adamc@34
|
534 | spath (spath)
|
adamc@40
|
535 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN DARROW str
|
adamc@40
|
536 (StrFun (CSYMBOL, sgn, NONE, str), s (FUNCTORleft, strright))
|
adamc@40
|
537 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn DARROW str
|
adamc@40
|
538 (StrFun (CSYMBOL, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))
|
adamc@44
|
539 | spath LPAREN str RPAREN (StrApp (spath, str), s (spathleft, RPARENright))
|
adamc@34
|
540
|
adamc@34
|
541 spath : CSYMBOL (StrVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@34
|
542 | spath DOT CSYMBOL (StrProj (spath, CSYMBOL), s (spathleft, CSYMBOLright))
|
adamc@30
|
543
|
adamc@1
|
544 kind : TYPE (KType, s (TYPEleft, TYPEright))
|
adamc@1
|
545 | NAME (KName, s (NAMEleft, NAMEright))
|
adamc@1
|
546 | LBRACE kind RBRACE (KRecord kind, s (LBRACEleft, RBRACEright))
|
adamc@1
|
547 | kind ARROW kind (KArrow (kind1, kind2), s (kind1left, kind2right))
|
adamc@1
|
548 | LPAREN kind RPAREN (#1 kind, s (LPARENleft, RPARENright))
|
adamc@82
|
549 | KUNIT (KUnit, s (KUNITleft, KUNITright))
|
adamc@18
|
550 | UNDERUNDER (KWild, s (UNDERUNDERleft, UNDERUNDERright))
|
adamc@207
|
551 | LPAREN ktuple RPAREN (KTuple ktuple, s (LPARENleft, RPARENright))
|
adamc@207
|
552
|
adamc@207
|
553 ktuple : kind STAR kind ([kind1, kind2])
|
adamc@207
|
554 | kind STAR ktuple (kind :: ktuple)
|
adamc@1
|
555
|
adamc@1
|
556 capps : cterm (cterm)
|
adamc@1
|
557 | capps cterm (CApp (capps, cterm), s (cappsleft, ctermright))
|
adamc@1
|
558
|
adamc@1
|
559 cexp : capps (capps)
|
adamc@1
|
560 | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right))
|
adamc@15
|
561 | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright))
|
adamc@1
|
562
|
adamc@1
|
563 | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right))
|
adamc@1
|
564
|
adamc@239
|
565 | FN cargs DARROW cexp (#1 (cargs (cexp, (KWild, s (FNleft, cexpright)))))
|
adamc@1
|
566
|
adamc@8
|
567 | LPAREN cexp RPAREN DCOLON kind (CAnnot (cexp, kind), s (LPARENleft, kindright))
|
adamc@6
|
568
|
adamc@18
|
569 | UNDER DCOLON kind (CWild kind, s (UNDERleft, UNDERright))
|
adamc@195
|
570 | ctuple (let
|
adamc@195
|
571 val loc = s (ctupleleft, ctupleright)
|
adamc@195
|
572 in
|
adamc@195
|
573 (TRecord (CRecord (ListUtil.mapi (fn (i, c) =>
|
adamc@195
|
574 ((CName (Int.toString (i + 1)), loc),
|
adamc@195
|
575 c)) ctuple),
|
adamc@195
|
576 loc), loc)
|
adamc@195
|
577 end)
|
adamc@18
|
578
|
adamc@1
|
579 kcolon : DCOLON (Explicit)
|
adamc@1
|
580 | TCOLON (Implicit)
|
adamc@1
|
581
|
adamc@239
|
582 cargs : carg (carg)
|
adamc@239
|
583 | cargl (cargl)
|
adamc@239
|
584
|
adamc@239
|
585 cargl : cargp cargp (cargp1 o cargp2)
|
adamc@239
|
586 | cargp cargl (cargp o cargl)
|
adamc@239
|
587
|
adamc@240
|
588 cargl2 : (fn x => x)
|
adamc@240
|
589 | cargp cargl2 (cargp o cargl2)
|
adamc@240
|
590
|
adamc@241
|
591 carg : SYMBOL DCOLON kind (fn (c, k) =>
|
adamc@239
|
592 let
|
adamc@239
|
593 val loc = s (SYMBOLleft, kindright)
|
adamc@239
|
594 in
|
adamc@239
|
595 ((CAbs (SYMBOL, SOME kind, c), loc),
|
adamc@239
|
596 (KArrow (kind, k), loc))
|
adamc@239
|
597 end)
|
adamc@329
|
598 | UNDER DCOLON kind (fn (c, k) =>
|
adamc@329
|
599 let
|
adamc@329
|
600 val loc = s (UNDERleft, kindright)
|
adamc@329
|
601 in
|
adamc@329
|
602 ((CAbs ("_", SOME kind, c), loc),
|
adamc@329
|
603 (KArrow (kind, k), loc))
|
adamc@329
|
604 end)
|
adamc@241
|
605 | cargp (cargp)
|
adamc@239
|
606
|
adamc@239
|
607 cargp : SYMBOL (fn (c, k) =>
|
adamc@239
|
608 let
|
adamc@239
|
609 val loc = s (SYMBOLleft, SYMBOLright)
|
adamc@239
|
610 in
|
adamc@239
|
611 ((CAbs (SYMBOL, NONE, c), loc),
|
adamc@239
|
612 (KArrow ((KWild, loc), k), loc))
|
adamc@239
|
613 end)
|
adamc@329
|
614 | UNDER (fn (c, k) =>
|
adamc@329
|
615 let
|
adamc@329
|
616 val loc = s (UNDERleft, UNDERright)
|
adamc@329
|
617 in
|
adamc@329
|
618 ((CAbs ("_", NONE, c), loc),
|
adamc@329
|
619 (KArrow ((KWild, loc), k), loc))
|
adamc@329
|
620 end)
|
adamc@239
|
621 | LPAREN SYMBOL DCOLON kind RPAREN (fn (c, k) =>
|
adamc@239
|
622 let
|
adamc@239
|
623 val loc = s (LPARENleft, RPARENright)
|
adamc@239
|
624 in
|
adamc@239
|
625 ((CAbs (SYMBOL, SOME kind, c), loc),
|
adamc@239
|
626 (KArrow (kind, k), loc))
|
adamc@239
|
627 end)
|
adamc@478
|
628 | LBRACK cexp TWIDDLE cexp RBRACK (fn (c, k) =>
|
adamc@354
|
629 let
|
adamc@354
|
630 val loc = s (LBRACKleft, RBRACKright)
|
adamc@354
|
631 in
|
adamc@478
|
632 ((CDisjoint (cexp1, cexp2, c), loc),
|
adamc@354
|
633 k)
|
adamc@354
|
634 end)
|
adamc@239
|
635
|
adamc@34
|
636 path : SYMBOL ([], SYMBOL)
|
adamc@34
|
637 | CSYMBOL DOT path (let val (ms, x) = path in (CSYMBOL :: ms, x) end)
|
adamc@34
|
638
|
adamc@156
|
639 cpath : CSYMBOL ([], CSYMBOL)
|
adamc@156
|
640 | CSYMBOL DOT cpath (let val (ms, x) = cpath in (CSYMBOL :: ms, x) end)
|
adamc@156
|
641
|
adamc@59
|
642 mpath : CSYMBOL ([CSYMBOL])
|
adamc@59
|
643 | CSYMBOL DOT mpath (CSYMBOL :: mpath)
|
adamc@59
|
644
|
adamc@1
|
645 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright))
|
adamc@1
|
646 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright))
|
adamc@83
|
647 | LBRACK rconn RBRACK (CRecord rconn, s (LBRACKleft, RBRACKright))
|
adamc@1
|
648 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)),
|
adamc@1
|
649 s (LBRACEleft, RBRACEright))
|
adamc@1
|
650 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright))
|
adamc@1
|
651 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright))
|
adamc@195
|
652 | HASH INT (CName (Int64.toString INT), s (HASHleft, INTright))
|
adamc@1
|
653
|
adamc@34
|
654 | path (CVar path, s (pathleft, pathright))
|
adamc@207
|
655 | path DOT INT (CProj ((CVar path, s (pathleft, pathright)), Int64.toInt INT),
|
adamc@207
|
656 s (pathleft, INTright))
|
adamc@18
|
657 | UNDER (CWild (KWild, s (UNDERleft, UNDERright)), s (UNDERleft, UNDERright))
|
adamc@67
|
658 | FOLD (CFold, s (FOLDleft, FOLDright))
|
adamc@82
|
659 | UNIT (CUnit, s (UNITleft, UNITright))
|
adamc@207
|
660 | LPAREN ctuplev RPAREN (CTuple ctuplev, s (LPARENleft, RPARENright))
|
adamc@207
|
661
|
adamc@207
|
662 ctuplev: cexp COMMA cexp ([cexp1, cexp2])
|
adamc@207
|
663 | cexp COMMA ctuplev (cexp :: ctuplev)
|
adamc@1
|
664
|
adamc@196
|
665 ctuple : capps STAR capps ([capps1, capps2])
|
adamc@196
|
666 | capps STAR ctuple (capps :: ctuple)
|
adamc@195
|
667
|
adamc@1
|
668 rcon : ([])
|
adamc@1
|
669 | ident EQ cexp ([(ident, cexp)])
|
adamc@1
|
670 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon)
|
adamc@1
|
671
|
adamc@83
|
672 rconn : ident ([(ident, (CUnit, s (identleft, identright)))])
|
adamc@83
|
673 | ident COMMA rconn ((ident, (CUnit, s (identleft, identright))) :: rconn)
|
adamc@83
|
674
|
adamc@1
|
675 rcone : ([])
|
adamc@1
|
676 | ident COLON cexp ([(ident, cexp)])
|
adamc@1
|
677 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone)
|
adamc@1
|
678
|
adamc@1
|
679 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@195
|
680 | INT (CName (Int64.toString INT), s (INTleft, INTright))
|
adamc@200
|
681 | SYMBOL (CVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
|
adamc@8
|
682
|
adamc@8
|
683 eapps : eterm (eterm)
|
adamc@8
|
684 | eapps eterm (EApp (eapps, eterm), s (eappsleft, etermright))
|
adamc@8
|
685 | eapps LBRACK cexp RBRACK (ECApp (eapps, cexp), s (eappsleft, RBRACKright))
|
adamc@8
|
686
|
adamc@8
|
687 eexp : eapps (eapps)
|
adamc@241
|
688 | FN eargs DARROW eexp (let
|
adamc@93
|
689 val loc = s (FNleft, eexpright)
|
adamc@93
|
690 in
|
adamc@241
|
691 #1 (eargs (eexp, (CWild (KType, loc), loc)))
|
adamc@93
|
692 end)
|
adamc@196
|
693 | eexp COLON cexp (EAnnot (eexp, cexp), s (eexpleft, cexpright))
|
adamc@149
|
694 | eexp MINUSMINUS cexp (ECut (eexp, cexp), s (eexpleft, cexpright))
|
adamc@493
|
695 | eexp MINUSMINUSMINUS cexp (ECutMulti (eexp, cexp), s (eexpleft, cexpright))
|
adamc@170
|
696 | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
|
adamc@190
|
697 | IF eexp THEN eexp ELSE eexp (let
|
adamc@190
|
698 val loc = s (IFleft, eexp3right)
|
adamc@190
|
699 in
|
adamc@190
|
700 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc), eexp2),
|
adamc@190
|
701 ((PCon (["Basis"], "False", NONE), loc), eexp3)]), loc)
|
adamc@190
|
702 end)
|
adamc@434
|
703 | bind SEMI eexp (let
|
adamc@434
|
704 val loc = s (bindleft, eexpright)
|
adamc@434
|
705 val (v, to, e1) = bind
|
adamc@403
|
706 val e = (EVar (["Basis"], "bind", Infer), loc)
|
adamc@434
|
707 val e = (EApp (e, e1), loc)
|
adamc@243
|
708 in
|
adamc@434
|
709 (EApp (e, (EAbs (v, to, eexp), loc)), loc)
|
adamc@299
|
710 end)
|
adamc@256
|
711 | eexp EQ eexp (native_op ("eq", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@257
|
712 | eexp NE eexp (native_op ("ne", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@389
|
713 | MINUS eterm (native_unop ("neg", eterm, s (MINUSleft, etermright)))
|
adamc@389
|
714 | eexp PLUS eexp (native_op ("plus", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@389
|
715 | eexp MINUS eexp (native_op ("minus", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@389
|
716 | eterm STAR eexp (native_op ("times", eterm, eexp, s (etermleft, eexpright)))
|
adamc@389
|
717 | eexp DIVIDE eexp (native_op ("div", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@389
|
718 | eexp MOD eexp (native_op ("mod", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
719
|
adamc@391
|
720 | eexp LT eexp (native_op ("lt", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
721 | eexp LE eexp (native_op ("le", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
722 | eexp GT eexp (native_op ("gt", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
723 | eexp GE eexp (native_op ("ge", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
724
|
adamc@445
|
725 | eexp PLUSPLUS eexp (EConcat (eexp1, eexp2), s (eexp1left, eexp2right))
|
adamc@8
|
726
|
adamc@434
|
727 bind : SYMBOL LARROW eapps (SYMBOL, NONE, eapps)
|
adamc@434
|
728 | UNIT LARROW eapps (let
|
adamc@434
|
729 val loc = s (UNITleft, eappsright)
|
adamc@434
|
730 in
|
adamc@434
|
731 ("_", SOME (TRecord (CRecord [], loc), loc), eapps)
|
adamc@434
|
732 end)
|
adamc@434
|
733 | eapps (let
|
adamc@434
|
734 val loc = s (eappsleft, eappsright)
|
adamc@434
|
735 in
|
adamc@434
|
736 ("_", SOME (TRecord (CRecord [], loc), loc), eapps)
|
adamc@434
|
737 end)
|
adamc@434
|
738
|
adamc@241
|
739 eargs : earg (earg)
|
adamc@241
|
740 | eargl (eargl)
|
adamc@241
|
741
|
adamc@241
|
742 eargl : eargp eargp (eargp1 o eargp2)
|
adamc@241
|
743 | eargp eargl (eargp o eargl)
|
adamc@241
|
744
|
adamc@242
|
745 eargl2 : (fn x => x)
|
adamc@242
|
746 | eargp eargl2 (eargp o eargl2)
|
adamc@242
|
747
|
adamc@241
|
748 earg : SYMBOL kcolon kind (fn (e, t) =>
|
adamc@241
|
749 let
|
adamc@241
|
750 val loc = s (SYMBOLleft, kindright)
|
adamc@241
|
751 in
|
adamc@241
|
752 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
|
adamc@241
|
753 (TCFun (kcolon, SYMBOL, kind, t), loc))
|
adamc@241
|
754 end)
|
adamc@241
|
755 | SYMBOL COLON cexp (fn (e, t) =>
|
adamc@241
|
756 let
|
adamc@241
|
757 val loc = s (SYMBOLleft, cexpright)
|
adamc@241
|
758 in
|
adamc@241
|
759 ((EAbs (SYMBOL, SOME cexp, e), loc),
|
adamc@241
|
760 (TFun (cexp, t), loc))
|
adamc@241
|
761 end)
|
adamc@241
|
762 | UNDER COLON cexp (fn (e, t) =>
|
adamc@241
|
763 let
|
adamc@241
|
764 val loc = s (UNDERleft, cexpright)
|
adamc@241
|
765 in
|
adamc@241
|
766 ((EAbs ("_", SOME cexp, e), loc),
|
adamc@241
|
767 (TFun (cexp, t), loc))
|
adamc@241
|
768 end)
|
adamc@241
|
769 | eargp (eargp)
|
adamc@241
|
770
|
adamc@241
|
771 eargp : SYMBOL (fn (e, t) =>
|
adamc@241
|
772 let
|
adamc@241
|
773 val loc = s (SYMBOLleft, SYMBOLright)
|
adamc@241
|
774 in
|
adamc@241
|
775 ((EAbs (SYMBOL, NONE, e), loc),
|
adamc@241
|
776 (TFun ((CWild (KType, loc), loc), t), loc))
|
adamc@241
|
777 end)
|
adamc@241
|
778 | UNIT (fn (e, t) =>
|
adamc@241
|
779 let
|
adamc@241
|
780 val loc = s (UNITleft, UNITright)
|
adamc@241
|
781 val t' = (TRecord (CRecord [], loc), loc)
|
adamc@241
|
782 in
|
adamc@241
|
783 ((EAbs ("_", SOME t', e), loc),
|
adamc@241
|
784 (TFun (t', t), loc))
|
adamc@241
|
785 end)
|
adamc@241
|
786 | UNDER (fn (e, t) =>
|
adamc@241
|
787 let
|
adamc@241
|
788 val loc = s (UNDERleft, UNDERright)
|
adamc@241
|
789 in
|
adamc@241
|
790 ((EAbs ("_", NONE, e), loc),
|
adamc@241
|
791 (TFun ((CWild (KType, loc), loc), t), loc))
|
adamc@241
|
792 end)
|
adamc@241
|
793 | LPAREN SYMBOL kcolon kind RPAREN(fn (e, t) =>
|
adamc@241
|
794 let
|
adamc@241
|
795 val loc = s (LPARENleft, RPARENright)
|
adamc@241
|
796 in
|
adamc@241
|
797 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
|
adamc@241
|
798 (TCFun (kcolon, SYMBOL, kind, t), loc))
|
adamc@241
|
799 end)
|
adamc@241
|
800 | LPAREN SYMBOL COLON cexp RPAREN (fn (e, t) =>
|
adamc@241
|
801 let
|
adamc@241
|
802 val loc = s (LPARENleft, RPARENright)
|
adamc@241
|
803 in
|
adamc@241
|
804 ((EAbs (SYMBOL, SOME cexp, e), loc),
|
adamc@241
|
805 (TFun (cexp, t), loc))
|
adamc@241
|
806 end)
|
adamc@241
|
807 | LPAREN UNDER COLON cexp RPAREN (fn (e, t) =>
|
adamc@241
|
808 let
|
adamc@241
|
809 val loc = s (LPARENleft, RPARENright)
|
adamc@241
|
810 in
|
adamc@241
|
811 ((EAbs ("_", SOME cexp, e), loc),
|
adamc@241
|
812 (TFun (cexp, t), loc))
|
adamc@241
|
813 end)
|
adamc@478
|
814 | LPAREN cexp TWIDDLE cexp RPAREN (fn (e, t) =>
|
adamc@354
|
815 let
|
adamc@354
|
816 val loc = s (LPARENleft, RPARENright)
|
adamc@354
|
817 in
|
adamc@478
|
818 ((EDisjoint (cexp1, cexp2, e), loc),
|
adamc@478
|
819 (CDisjoint (cexp1, cexp2, t), loc))
|
adamc@354
|
820 end)
|
adamc@478
|
821 | LBRACK cexp TWIDDLE cexp RBRACK(fn (e, t) =>
|
adamc@356
|
822 let
|
adamc@356
|
823 val loc = s (LBRACKleft, RBRACKright)
|
adamc@356
|
824 in
|
adamc@478
|
825 ((EDisjoint (cexp1, cexp2, e), loc),
|
adamc@478
|
826 (CDisjoint (cexp1, cexp2, t), loc))
|
adamc@356
|
827 end)
|
adamc@241
|
828
|
adamc@8
|
829 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
|
adamc@195
|
830 | LPAREN etuple RPAREN (let
|
adamc@195
|
831 val loc = s (LPARENleft, RPARENright)
|
adamc@195
|
832 in
|
adamc@195
|
833 (ERecord (ListUtil.mapi (fn (i, e) =>
|
adamc@195
|
834 ((CName (Int.toString (i + 1)), loc),
|
adamc@195
|
835 e)) etuple), loc)
|
adamc@195
|
836 end)
|
adamc@8
|
837
|
adamc@403
|
838 | path (EVar (#1 path, #2 path, Infer), s (pathleft, pathright))
|
adamc@403
|
839 | cpath (EVar (#1 cpath, #2 cpath, Infer), s (cpathleft, cpathright))
|
adamc@403
|
840 | AT path (EVar (#1 path, #2 path, TypesOnly), s (ATleft, pathright))
|
adamc@403
|
841 | AT AT path (EVar (#1 path, #2 path, DontInfer), s (AT1left, pathright))
|
adamc@403
|
842 | AT cpath (EVar (#1 cpath, #2 cpath, TypesOnly), s (ATleft, cpathright))
|
adamc@403
|
843 | AT AT cpath (EVar (#1 cpath, #2 cpath, DontInfer), s (AT1left, cpathright))
|
adamc@12
|
844 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
|
adamc@110
|
845 | UNIT (ERecord [], s (UNITleft, UNITright))
|
adamc@12
|
846
|
adamc@14
|
847 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@14
|
848 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
|
adamc@14
|
849 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@14
|
850
|
adamc@200
|
851 | path DOT idents (let
|
adamc@200
|
852 val loc = s (pathleft, identsright)
|
adamc@200
|
853 in
|
adamc@200
|
854 foldl (fn (ident, e) =>
|
adamc@200
|
855 (EField (e, ident), loc))
|
adamc@403
|
856 (EVar (#1 path, #2 path, Infer), s (pathleft, pathright)) idents
|
adamc@403
|
857 end)
|
adamc@403
|
858 | AT path DOT idents (let
|
adamc@403
|
859 val loc = s (ATleft, identsright)
|
adamc@403
|
860 in
|
adamc@403
|
861 foldl (fn (ident, e) =>
|
adamc@403
|
862 (EField (e, ident), loc))
|
adamc@403
|
863 (EVar (#1 path, #2 path, TypesOnly), s (pathleft, pathright)) idents
|
adamc@403
|
864 end)
|
adamc@403
|
865 | AT AT path DOT idents (let
|
adamc@403
|
866 val loc = s (AT1left, identsright)
|
adamc@403
|
867 in
|
adamc@403
|
868 foldl (fn (ident, e) =>
|
adamc@403
|
869 (EField (e, ident), loc))
|
adamc@403
|
870 (EVar (#1 path, #2 path, DontInfer), s (pathleft, pathright)) idents
|
adamc@200
|
871 end)
|
adamc@71
|
872 | FOLD (EFold, s (FOLDleft, FOLDright))
|
adamc@71
|
873
|
adamc@360
|
874 | XML_BEGIN xml XML_END (let
|
adamc@360
|
875 val loc = s (XML_BEGINleft, XML_ENDright)
|
adamc@360
|
876 in
|
adamc@360
|
877 if XML_BEGIN = "xml" then
|
adamc@360
|
878 ()
|
adamc@360
|
879 else
|
adamc@360
|
880 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
|
adamc@360
|
881 xml
|
adamc@360
|
882 end)
|
adamc@360
|
883 | XML_BEGIN XML_END (let
|
adamc@360
|
884 val loc = s (XML_BEGINleft, XML_ENDright)
|
adamc@360
|
885 in
|
adamc@360
|
886 if XML_BEGIN = "xml" then
|
adamc@360
|
887 ()
|
adamc@360
|
888 else
|
adamc@360
|
889 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
|
adamc@403
|
890 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
|
adamc@360
|
891 (EPrim (Prim.String ""), loc)),
|
adamc@360
|
892 loc)
|
adamc@360
|
893 end)
|
adamc@360
|
894 | XML_BEGIN_END (let
|
adamc@360
|
895 val loc = s (XML_BEGIN_ENDleft, XML_BEGIN_ENDright)
|
adamc@360
|
896 in
|
adamc@360
|
897 if XML_BEGIN_END = "xml" then
|
adamc@360
|
898 ()
|
adamc@360
|
899 else
|
adamc@360
|
900 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
|
adamc@403
|
901 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
|
adamc@360
|
902 (EPrim (Prim.String ""), loc)),
|
adamc@360
|
903 loc)
|
adamc@360
|
904 end)
|
adamc@302
|
905
|
adamc@204
|
906 | LPAREN query RPAREN (query)
|
adamc@300
|
907 | LPAREN CWHERE sqlexp RPAREN (sqlexp)
|
adamc@339
|
908 | LPAREN SQL sqlexp RPAREN (sqlexp)
|
adamc@302
|
909
|
adamc@302
|
910 | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN
|
adamc@302
|
911 (let
|
adamc@302
|
912 val loc = s (LPAREN1left, RPAREN3right)
|
adamc@302
|
913
|
adamc@403
|
914 val e = (EVar (["Basis"], "insert", Infer), loc)
|
adamc@302
|
915 val e = (EApp (e, texp), loc)
|
adamc@302
|
916 in
|
adamc@302
|
917 if length fields <> length sqlexps then
|
adamc@302
|
918 ErrorMsg.errorAt loc "Length mismatch in INSERT field specification"
|
adamc@302
|
919 else
|
adamc@302
|
920 ();
|
adamc@302
|
921 (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
|
adamc@302
|
922 end)
|
adamc@310
|
923 | LPAREN enterDml UPDATE texp SET fsets CWHERE sqlexp leaveDml RPAREN
|
adamc@303
|
924 (let
|
adamc@303
|
925 val loc = s (LPARENleft, RPARENright)
|
adamc@303
|
926
|
adamc@403
|
927 val e = (EVar (["Basis"], "update", Infer), loc)
|
adamc@342
|
928 val e = (ECApp (e, (CWild (KRecord (KType, loc), loc), loc)), loc)
|
adamc@306
|
929 val e = (EApp (e, (ERecord fsets, loc)), loc)
|
adamc@305
|
930 val e = (EApp (e, texp), loc)
|
adamc@303
|
931 in
|
adamc@303
|
932 (EApp (e, sqlexp), loc)
|
adamc@303
|
933 end)
|
adamc@310
|
934 | LPAREN enterDml DELETE FROM texp CWHERE sqlexp leaveDml RPAREN
|
adamc@304
|
935 (let
|
adamc@304
|
936 val loc = s (LPARENleft, RPARENright)
|
adamc@304
|
937
|
adamc@403
|
938 val e = (EVar (["Basis"], "delete", Infer), loc)
|
adamc@304
|
939 val e = (EApp (e, texp), loc)
|
adamc@304
|
940 in
|
adamc@304
|
941 (EApp (e, sqlexp), loc)
|
adamc@304
|
942 end)
|
adamc@302
|
943
|
adamc@211
|
944 | UNDER (EWild, s (UNDERleft, UNDERright))
|
adamc@91
|
945
|
adamc@446
|
946 | LET edecls IN eexp END (ELet (edecls, eexp), s (LETleft, ENDright))
|
adamc@446
|
947
|
adamc@446
|
948 edecls : ([])
|
adamc@446
|
949 | edecl edecls (edecl :: edecls)
|
adamc@446
|
950
|
adamc@446
|
951 edecl : VAL vali ((EDVal vali, s (VALleft, valiright)))
|
adamc@446
|
952 | VAL REC valis ((EDValRec valis, s (VALleft, valisright)))
|
adamc@446
|
953 | FUN valis ((EDValRec valis, s (FUNleft, valisright)))
|
adamc@446
|
954
|
adamc@310
|
955 enterDml : (inDml := true)
|
adamc@310
|
956 leaveDml : (inDml := false)
|
adamc@310
|
957
|
adamc@403
|
958 texp : SYMBOL (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
|
adamc@302
|
959 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
|
adamc@302
|
960
|
adamc@302
|
961 fields : fident ([fident])
|
adamc@302
|
962 | fident COMMA fields (fident :: fields)
|
adamc@302
|
963
|
adamc@302
|
964 sqlexps: sqlexp ([sqlexp])
|
adamc@302
|
965 | sqlexp COMMA sqlexps (sqlexp :: sqlexps)
|
adamc@302
|
966
|
adamc@303
|
967 fsets : fident EQ sqlexp ([(fident, sqlexp)])
|
adamc@303
|
968 | fident EQ sqlexp COMMA fsets ((fident, sqlexp) :: fsets)
|
adamc@303
|
969
|
adamc@200
|
970 idents : ident ([ident])
|
adamc@200
|
971 | ident DOT idents (ident :: idents)
|
adamc@200
|
972
|
adamc@195
|
973 etuple : eexp COMMA eexp ([eexp1, eexp2])
|
adamc@195
|
974 | eexp COMMA etuple (eexp :: etuple)
|
adamc@195
|
975
|
adamc@170
|
976 branch : pat DARROW eexp (pat, eexp)
|
adamc@170
|
977
|
adamc@170
|
978 branchs: ([])
|
adamc@170
|
979 | BAR branch branchs (branch :: branchs)
|
adamc@170
|
980
|
adamc@170
|
981 pat : pterm (pterm)
|
adamc@170
|
982 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
|
adamc@170
|
983
|
adamc@170
|
984 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
|
adamc@170
|
985 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
|
adamc@170
|
986 | UNDER (PWild, s (UNDERleft, UNDERright))
|
adamc@173
|
987 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@173
|
988 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@170
|
989 | LPAREN pat RPAREN (pat)
|
adamc@174
|
990 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
|
adamc@174
|
991 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
|
adamc@174
|
992 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
|
adamc@195
|
993 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
|
adamc@195
|
994 false),
|
adamc@195
|
995 s (LPARENleft, RPARENright))
|
adamc@174
|
996
|
adamc@175
|
997 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
|
adamc@243
|
998 | INT EQ pat ([(Int64.toString INT, pat)], false)
|
adamc@174
|
999 | DOTDOTDOT ([], true)
|
adamc@175
|
1000 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
|
adamc@243
|
1001 | INT EQ pat COMMA rpat ((Int64.toString INT, pat) :: #1 rpat, #2 rpat)
|
adamc@170
|
1002
|
adamc@195
|
1003 ptuple : pat COMMA pat ([pat1, pat2])
|
adamc@195
|
1004 | pat COMMA ptuple (pat :: ptuple)
|
adamc@195
|
1005
|
adamc@12
|
1006 rexp : ([])
|
adamc@12
|
1007 | ident EQ eexp ([(ident, eexp)])
|
adamc@12
|
1008 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
|
adamc@91
|
1009
|
adamc@141
|
1010 xml : xmlOne xml (let
|
adamc@141
|
1011 val pos = s (xmlOneleft, xmlright)
|
adamc@141
|
1012 in
|
adamc@141
|
1013 (EApp ((EApp (
|
adamc@403
|
1014 (EVar (["Basis"], "join", Infer), pos),
|
adamc@91
|
1015 xmlOne), pos),
|
adamc@141
|
1016 xml), pos)
|
adamc@141
|
1017 end)
|
adamc@141
|
1018 | xmlOne (xmlOne)
|
adamc@91
|
1019
|
adamc@403
|
1020 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata", Infer), s (NOTAGSleft, NOTAGSright)),
|
adamc@141
|
1021 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
|
adamc@141
|
1022 s (NOTAGSleft, NOTAGSright))
|
adamc@141
|
1023 | tag DIVIDE GT (let
|
adamc@141
|
1024 val pos = s (tagleft, GTright)
|
adamc@141
|
1025 in
|
adamc@141
|
1026 (EApp (#2 tag,
|
adamc@403
|
1027 (EApp ((EVar (["Basis"], "cdata", Infer), pos),
|
adamc@141
|
1028 (EPrim (Prim.String ""), pos)),
|
adamc@141
|
1029 pos)), pos)
|
adamc@141
|
1030 end)
|
adamc@141
|
1031
|
adamc@141
|
1032 | tag GT xml END_TAG (let
|
adamc@141
|
1033 val pos = s (tagleft, GTright)
|
adamc@325
|
1034 val et = tagIn END_TAG
|
adamc@141
|
1035 in
|
adamc@325
|
1036 if #1 tag = et then
|
adamc@361
|
1037 if et = "form" then
|
adamc@403
|
1038 (EApp ((EVar (["Basis"], "form", Infer), pos),
|
adamc@141
|
1039 xml), pos)
|
adamc@141
|
1040 else
|
adamc@141
|
1041 (EApp (#2 tag, xml), pos)
|
adamc@141
|
1042 else
|
adamc@325
|
1043 (if ErrorMsg.anyErrors () then
|
adamc@325
|
1044 ()
|
adamc@325
|
1045 else
|
adamc@325
|
1046 ErrorMsg.errorAt pos "Begin and end tags don't match.";
|
adamc@141
|
1047 (EFold, pos))
|
adamc@141
|
1048 end)
|
adamc@141
|
1049 | LBRACE eexp RBRACE (eexp)
|
adamc@391
|
1050 | LBRACE LBRACK eexp RBRACK RBRACE (let
|
adamc@391
|
1051 val loc = s (LBRACEleft, RBRACEright)
|
adamc@403
|
1052 val e = (EVar (["Top"], "txt", Infer), loc)
|
adamc@391
|
1053 in
|
adamc@391
|
1054 (EApp (e, eexp), loc)
|
adamc@391
|
1055 end)
|
adamc@92
|
1056
|
adamc@141
|
1057 tag : tagHead attrs (let
|
adamc@141
|
1058 val pos = s (tagHeadleft, attrsright)
|
adamc@141
|
1059 in
|
adamc@141
|
1060 (#1 tagHead,
|
adamc@403
|
1061 (EApp ((EApp ((EVar (["Basis"], "tag", Infer), pos),
|
adamc@141
|
1062 (ERecord attrs, pos)), pos),
|
adamc@141
|
1063 (EApp (#2 tagHead,
|
adamc@141
|
1064 (ERecord [], pos)), pos)),
|
adamc@141
|
1065 pos))
|
adamc@141
|
1066 end)
|
adamc@141
|
1067
|
adamc@141
|
1068 tagHead: BEGIN_TAG (let
|
adamc@325
|
1069 val bt = tagIn BEGIN_TAG
|
adamc@141
|
1070 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
|
adamc@141
|
1071 in
|
adamc@325
|
1072 (bt,
|
adamc@473
|
1073 (EVar (["Basis"], bt, Infer), pos))
|
adamc@141
|
1074 end)
|
adamc@141
|
1075 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
|
adamc@92
|
1076
|
adamc@104
|
1077 attrs : ([])
|
adamc@104
|
1078 | attr attrs (attr :: attrs)
|
adamc@104
|
1079
|
adamc@204
|
1080 attr : SYMBOL EQ attrv ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)), attrv)
|
adamc@204
|
1081
|
adamc@104
|
1082 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@104
|
1083 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
|
adamc@104
|
1084 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@110
|
1085 | LBRACE eexp RBRACE (eexp)
|
adamc@226
|
1086
|
adamc@232
|
1087 query : query1 obopt lopt ofopt (let
|
adamc@229
|
1088 val loc = s (query1left, query1right)
|
adamc@230
|
1089
|
adamc@230
|
1090 val re = (ERecord [((CName "Rows", loc),
|
adamc@230
|
1091 query1),
|
adamc@230
|
1092 ((CName "OrderBy", loc),
|
adamc@231
|
1093 obopt),
|
adamc@231
|
1094 ((CName "Limit", loc),
|
adamc@232
|
1095 lopt),
|
adamc@232
|
1096 ((CName "Offset", loc),
|
adamc@232
|
1097 ofopt)], loc)
|
adamc@229
|
1098 in
|
adamc@403
|
1099 (EApp ((EVar (["Basis"], "sql_query", Infer), loc), re), loc)
|
adamc@229
|
1100 end)
|
adamc@204
|
1101
|
adamc@227
|
1102 query1 : SELECT select FROM tables wopt gopt hopt
|
adamc@209
|
1103 (let
|
adamc@204
|
1104 val loc = s (SELECTleft, tablesright)
|
adamc@207
|
1105
|
adamc@233
|
1106 val (sel, exps) =
|
adamc@207
|
1107 case select of
|
adamc@233
|
1108 Star => (map (fn (nm, _) =>
|
adamc@233
|
1109 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
|
adamc@233
|
1110 loc),
|
adamc@233
|
1111 (CRecord [], loc)],
|
adamc@233
|
1112 loc))) tables,
|
adamc@233
|
1113 [])
|
adamc@207
|
1114 | Items sis =>
|
adamc@207
|
1115 let
|
adamc@207
|
1116 val tabs = map (fn (nm, _) => (nm, (CRecord [], loc))) tables
|
adamc@233
|
1117 val (tabs, exps) = foldl (amend_select loc) (tabs, []) sis
|
adamc@207
|
1118 in
|
adamc@233
|
1119 (map (fn (nm, c) => (nm,
|
adamc@233
|
1120 (CTuple [c,
|
adamc@233
|
1121 (CWild (KRecord (KType, loc), loc),
|
adamc@233
|
1122 loc)], loc))) tabs,
|
adamc@233
|
1123 exps)
|
adamc@207
|
1124 end
|
adamc@207
|
1125
|
adamc@207
|
1126 val sel = (CRecord sel, loc)
|
adamc@207
|
1127
|
adamc@226
|
1128 val grp = case gopt of
|
adamc@403
|
1129 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all",
|
adamc@403
|
1130 Infer), loc),
|
adamc@226
|
1131 (CWild (KRecord (KRecord (KType, loc), loc),
|
adamc@226
|
1132 loc), loc)), loc)
|
adamc@226
|
1133 | SOME gis =>
|
adamc@226
|
1134 let
|
adamc@226
|
1135 val tabs = map (fn (nm, _) =>
|
adamc@226
|
1136 (nm, (CRecord [], loc))) tables
|
adamc@226
|
1137 val tabs = foldl (amend_group loc) tabs gis
|
adamc@226
|
1138
|
adamc@226
|
1139 val tabs = map (fn (nm, c) =>
|
adamc@226
|
1140 (nm,
|
adamc@226
|
1141 (CTuple [c,
|
adamc@226
|
1142 (CWild (KRecord (KType, loc),
|
adamc@226
|
1143 loc),
|
adamc@226
|
1144 loc)], loc))) tabs
|
adamc@226
|
1145 in
|
adamc@403
|
1146 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
|
adamc@226
|
1147 (CRecord tabs, loc)), loc)
|
adamc@226
|
1148 end
|
adamc@226
|
1149
|
adamc@403
|
1150 val e = (EVar (["Basis"], "sql_query1", Infer), loc)
|
adamc@209
|
1151 val re = (ERecord [((CName "From", loc),
|
adamc@209
|
1152 (ERecord tables, loc)),
|
adamc@209
|
1153 ((CName "Where", loc),
|
adamc@223
|
1154 wopt),
|
adamc@224
|
1155 ((CName "GroupBy", loc),
|
adamc@226
|
1156 grp),
|
adamc@224
|
1157 ((CName "Having", loc),
|
adamc@224
|
1158 hopt),
|
adamc@223
|
1159 ((CName "SelectFields", loc),
|
adamc@403
|
1160 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
|
adamc@233
|
1161 sel), loc)),
|
adamc@233
|
1162 ((CName "SelectExps", loc),
|
adamc@233
|
1163 (ERecord exps, loc))], loc)
|
adamc@223
|
1164
|
adamc@209
|
1165 val e = (EApp (e, re), loc)
|
adamc@204
|
1166 in
|
adamc@207
|
1167 e
|
adamc@204
|
1168 end)
|
adamc@229
|
1169 | query1 UNION query1 (sql_relop ("union", query11, query12, s (query11left, query12right)))
|
adamc@229
|
1170 | query1 INTERSECT query1 (sql_relop ("intersect", query11, query12, s (query11left, query12right)))
|
adamc@229
|
1171 | query1 EXCEPT query1 (sql_relop ("except", query11, query12, s (query11left, query12right)))
|
adamc@204
|
1172
|
adamc@204
|
1173 tables : table ([table])
|
adamc@204
|
1174 | table COMMA tables (table :: tables)
|
adamc@204
|
1175
|
adamc@204
|
1176 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@204
|
1177 | LBRACE cexp RBRACE (cexp)
|
adamc@204
|
1178
|
adamc@243
|
1179 table : SYMBOL ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)),
|
adamc@403
|
1180 (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
|
adamc@403
|
1181 | SYMBOL AS tname (tname, (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
|
adamc@221
|
1182 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
|
adamc@207
|
1183
|
adamc@243
|
1184 tident : SYMBOL (CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright))
|
adamc@207
|
1185 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@221
|
1186 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
|
adamc@207
|
1187
|
adamc@207
|
1188 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@207
|
1189 | LBRACE cexp RBRACE (cexp)
|
adamc@207
|
1190
|
adamc@207
|
1191 seli : tident DOT fident (Field (tident, fident))
|
adamc@233
|
1192 | sqlexp AS fident (Exp (fident, sqlexp))
|
adamc@341
|
1193 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (Fields (tident, cexp))
|
adamc@207
|
1194
|
adamc@207
|
1195 selis : seli ([seli])
|
adamc@207
|
1196 | seli COMMA selis (seli :: selis)
|
adamc@207
|
1197
|
adamc@207
|
1198 select : STAR (Star)
|
adamc@207
|
1199 | selis (Items selis)
|
adamc@209
|
1200
|
adamc@403
|
1201 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", Infer),
|
adamc@209
|
1202 s (TRUEleft, TRUEright)))
|
adamc@403
|
1203 | FALSE (sql_inject (EVar (["Basis"], "False", Infer),
|
adamc@209
|
1204 s (FALSEleft, FALSEright)))
|
adamc@209
|
1205
|
adamc@222
|
1206 | INT (sql_inject (EPrim (Prim.Int INT),
|
adamc@222
|
1207 s (INTleft, INTright)))
|
adamc@222
|
1208 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
|
adamc@222
|
1209 s (FLOATleft, FLOATright)))
|
adamc@229
|
1210 | STRING (sql_inject (EPrim (Prim.String STRING),
|
adamc@229
|
1211 s (STRINGleft, STRINGright)))
|
adamc@441
|
1212 | CURRENT_TIMESTAMP (sql_nfunc ("current_timestamp",
|
adamc@441
|
1213 s (CURRENT_TIMESTAMPleft, CURRENT_TIMESTAMPright)))
|
adamc@222
|
1214
|
adamc@221
|
1215 | tident DOT fident (let
|
adamc@221
|
1216 val loc = s (tidentleft, fidentright)
|
adamc@403
|
1217 val e = (EVar (["Basis"], "sql_field", Infer), loc)
|
adamc@221
|
1218 val e = (ECApp (e, tident), loc)
|
adamc@221
|
1219 in
|
adamc@221
|
1220 (ECApp (e, fident), loc)
|
adamc@221
|
1221 end)
|
adamc@234
|
1222 | CSYMBOL (let
|
adamc@234
|
1223 val loc = s (CSYMBOLleft, CSYMBOLright)
|
adamc@310
|
1224 in
|
adamc@310
|
1225 if !inDml then
|
adamc@310
|
1226 let
|
adamc@403
|
1227 val e = (EVar (["Basis"], "sql_field", Infer), loc)
|
adamc@310
|
1228 val e = (ECApp (e, (CName "T", loc)), loc)
|
adamc@310
|
1229 in
|
adamc@310
|
1230 (ECApp (e, (CName CSYMBOL, loc)), loc)
|
adamc@310
|
1231 end
|
adamc@310
|
1232 else
|
adamc@310
|
1233 let
|
adamc@403
|
1234 val e = (EVar (["Basis"], "sql_exp", Infer), loc)
|
adamc@310
|
1235 in
|
adamc@310
|
1236 (ECApp (e, (CName CSYMBOL, loc)), loc)
|
adamc@310
|
1237 end
|
adamc@310
|
1238 end)
|
adamc@221
|
1239
|
adamc@471
|
1240 | LBRACE eexp RBRACE (eexp)
|
adamc@470
|
1241
|
adamc@219
|
1242 | sqlexp EQ sqlexp (sql_compare ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1243 | sqlexp NE sqlexp (sql_compare ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1244 | sqlexp LT sqlexp (sql_compare ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1245 | sqlexp LE sqlexp (sql_compare ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1246 | sqlexp GT sqlexp (sql_compare ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1247 | sqlexp GE sqlexp (sql_compare ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1248
|
adamc@220
|
1249 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@220
|
1250 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@220
|
1251 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
|
adamc@220
|
1252
|
adamc@470
|
1253 | sqlexp IS NULL (let
|
adamc@470
|
1254 val loc = s (sqlexpleft, NULLright)
|
adamc@470
|
1255 in
|
adamc@470
|
1256 (EApp ((EVar (["Basis"], "sql_is_null", Infer), loc),
|
adamc@470
|
1257 sqlexp), loc)
|
adamc@470
|
1258 end)
|
adamc@470
|
1259
|
adamc@471
|
1260 | LBRACE LBRACK eexp RBRACK RBRACE (sql_inject (#1 eexp,
|
adamc@471
|
1261 s (LBRACEleft, RBRACEright)))
|
adamc@220
|
1262 | LPAREN sqlexp RPAREN (sqlexp)
|
adamc@210
|
1263
|
adamc@467
|
1264 | NULL (sql_inject ((EVar (["Basis"], "None", Infer),
|
adamc@467
|
1265 s (NULLleft, NULLright))))
|
adamc@467
|
1266
|
adamc@235
|
1267 | COUNT LPAREN STAR RPAREN (let
|
adamc@235
|
1268 val loc = s (COUNTleft, RPARENright)
|
adamc@235
|
1269 in
|
adamc@403
|
1270 (EApp ((EVar (["Basis"], "sql_count", Infer), loc),
|
adamc@235
|
1271 (ERecord [], loc)), loc)
|
adamc@235
|
1272 end)
|
adamc@236
|
1273 | sqlagg LPAREN sqlexp RPAREN (let
|
adamc@236
|
1274 val loc = s (sqlaggleft, RPARENright)
|
adamc@236
|
1275
|
adamc@403
|
1276 val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
|
adamc@403
|
1277 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
|
adamc@236
|
1278 e), loc)
|
adamc@236
|
1279 in
|
adamc@236
|
1280 (EApp (e, sqlexp), loc)
|
adamc@236
|
1281 end)
|
adamc@235
|
1282
|
adamc@403
|
1283 wopt : (sql_inject (EVar (["Basis"], "True", Infer),
|
adamc@230
|
1284 dummy))
|
adamc@209
|
1285 | CWHERE sqlexp (sqlexp)
|
adamc@226
|
1286
|
adamc@226
|
1287 groupi : tident DOT fident (GField (tident, fident))
|
adamc@226
|
1288
|
adamc@226
|
1289 groupis: groupi ([groupi])
|
adamc@226
|
1290 | groupi COMMA groupis (groupi :: groupis)
|
adamc@226
|
1291
|
adamc@226
|
1292 gopt : (NONE)
|
adamc@226
|
1293 | GROUP BY groupis (SOME groupis)
|
adamc@227
|
1294
|
adamc@403
|
1295 hopt : (sql_inject (EVar (["Basis"], "True", Infer),
|
adamc@230
|
1296 dummy))
|
adamc@227
|
1297 | HAVING sqlexp (sqlexp)
|
adamc@230
|
1298
|
adamc@403
|
1299 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
|
adamc@234
|
1300 (CWild (KRecord (KType, dummy), dummy), dummy)),
|
adamc@230
|
1301 dummy)
|
adamc@230
|
1302 | ORDER BY obexps (obexps)
|
adamc@230
|
1303
|
adamc@268
|
1304 obitem : sqlexp diropt (sqlexp, diropt)
|
adamc@268
|
1305
|
adamc@268
|
1306 obexps : obitem (let
|
adamc@268
|
1307 val loc = s (obitemleft, obitemright)
|
adamc@230
|
1308
|
adamc@403
|
1309 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), loc),
|
adamc@234
|
1310 (CWild (KRecord (KType, loc), loc), loc)),
|
adamc@230
|
1311 loc)
|
adamc@403
|
1312 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
|
adamc@268
|
1313 #1 obitem), loc)
|
adamc@268
|
1314 val e = (EApp (e, #2 obitem), loc)
|
adamc@230
|
1315 in
|
adamc@230
|
1316 (EApp (e, e'), loc)
|
adamc@230
|
1317 end)
|
adamc@268
|
1318 | obitem COMMA obexps (let
|
adamc@268
|
1319 val loc = s (obitemleft, obexpsright)
|
adamc@230
|
1320
|
adamc@403
|
1321 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
|
adamc@268
|
1322 #1 obitem), loc)
|
adamc@268
|
1323 val e = (EApp (e, #2 obitem), loc)
|
adamc@230
|
1324 in
|
adamc@230
|
1325 (EApp (e, obexps), loc)
|
adamc@230
|
1326 end)
|
adamc@231
|
1327
|
adamc@403
|
1328 diropt : (EVar (["Basis"], "sql_asc", Infer), dummy)
|
adamc@403
|
1329 | ASC (EVar (["Basis"], "sql_asc", Infer), s (ASCleft, ASCright))
|
adamc@403
|
1330 | DESC (EVar (["Basis"], "sql_desc", Infer), s (DESCleft, DESCright))
|
adamc@268
|
1331
|
adamc@403
|
1332 lopt : (EVar (["Basis"], "sql_no_limit", Infer), dummy)
|
adamc@403
|
1333 | LIMIT ALL (EVar (["Basis"], "sql_no_limit", Infer), dummy)
|
adamc@231
|
1334 | LIMIT sqlint (let
|
adamc@231
|
1335 val loc = s (LIMITleft, sqlintright)
|
adamc@231
|
1336 in
|
adamc@403
|
1337 (EApp ((EVar (["Basis"], "sql_limit", Infer), loc), sqlint), loc)
|
adamc@231
|
1338 end)
|
adamc@231
|
1339
|
adamc@403
|
1340 ofopt : (EVar (["Basis"], "sql_no_offset", Infer), dummy)
|
adamc@232
|
1341 | OFFSET sqlint (let
|
adamc@232
|
1342 val loc = s (OFFSETleft, sqlintright)
|
adamc@232
|
1343 in
|
adamc@403
|
1344 (EApp ((EVar (["Basis"], "sql_offset", Infer), loc), sqlint), loc)
|
adamc@232
|
1345 end)
|
adamc@232
|
1346
|
adamc@231
|
1347 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@231
|
1348 | LBRACE eexp RBRACE (eexp)
|
adamc@236
|
1349
|
adamc@236
|
1350 sqlagg : AVG ("avg")
|
adamc@236
|
1351 | SUM ("sum")
|
adamc@236
|
1352 | MIN ("min")
|
adamc@236
|
1353 | MAX ("max")
|