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