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@241
|
546 | cargp (cargp)
|
adamc@239
|
547
|
adamc@239
|
548 cargp : SYMBOL (fn (c, k) =>
|
adamc@239
|
549 let
|
adamc@239
|
550 val loc = s (SYMBOLleft, SYMBOLright)
|
adamc@239
|
551 in
|
adamc@239
|
552 ((CAbs (SYMBOL, NONE, c), loc),
|
adamc@239
|
553 (KArrow ((KWild, loc), k), loc))
|
adamc@239
|
554 end)
|
adamc@239
|
555 | LPAREN SYMBOL DCOLON kind RPAREN (fn (c, k) =>
|
adamc@239
|
556 let
|
adamc@239
|
557 val loc = s (LPARENleft, RPARENright)
|
adamc@239
|
558 in
|
adamc@239
|
559 ((CAbs (SYMBOL, SOME kind, c), loc),
|
adamc@239
|
560 (KArrow (kind, k), loc))
|
adamc@239
|
561 end)
|
adamc@239
|
562
|
adamc@34
|
563 path : SYMBOL ([], SYMBOL)
|
adamc@34
|
564 | CSYMBOL DOT path (let val (ms, x) = path in (CSYMBOL :: ms, x) end)
|
adamc@34
|
565
|
adamc@156
|
566 cpath : CSYMBOL ([], CSYMBOL)
|
adamc@156
|
567 | CSYMBOL DOT cpath (let val (ms, x) = cpath in (CSYMBOL :: ms, x) end)
|
adamc@156
|
568
|
adamc@59
|
569 mpath : CSYMBOL ([CSYMBOL])
|
adamc@59
|
570 | CSYMBOL DOT mpath (CSYMBOL :: mpath)
|
adamc@59
|
571
|
adamc@1
|
572 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright))
|
adamc@1
|
573 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright))
|
adamc@83
|
574 | LBRACK rconn RBRACK (CRecord rconn, s (LBRACKleft, RBRACKright))
|
adamc@1
|
575 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)),
|
adamc@1
|
576 s (LBRACEleft, RBRACEright))
|
adamc@1
|
577 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright))
|
adamc@1
|
578 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright))
|
adamc@195
|
579 | HASH INT (CName (Int64.toString INT), s (HASHleft, INTright))
|
adamc@1
|
580
|
adamc@34
|
581 | path (CVar path, s (pathleft, pathright))
|
adamc@207
|
582 | path DOT INT (CProj ((CVar path, s (pathleft, pathright)), Int64.toInt INT),
|
adamc@207
|
583 s (pathleft, INTright))
|
adamc@18
|
584 | UNDER (CWild (KWild, s (UNDERleft, UNDERright)), s (UNDERleft, UNDERright))
|
adamc@67
|
585 | FOLD (CFold, s (FOLDleft, FOLDright))
|
adamc@82
|
586 | UNIT (CUnit, s (UNITleft, UNITright))
|
adamc@207
|
587 | LPAREN ctuplev RPAREN (CTuple ctuplev, s (LPARENleft, RPARENright))
|
adamc@207
|
588
|
adamc@207
|
589 ctuplev: cexp COMMA cexp ([cexp1, cexp2])
|
adamc@207
|
590 | cexp COMMA ctuplev (cexp :: ctuplev)
|
adamc@1
|
591
|
adamc@196
|
592 ctuple : capps STAR capps ([capps1, capps2])
|
adamc@196
|
593 | capps STAR ctuple (capps :: ctuple)
|
adamc@195
|
594
|
adamc@1
|
595 rcon : ([])
|
adamc@1
|
596 | ident EQ cexp ([(ident, cexp)])
|
adamc@1
|
597 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon)
|
adamc@1
|
598
|
adamc@83
|
599 rconn : ident ([(ident, (CUnit, s (identleft, identright)))])
|
adamc@83
|
600 | ident COMMA rconn ((ident, (CUnit, s (identleft, identright))) :: rconn)
|
adamc@83
|
601
|
adamc@1
|
602 rcone : ([])
|
adamc@1
|
603 | ident COLON cexp ([(ident, cexp)])
|
adamc@1
|
604 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone)
|
adamc@1
|
605
|
adamc@1
|
606 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@195
|
607 | INT (CName (Int64.toString INT), s (INTleft, INTright))
|
adamc@200
|
608 | SYMBOL (CVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
|
adamc@8
|
609
|
adamc@8
|
610 eapps : eterm (eterm)
|
adamc@8
|
611 | eapps eterm (EApp (eapps, eterm), s (eappsleft, etermright))
|
adamc@8
|
612 | eapps LBRACK cexp RBRACK (ECApp (eapps, cexp), s (eappsleft, RBRACKright))
|
adamc@8
|
613
|
adamc@8
|
614 eexp : eapps (eapps)
|
adamc@241
|
615 | FN eargs DARROW eexp (let
|
adamc@93
|
616 val loc = s (FNleft, eexpright)
|
adamc@93
|
617 in
|
adamc@241
|
618 #1 (eargs (eexp, (CWild (KType, loc), loc)))
|
adamc@93
|
619 end)
|
adamc@241
|
620 | LBRACK cterm TWIDDLE cterm RBRACK DARROW eexp(EDisjoint (cterm1, cterm2, eexp), s (LBRACKleft, RBRACKright))
|
adamc@196
|
621 | eexp COLON cexp (EAnnot (eexp, cexp), s (eexpleft, cexpright))
|
adamc@149
|
622 | eexp MINUSMINUS cexp (ECut (eexp, cexp), s (eexpleft, cexpright))
|
adamc@170
|
623 | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
|
adamc@190
|
624 | IF eexp THEN eexp ELSE eexp (let
|
adamc@190
|
625 val loc = s (IFleft, eexp3right)
|
adamc@190
|
626 in
|
adamc@190
|
627 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc), eexp2),
|
adamc@190
|
628 ((PCon (["Basis"], "False", NONE), loc), eexp3)]), loc)
|
adamc@190
|
629 end)
|
adamc@243
|
630 | SYMBOL LARROW eexp SEMI eexp (let
|
adamc@243
|
631 val loc = s (SYMBOLleft, eexp2right)
|
adamc@243
|
632 val e = (EVar (["Basis"], "bind"), loc)
|
adamc@243
|
633 val e = (EApp (e, eexp1), loc)
|
adamc@243
|
634 in
|
adamc@243
|
635 (EApp (e, (EAbs (SYMBOL, NONE, eexp2), loc)), loc)
|
adamc@243
|
636 end)
|
adamc@299
|
637 | UNIT LARROW eexp SEMI eexp (let
|
adamc@299
|
638 val loc = s (UNITleft, eexp2right)
|
adamc@299
|
639 val e = (EVar (["Basis"], "bind"), loc)
|
adamc@299
|
640 val e = (EApp (e, eexp1), loc)
|
adamc@299
|
641 val t = (TRecord (CRecord [], loc), loc)
|
adamc@299
|
642 in
|
adamc@299
|
643 (EApp (e, (EAbs ("_", SOME t, eexp2), loc)), loc)
|
adamc@299
|
644 end)
|
adamc@256
|
645 | eexp EQ eexp (native_op ("eq", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@257
|
646 | eexp NE eexp (native_op ("ne", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@8
|
647
|
adamc@241
|
648 eargs : earg (earg)
|
adamc@241
|
649 | eargl (eargl)
|
adamc@241
|
650
|
adamc@241
|
651 eargl : eargp eargp (eargp1 o eargp2)
|
adamc@241
|
652 | eargp eargl (eargp o eargl)
|
adamc@241
|
653
|
adamc@242
|
654 eargl2 : (fn x => x)
|
adamc@242
|
655 | eargp eargl2 (eargp o eargl2)
|
adamc@242
|
656
|
adamc@241
|
657 earg : SYMBOL kcolon kind (fn (e, t) =>
|
adamc@241
|
658 let
|
adamc@241
|
659 val loc = s (SYMBOLleft, kindright)
|
adamc@241
|
660 in
|
adamc@241
|
661 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
|
adamc@241
|
662 (TCFun (kcolon, SYMBOL, kind, t), loc))
|
adamc@241
|
663 end)
|
adamc@241
|
664 | SYMBOL COLON cexp (fn (e, t) =>
|
adamc@241
|
665 let
|
adamc@241
|
666 val loc = s (SYMBOLleft, cexpright)
|
adamc@241
|
667 in
|
adamc@241
|
668 ((EAbs (SYMBOL, SOME cexp, e), loc),
|
adamc@241
|
669 (TFun (cexp, t), loc))
|
adamc@241
|
670 end)
|
adamc@241
|
671 | UNDER COLON cexp (fn (e, t) =>
|
adamc@241
|
672 let
|
adamc@241
|
673 val loc = s (UNDERleft, cexpright)
|
adamc@241
|
674 in
|
adamc@241
|
675 ((EAbs ("_", SOME cexp, e), loc),
|
adamc@241
|
676 (TFun (cexp, t), loc))
|
adamc@241
|
677 end)
|
adamc@241
|
678 | eargp (eargp)
|
adamc@241
|
679
|
adamc@241
|
680 eargp : SYMBOL (fn (e, t) =>
|
adamc@241
|
681 let
|
adamc@241
|
682 val loc = s (SYMBOLleft, SYMBOLright)
|
adamc@241
|
683 in
|
adamc@241
|
684 ((EAbs (SYMBOL, NONE, e), loc),
|
adamc@241
|
685 (TFun ((CWild (KType, loc), loc), t), loc))
|
adamc@241
|
686 end)
|
adamc@241
|
687 | UNIT (fn (e, t) =>
|
adamc@241
|
688 let
|
adamc@241
|
689 val loc = s (UNITleft, UNITright)
|
adamc@241
|
690 val t' = (TRecord (CRecord [], loc), loc)
|
adamc@241
|
691 in
|
adamc@241
|
692 ((EAbs ("_", SOME t', e), loc),
|
adamc@241
|
693 (TFun (t', t), loc))
|
adamc@241
|
694 end)
|
adamc@241
|
695 | UNDER (fn (e, t) =>
|
adamc@241
|
696 let
|
adamc@241
|
697 val loc = s (UNDERleft, UNDERright)
|
adamc@241
|
698 in
|
adamc@241
|
699 ((EAbs ("_", NONE, e), loc),
|
adamc@241
|
700 (TFun ((CWild (KType, loc), loc), t), loc))
|
adamc@241
|
701 end)
|
adamc@241
|
702 | LPAREN SYMBOL kcolon kind RPAREN(fn (e, t) =>
|
adamc@241
|
703 let
|
adamc@241
|
704 val loc = s (LPARENleft, RPARENright)
|
adamc@241
|
705 in
|
adamc@241
|
706 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
|
adamc@241
|
707 (TCFun (kcolon, SYMBOL, kind, t), loc))
|
adamc@241
|
708 end)
|
adamc@241
|
709 | LPAREN SYMBOL COLON cexp RPAREN (fn (e, t) =>
|
adamc@241
|
710 let
|
adamc@241
|
711 val loc = s (LPARENleft, RPARENright)
|
adamc@241
|
712 in
|
adamc@241
|
713 ((EAbs (SYMBOL, SOME cexp, e), loc),
|
adamc@241
|
714 (TFun (cexp, t), loc))
|
adamc@241
|
715 end)
|
adamc@241
|
716 | LPAREN UNDER COLON cexp RPAREN (fn (e, t) =>
|
adamc@241
|
717 let
|
adamc@241
|
718 val loc = s (LPARENleft, RPARENright)
|
adamc@241
|
719 in
|
adamc@241
|
720 ((EAbs ("_", SOME cexp, e), loc),
|
adamc@241
|
721 (TFun (cexp, t), loc))
|
adamc@241
|
722 end)
|
adamc@241
|
723
|
adamc@8
|
724 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
|
adamc@195
|
725 | LPAREN etuple RPAREN (let
|
adamc@195
|
726 val loc = s (LPARENleft, RPARENright)
|
adamc@195
|
727 in
|
adamc@195
|
728 (ERecord (ListUtil.mapi (fn (i, e) =>
|
adamc@195
|
729 ((CName (Int.toString (i + 1)), loc),
|
adamc@195
|
730 e)) etuple), loc)
|
adamc@195
|
731 end)
|
adamc@8
|
732
|
adamc@34
|
733 | path (EVar path, s (pathleft, pathright))
|
adamc@156
|
734 | cpath (EVar cpath, s (cpathleft, cpathright))
|
adamc@12
|
735 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
|
adamc@110
|
736 | UNIT (ERecord [], s (UNITleft, UNITright))
|
adamc@12
|
737
|
adamc@14
|
738 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@14
|
739 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
|
adamc@14
|
740 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@14
|
741
|
adamc@200
|
742 | path DOT idents (let
|
adamc@200
|
743 val loc = s (pathleft, identsright)
|
adamc@200
|
744 in
|
adamc@200
|
745 foldl (fn (ident, e) =>
|
adamc@200
|
746 (EField (e, ident), loc))
|
adamc@200
|
747 (EVar path, s (pathleft, pathright)) idents
|
adamc@200
|
748 end)
|
adamc@71
|
749 | FOLD (EFold, s (FOLDleft, FOLDright))
|
adamc@71
|
750
|
adamc@91
|
751 | XML_BEGIN xml XML_END (xml)
|
adamc@91
|
752 | XML_BEGIN XML_END (EApp ((EVar (["Basis"], "cdata"), s (XML_BEGINleft, XML_ENDright)),
|
adamc@91
|
753 (EPrim (Prim.String ""), s (XML_BEGINleft, XML_ENDright))),
|
adamc@91
|
754 s (XML_BEGINleft, XML_ENDright))
|
adamc@302
|
755
|
adamc@204
|
756 | LPAREN query RPAREN (query)
|
adamc@300
|
757 | LPAREN CWHERE sqlexp RPAREN (sqlexp)
|
adamc@302
|
758
|
adamc@302
|
759 | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN
|
adamc@302
|
760 (let
|
adamc@302
|
761 val loc = s (LPAREN1left, RPAREN3right)
|
adamc@302
|
762
|
adamc@302
|
763 val e = (EVar (["Basis"], "insert"), loc)
|
adamc@302
|
764 val e = (EApp (e, texp), loc)
|
adamc@302
|
765 in
|
adamc@302
|
766 if length fields <> length sqlexps then
|
adamc@302
|
767 ErrorMsg.errorAt loc "Length mismatch in INSERT field specification"
|
adamc@302
|
768 else
|
adamc@302
|
769 ();
|
adamc@302
|
770 (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
|
adamc@302
|
771 end)
|
adamc@310
|
772 | LPAREN enterDml UPDATE texp SET fsets CWHERE sqlexp leaveDml RPAREN
|
adamc@303
|
773 (let
|
adamc@303
|
774 val loc = s (LPARENleft, RPARENright)
|
adamc@303
|
775
|
adamc@303
|
776 val e = (EVar (["Basis"], "update"), loc)
|
adamc@306
|
777 val e = (EApp (e, (ERecord fsets, loc)), loc)
|
adamc@305
|
778 val e = (EApp (e, texp), loc)
|
adamc@303
|
779 in
|
adamc@303
|
780 (EApp (e, sqlexp), loc)
|
adamc@303
|
781 end)
|
adamc@310
|
782 | LPAREN enterDml DELETE FROM texp CWHERE sqlexp leaveDml RPAREN
|
adamc@304
|
783 (let
|
adamc@304
|
784 val loc = s (LPARENleft, RPARENright)
|
adamc@304
|
785
|
adamc@304
|
786 val e = (EVar (["Basis"], "delete"), loc)
|
adamc@304
|
787 val e = (EApp (e, texp), loc)
|
adamc@304
|
788 in
|
adamc@304
|
789 (EApp (e, sqlexp), loc)
|
adamc@304
|
790 end)
|
adamc@302
|
791
|
adamc@211
|
792 | UNDER (EWild, s (UNDERleft, UNDERright))
|
adamc@91
|
793
|
adamc@310
|
794 enterDml : (inDml := true)
|
adamc@310
|
795 leaveDml : (inDml := false)
|
adamc@310
|
796
|
adamc@302
|
797 texp : SYMBOL (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
|
adamc@302
|
798 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
|
adamc@302
|
799
|
adamc@302
|
800 fields : fident ([fident])
|
adamc@302
|
801 | fident COMMA fields (fident :: fields)
|
adamc@302
|
802
|
adamc@302
|
803 sqlexps: sqlexp ([sqlexp])
|
adamc@302
|
804 | sqlexp COMMA sqlexps (sqlexp :: sqlexps)
|
adamc@302
|
805
|
adamc@303
|
806 fsets : fident EQ sqlexp ([(fident, sqlexp)])
|
adamc@303
|
807 | fident EQ sqlexp COMMA fsets ((fident, sqlexp) :: fsets)
|
adamc@303
|
808
|
adamc@200
|
809 idents : ident ([ident])
|
adamc@200
|
810 | ident DOT idents (ident :: idents)
|
adamc@200
|
811
|
adamc@195
|
812 etuple : eexp COMMA eexp ([eexp1, eexp2])
|
adamc@195
|
813 | eexp COMMA etuple (eexp :: etuple)
|
adamc@195
|
814
|
adamc@170
|
815 branch : pat DARROW eexp (pat, eexp)
|
adamc@170
|
816
|
adamc@170
|
817 branchs: ([])
|
adamc@170
|
818 | BAR branch branchs (branch :: branchs)
|
adamc@170
|
819
|
adamc@170
|
820 pat : pterm (pterm)
|
adamc@170
|
821 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
|
adamc@170
|
822
|
adamc@170
|
823 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
|
adamc@170
|
824 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
|
adamc@170
|
825 | UNDER (PWild, s (UNDERleft, UNDERright))
|
adamc@173
|
826 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@173
|
827 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@170
|
828 | LPAREN pat RPAREN (pat)
|
adamc@174
|
829 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
|
adamc@174
|
830 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
|
adamc@174
|
831 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
|
adamc@195
|
832 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
|
adamc@195
|
833 false),
|
adamc@195
|
834 s (LPARENleft, RPARENright))
|
adamc@174
|
835
|
adamc@175
|
836 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
|
adamc@243
|
837 | INT EQ pat ([(Int64.toString INT, pat)], false)
|
adamc@174
|
838 | DOTDOTDOT ([], true)
|
adamc@175
|
839 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
|
adamc@243
|
840 | INT EQ pat COMMA rpat ((Int64.toString INT, pat) :: #1 rpat, #2 rpat)
|
adamc@170
|
841
|
adamc@195
|
842 ptuple : pat COMMA pat ([pat1, pat2])
|
adamc@195
|
843 | pat COMMA ptuple (pat :: ptuple)
|
adamc@195
|
844
|
adamc@12
|
845 rexp : ([])
|
adamc@12
|
846 | ident EQ eexp ([(ident, eexp)])
|
adamc@12
|
847 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
|
adamc@91
|
848
|
adamc@141
|
849 xml : xmlOne xml (let
|
adamc@141
|
850 val pos = s (xmlOneleft, xmlright)
|
adamc@141
|
851 in
|
adamc@141
|
852 (EApp ((EApp (
|
adamc@141
|
853 (EVar (["Basis"], "join"), pos),
|
adamc@91
|
854 xmlOne), pos),
|
adamc@141
|
855 xml), pos)
|
adamc@141
|
856 end)
|
adamc@141
|
857 | xmlOne (xmlOne)
|
adamc@91
|
858
|
adamc@141
|
859 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata"), s (NOTAGSleft, NOTAGSright)),
|
adamc@141
|
860 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
|
adamc@141
|
861 s (NOTAGSleft, NOTAGSright))
|
adamc@141
|
862 | tag DIVIDE GT (let
|
adamc@141
|
863 val pos = s (tagleft, GTright)
|
adamc@141
|
864 in
|
adamc@141
|
865 (EApp (#2 tag,
|
adamc@141
|
866 (EApp ((EVar (["Basis"], "cdata"), pos),
|
adamc@141
|
867 (EPrim (Prim.String ""), pos)),
|
adamc@141
|
868 pos)), pos)
|
adamc@141
|
869 end)
|
adamc@141
|
870
|
adamc@141
|
871 | tag GT xml END_TAG (let
|
adamc@141
|
872 val pos = s (tagleft, GTright)
|
adamc@325
|
873 val et = tagIn END_TAG
|
adamc@141
|
874 in
|
adamc@325
|
875 if #1 tag = et then
|
adamc@325
|
876 if et = "lform" then
|
adamc@141
|
877 (EApp ((EVar (["Basis"], "lform"), pos),
|
adamc@141
|
878 xml), pos)
|
adamc@141
|
879 else
|
adamc@141
|
880 (EApp (#2 tag, xml), pos)
|
adamc@141
|
881 else
|
adamc@325
|
882 (if ErrorMsg.anyErrors () then
|
adamc@325
|
883 ()
|
adamc@325
|
884 else
|
adamc@325
|
885 ErrorMsg.errorAt pos "Begin and end tags don't match.";
|
adamc@141
|
886 (EFold, pos))
|
adamc@141
|
887 end)
|
adamc@141
|
888 | LBRACE eexp RBRACE (eexp)
|
adamc@92
|
889
|
adamc@141
|
890 tag : tagHead attrs (let
|
adamc@141
|
891 val pos = s (tagHeadleft, attrsright)
|
adamc@141
|
892 in
|
adamc@141
|
893 (#1 tagHead,
|
adamc@141
|
894 (EApp ((EApp ((EVar (["Basis"], "tag"), pos),
|
adamc@141
|
895 (ERecord attrs, pos)), pos),
|
adamc@141
|
896 (EApp (#2 tagHead,
|
adamc@141
|
897 (ERecord [], pos)), pos)),
|
adamc@141
|
898 pos))
|
adamc@141
|
899 end)
|
adamc@141
|
900
|
adamc@141
|
901 tagHead: BEGIN_TAG (let
|
adamc@325
|
902 val bt = tagIn BEGIN_TAG
|
adamc@141
|
903 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
|
adamc@141
|
904 in
|
adamc@325
|
905 (bt,
|
adamc@325
|
906 (EVar ([], bt), pos))
|
adamc@141
|
907 end)
|
adamc@141
|
908 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
|
adamc@92
|
909
|
adamc@104
|
910 attrs : ([])
|
adamc@104
|
911 | attr attrs (attr :: attrs)
|
adamc@104
|
912
|
adamc@204
|
913 attr : SYMBOL EQ attrv ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)), attrv)
|
adamc@204
|
914
|
adamc@104
|
915 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@104
|
916 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
|
adamc@104
|
917 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@110
|
918 | LBRACE eexp RBRACE (eexp)
|
adamc@226
|
919
|
adamc@232
|
920 query : query1 obopt lopt ofopt (let
|
adamc@229
|
921 val loc = s (query1left, query1right)
|
adamc@230
|
922
|
adamc@230
|
923 val re = (ERecord [((CName "Rows", loc),
|
adamc@230
|
924 query1),
|
adamc@230
|
925 ((CName "OrderBy", loc),
|
adamc@231
|
926 obopt),
|
adamc@231
|
927 ((CName "Limit", loc),
|
adamc@232
|
928 lopt),
|
adamc@232
|
929 ((CName "Offset", loc),
|
adamc@232
|
930 ofopt)], loc)
|
adamc@229
|
931 in
|
adamc@230
|
932 (EApp ((EVar (["Basis"], "sql_query"), loc), re), loc)
|
adamc@229
|
933 end)
|
adamc@204
|
934
|
adamc@227
|
935 query1 : SELECT select FROM tables wopt gopt hopt
|
adamc@209
|
936 (let
|
adamc@204
|
937 val loc = s (SELECTleft, tablesright)
|
adamc@207
|
938
|
adamc@233
|
939 val (sel, exps) =
|
adamc@207
|
940 case select of
|
adamc@233
|
941 Star => (map (fn (nm, _) =>
|
adamc@233
|
942 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
|
adamc@233
|
943 loc),
|
adamc@233
|
944 (CRecord [], loc)],
|
adamc@233
|
945 loc))) tables,
|
adamc@233
|
946 [])
|
adamc@207
|
947 | Items sis =>
|
adamc@207
|
948 let
|
adamc@207
|
949 val tabs = map (fn (nm, _) => (nm, (CRecord [], loc))) tables
|
adamc@233
|
950 val (tabs, exps) = foldl (amend_select loc) (tabs, []) sis
|
adamc@207
|
951 in
|
adamc@233
|
952 (map (fn (nm, c) => (nm,
|
adamc@233
|
953 (CTuple [c,
|
adamc@233
|
954 (CWild (KRecord (KType, loc), loc),
|
adamc@233
|
955 loc)], loc))) tabs,
|
adamc@233
|
956 exps)
|
adamc@207
|
957 end
|
adamc@207
|
958
|
adamc@207
|
959 val sel = (CRecord sel, loc)
|
adamc@207
|
960
|
adamc@226
|
961 val grp = case gopt of
|
adamc@226
|
962 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all"), loc),
|
adamc@226
|
963 (CWild (KRecord (KRecord (KType, loc), loc),
|
adamc@226
|
964 loc), loc)), loc)
|
adamc@226
|
965 | SOME gis =>
|
adamc@226
|
966 let
|
adamc@226
|
967 val tabs = map (fn (nm, _) =>
|
adamc@226
|
968 (nm, (CRecord [], loc))) tables
|
adamc@226
|
969 val tabs = foldl (amend_group loc) tabs gis
|
adamc@226
|
970
|
adamc@226
|
971 val tabs = map (fn (nm, c) =>
|
adamc@226
|
972 (nm,
|
adamc@226
|
973 (CTuple [c,
|
adamc@226
|
974 (CWild (KRecord (KType, loc),
|
adamc@226
|
975 loc),
|
adamc@226
|
976 loc)], loc))) tabs
|
adamc@226
|
977 in
|
adamc@226
|
978 (ECApp ((EVar (["Basis"], "sql_subset"), loc),
|
adamc@226
|
979 (CRecord tabs, loc)), loc)
|
adamc@226
|
980 end
|
adamc@226
|
981
|
adamc@229
|
982 val e = (EVar (["Basis"], "sql_query1"), loc)
|
adamc@209
|
983 val re = (ERecord [((CName "From", loc),
|
adamc@209
|
984 (ERecord tables, loc)),
|
adamc@209
|
985 ((CName "Where", loc),
|
adamc@223
|
986 wopt),
|
adamc@224
|
987 ((CName "GroupBy", loc),
|
adamc@226
|
988 grp),
|
adamc@224
|
989 ((CName "Having", loc),
|
adamc@224
|
990 hopt),
|
adamc@223
|
991 ((CName "SelectFields", loc),
|
adamc@223
|
992 (ECApp ((EVar (["Basis"], "sql_subset"), loc),
|
adamc@233
|
993 sel), loc)),
|
adamc@233
|
994 ((CName "SelectExps", loc),
|
adamc@233
|
995 (ERecord exps, loc))], loc)
|
adamc@223
|
996
|
adamc@209
|
997 val e = (EApp (e, re), loc)
|
adamc@204
|
998 in
|
adamc@207
|
999 e
|
adamc@204
|
1000 end)
|
adamc@229
|
1001 | query1 UNION query1 (sql_relop ("union", query11, query12, s (query11left, query12right)))
|
adamc@229
|
1002 | query1 INTERSECT query1 (sql_relop ("intersect", query11, query12, s (query11left, query12right)))
|
adamc@229
|
1003 | query1 EXCEPT query1 (sql_relop ("except", query11, query12, s (query11left, query12right)))
|
adamc@204
|
1004
|
adamc@204
|
1005 tables : table ([table])
|
adamc@204
|
1006 | table COMMA tables (table :: tables)
|
adamc@204
|
1007
|
adamc@204
|
1008 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@204
|
1009 | LBRACE cexp RBRACE (cexp)
|
adamc@204
|
1010
|
adamc@243
|
1011 table : SYMBOL ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)),
|
adamc@204
|
1012 (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright)))
|
adamc@204
|
1013 | SYMBOL AS tname (tname, (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright)))
|
adamc@221
|
1014 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
|
adamc@207
|
1015
|
adamc@243
|
1016 tident : SYMBOL (CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright))
|
adamc@207
|
1017 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@221
|
1018 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
|
adamc@207
|
1019
|
adamc@207
|
1020 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@207
|
1021 | LBRACE cexp RBRACE (cexp)
|
adamc@207
|
1022
|
adamc@207
|
1023 seli : tident DOT fident (Field (tident, fident))
|
adamc@233
|
1024 | sqlexp AS fident (Exp (fident, sqlexp))
|
adamc@207
|
1025
|
adamc@207
|
1026 selis : seli ([seli])
|
adamc@207
|
1027 | seli COMMA selis (seli :: selis)
|
adamc@207
|
1028
|
adamc@207
|
1029 select : STAR (Star)
|
adamc@207
|
1030 | selis (Items selis)
|
adamc@209
|
1031
|
adamc@209
|
1032 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True"),
|
adamc@209
|
1033 EVar (["Basis"], "sql_bool"),
|
adamc@209
|
1034 s (TRUEleft, TRUEright)))
|
adamc@209
|
1035 | FALSE (sql_inject (EVar (["Basis"], "False"),
|
adamc@209
|
1036 EVar (["Basis"], "sql_bool"),
|
adamc@209
|
1037 s (FALSEleft, FALSEright)))
|
adamc@209
|
1038
|
adamc@222
|
1039 | INT (sql_inject (EPrim (Prim.Int INT),
|
adamc@222
|
1040 EVar (["Basis"], "sql_int"),
|
adamc@222
|
1041 s (INTleft, INTright)))
|
adamc@222
|
1042 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
|
adamc@222
|
1043 EVar (["Basis"], "sql_float"),
|
adamc@222
|
1044 s (FLOATleft, FLOATright)))
|
adamc@229
|
1045 | STRING (sql_inject (EPrim (Prim.String STRING),
|
adamc@229
|
1046 EVar (["Basis"], "sql_string"),
|
adamc@229
|
1047 s (STRINGleft, STRINGright)))
|
adamc@222
|
1048
|
adamc@221
|
1049 | tident DOT fident (let
|
adamc@221
|
1050 val loc = s (tidentleft, fidentright)
|
adamc@221
|
1051 val e = (EVar (["Basis"], "sql_field"), loc)
|
adamc@221
|
1052 val e = (ECApp (e, tident), loc)
|
adamc@221
|
1053 in
|
adamc@221
|
1054 (ECApp (e, fident), loc)
|
adamc@221
|
1055 end)
|
adamc@234
|
1056 | CSYMBOL (let
|
adamc@234
|
1057 val loc = s (CSYMBOLleft, CSYMBOLright)
|
adamc@310
|
1058 in
|
adamc@310
|
1059 if !inDml then
|
adamc@310
|
1060 let
|
adamc@310
|
1061 val e = (EVar (["Basis"], "sql_field"), loc)
|
adamc@310
|
1062 val e = (ECApp (e, (CName "T", loc)), loc)
|
adamc@310
|
1063 in
|
adamc@310
|
1064 (ECApp (e, (CName CSYMBOL, loc)), loc)
|
adamc@310
|
1065 end
|
adamc@310
|
1066 else
|
adamc@310
|
1067 let
|
adamc@310
|
1068 val e = (EVar (["Basis"], "sql_exp"), loc)
|
adamc@310
|
1069 in
|
adamc@310
|
1070 (ECApp (e, (CName CSYMBOL, loc)), loc)
|
adamc@310
|
1071 end
|
adamc@310
|
1072 end)
|
adamc@221
|
1073
|
adamc@219
|
1074 | sqlexp EQ sqlexp (sql_compare ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1075 | sqlexp NE sqlexp (sql_compare ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1076 | sqlexp LT sqlexp (sql_compare ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1077 | sqlexp LE sqlexp (sql_compare ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1078 | sqlexp GT sqlexp (sql_compare ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1079 | sqlexp GE sqlexp (sql_compare ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
1080
|
adamc@220
|
1081 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@220
|
1082 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@220
|
1083 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
|
adamc@220
|
1084
|
adamc@210
|
1085 | LBRACE eexp RBRACE (sql_inject (#1 eexp,
|
adamc@211
|
1086 EWild,
|
adamc@210
|
1087 s (LBRACEleft, RBRACEright)))
|
adamc@220
|
1088 | LPAREN sqlexp RPAREN (sqlexp)
|
adamc@210
|
1089
|
adamc@235
|
1090 | COUNT LPAREN STAR RPAREN (let
|
adamc@235
|
1091 val loc = s (COUNTleft, RPARENright)
|
adamc@235
|
1092 in
|
adamc@235
|
1093 (EApp ((EVar (["Basis"], "sql_count"), loc),
|
adamc@235
|
1094 (ERecord [], loc)), loc)
|
adamc@235
|
1095 end)
|
adamc@236
|
1096 | sqlagg LPAREN sqlexp RPAREN (let
|
adamc@236
|
1097 val loc = s (sqlaggleft, RPARENright)
|
adamc@236
|
1098
|
adamc@236
|
1099 val e = (EApp ((EVar (["Basis"], "sql_" ^ sqlagg), loc),
|
adamc@236
|
1100 (EWild, loc)), loc)
|
adamc@236
|
1101 val e = (EApp ((EVar (["Basis"], "sql_aggregate"), loc),
|
adamc@236
|
1102 e), loc)
|
adamc@236
|
1103 in
|
adamc@236
|
1104 (EApp (e, sqlexp), loc)
|
adamc@236
|
1105 end)
|
adamc@235
|
1106
|
adamc@209
|
1107 wopt : (sql_inject (EVar (["Basis"], "True"),
|
adamc@209
|
1108 EVar (["Basis"], "sql_bool"),
|
adamc@230
|
1109 dummy))
|
adamc@209
|
1110 | CWHERE sqlexp (sqlexp)
|
adamc@226
|
1111
|
adamc@226
|
1112 groupi : tident DOT fident (GField (tident, fident))
|
adamc@226
|
1113
|
adamc@226
|
1114 groupis: groupi ([groupi])
|
adamc@226
|
1115 | groupi COMMA groupis (groupi :: groupis)
|
adamc@226
|
1116
|
adamc@226
|
1117 gopt : (NONE)
|
adamc@226
|
1118 | GROUP BY groupis (SOME groupis)
|
adamc@227
|
1119
|
adamc@227
|
1120 hopt : (sql_inject (EVar (["Basis"], "True"),
|
adamc@227
|
1121 EVar (["Basis"], "sql_bool"),
|
adamc@230
|
1122 dummy))
|
adamc@227
|
1123 | HAVING sqlexp (sqlexp)
|
adamc@230
|
1124
|
adamc@230
|
1125 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil"), dummy),
|
adamc@234
|
1126 (CWild (KRecord (KType, dummy), dummy), dummy)),
|
adamc@230
|
1127 dummy)
|
adamc@230
|
1128 | ORDER BY obexps (obexps)
|
adamc@230
|
1129
|
adamc@268
|
1130 obitem : sqlexp diropt (sqlexp, diropt)
|
adamc@268
|
1131
|
adamc@268
|
1132 obexps : obitem (let
|
adamc@268
|
1133 val loc = s (obitemleft, obitemright)
|
adamc@230
|
1134
|
adamc@230
|
1135 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil"), loc),
|
adamc@234
|
1136 (CWild (KRecord (KType, loc), loc), loc)),
|
adamc@230
|
1137 loc)
|
adamc@230
|
1138 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons"), loc),
|
adamc@268
|
1139 #1 obitem), loc)
|
adamc@268
|
1140 val e = (EApp (e, #2 obitem), loc)
|
adamc@230
|
1141 in
|
adamc@230
|
1142 (EApp (e, e'), loc)
|
adamc@230
|
1143 end)
|
adamc@268
|
1144 | obitem COMMA obexps (let
|
adamc@268
|
1145 val loc = s (obitemleft, obexpsright)
|
adamc@230
|
1146
|
adamc@230
|
1147 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons"), loc),
|
adamc@268
|
1148 #1 obitem), loc)
|
adamc@268
|
1149 val e = (EApp (e, #2 obitem), loc)
|
adamc@230
|
1150 in
|
adamc@230
|
1151 (EApp (e, obexps), loc)
|
adamc@230
|
1152 end)
|
adamc@231
|
1153
|
adamc@268
|
1154 diropt : (EVar (["Basis"], "sql_asc"), dummy)
|
adamc@268
|
1155 | ASC (EVar (["Basis"], "sql_asc"), s (ASCleft, ASCright))
|
adamc@268
|
1156 | DESC (EVar (["Basis"], "sql_desc"), s (DESCleft, DESCright))
|
adamc@268
|
1157
|
adamc@231
|
1158 lopt : (EVar (["Basis"], "sql_no_limit"), dummy)
|
adamc@232
|
1159 | LIMIT ALL (EVar (["Basis"], "sql_no_limit"), dummy)
|
adamc@231
|
1160 | LIMIT sqlint (let
|
adamc@231
|
1161 val loc = s (LIMITleft, sqlintright)
|
adamc@231
|
1162 in
|
adamc@231
|
1163 (EApp ((EVar (["Basis"], "sql_limit"), loc), sqlint), loc)
|
adamc@231
|
1164 end)
|
adamc@231
|
1165
|
adamc@232
|
1166 ofopt : (EVar (["Basis"], "sql_no_offset"), dummy)
|
adamc@232
|
1167 | OFFSET sqlint (let
|
adamc@232
|
1168 val loc = s (OFFSETleft, sqlintright)
|
adamc@232
|
1169 in
|
adamc@232
|
1170 (EApp ((EVar (["Basis"], "sql_offset"), loc), sqlint), loc)
|
adamc@232
|
1171 end)
|
adamc@232
|
1172
|
adamc@231
|
1173 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@231
|
1174 | LBRACE eexp RBRACE (eexp)
|
adamc@236
|
1175
|
adamc@236
|
1176 sqlagg : AVG ("avg")
|
adamc@236
|
1177 | SUM ("sum")
|
adamc@236
|
1178 | MIN ("min")
|
adamc@236
|
1179 | MAX ("max")
|