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