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