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