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