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