adam@1751
|
1 (* Copyright (c) 2008-2012, 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@1194
|
45 | Exp of con option * exp
|
adamc@341
|
46 | Fields of con * con
|
adam@1627
|
47 | StarFields of con
|
adamc@207
|
48
|
adamc@207
|
49 datatype select =
|
adamc@207
|
50 Star
|
adamc@207
|
51 | Items of select_item list
|
adamc@207
|
52
|
adamc@226
|
53 datatype group_item =
|
adamc@226
|
54 GField of con * con
|
adam@1425
|
55 | GFields of con * con
|
adamc@226
|
56
|
adamc@207
|
57 fun eqTnames ((c1, _), (c2, _)) =
|
adamc@207
|
58 case (c1, c2) of
|
adamc@207
|
59 (CVar (ms1, x1), CVar (ms2, x2)) => ms1 = ms2 andalso x1 = x2
|
adamc@207
|
60 | (CName x1, CName x2) => x1 = x2
|
adamc@207
|
61 | _ => false
|
adamc@207
|
62
|
adam@1424
|
63 fun nameString (c, _) =
|
adam@1424
|
64 case c of
|
adam@1424
|
65 CName s => s
|
adam@1424
|
66 | CVar (_, x) => x
|
adam@1424
|
67 | _ => "?"
|
adam@1424
|
68
|
adam@1627
|
69 datatype tableMode =
|
adam@1627
|
70 Unknown
|
adam@1627
|
71 | Everything
|
adam@1627
|
72 | Selective of con
|
adam@1627
|
73
|
adamc@1194
|
74 fun amend_select loc (si, (count, tabs, exps)) =
|
adamc@233
|
75 case si of
|
adamc@233
|
76 Field (tx, fx) =>
|
adamc@233
|
77 let
|
adamc@233
|
78 val c = (CRecord ([(fx, (CWild (KType, loc), loc))]), loc)
|
adamc@207
|
79
|
adamc@233
|
80 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
|
adamc@233
|
81 if eqTnames (tx, tx') then
|
adam@1627
|
82 case c' of
|
adam@1627
|
83 Everything =>
|
adam@1627
|
84 (ErrorMsg.errorAt loc
|
adam@1627
|
85 "Mixing specific-field and '*' selection of fields from same table";
|
adam@1627
|
86 ((tx', c'), found))
|
adam@1627
|
87 | Unknown =>
|
adam@1627
|
88 ((tx', Selective c), true)
|
adam@1627
|
89 | Selective c' =>
|
adam@1627
|
90 ((tx', Selective (CConcat (c, c'), loc)), true)
|
adamc@233
|
91 else
|
adamc@233
|
92 ((tx', c'), found))
|
adamc@233
|
93 false tabs
|
adamc@233
|
94 in
|
adamc@233
|
95 if found then
|
adamc@233
|
96 ()
|
adamc@233
|
97 else
|
adam@1424
|
98 ErrorMsg.errorAt loc ("Select of field " ^ nameString fx ^ " from unbound table " ^ nameString tx);
|
adamc@233
|
99
|
adamc@1194
|
100 (count, tabs, exps)
|
adamc@233
|
101 end
|
adamc@341
|
102 | Fields (tx, fs) =>
|
adamc@341
|
103 let
|
adamc@341
|
104 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
|
adamc@341
|
105 if eqTnames (tx, tx') then
|
adam@1627
|
106 case c' of
|
adam@1627
|
107 Everything =>
|
adam@1627
|
108 (ErrorMsg.errorAt loc
|
adam@1627
|
109 "Mixing specific-field and '*' selection of fields from same table";
|
adam@1627
|
110 ((tx', c'), found))
|
adam@1627
|
111 | Selective c' =>
|
adam@1627
|
112 ((tx', Selective (CConcat (fs, c'), loc)), true)
|
adam@1627
|
113 | Unknown =>
|
adam@1627
|
114 ((tx', Selective fs), true)
|
adamc@341
|
115 else
|
adamc@341
|
116 ((tx', c'), found))
|
adamc@341
|
117 false tabs
|
adamc@341
|
118 in
|
adamc@341
|
119 if found then
|
adamc@341
|
120 ()
|
adamc@341
|
121 else
|
adamc@341
|
122 ErrorMsg.errorAt loc "Select of field from unbound table";
|
adamc@341
|
123
|
adamc@1194
|
124 (count, tabs, exps)
|
adamc@341
|
125 end
|
adam@1627
|
126 | StarFields tx =>
|
adam@1627
|
127 if List.exists (fn (tx', c') => eqTnames (tx, tx') andalso case c' of
|
adam@1627
|
128 Unknown => false
|
adam@1627
|
129 | _ => true) tabs then
|
adam@1627
|
130 (ErrorMsg.errorAt loc "Selection with '*' from table already mentioned in same SELECT clause";
|
adam@1627
|
131 (count, tabs, exps))
|
adam@1627
|
132 else if List.all (fn (tx', c') => not (eqTnames (tx, tx'))) tabs then
|
adam@1627
|
133 (ErrorMsg.errorAt loc "Select of all fields from unbound table";
|
adam@1627
|
134 (count, tabs, exps))
|
adam@1627
|
135 else
|
adam@1627
|
136 (count, map (fn (tx', c') => (tx', if eqTnames (tx, tx') then Everything else c')) tabs, exps)
|
adamc@1194
|
137 | Exp (SOME c, e) => (count, tabs, (c, e) :: exps)
|
adamc@1194
|
138 | Exp (NONE, e) => (count+1, tabs, ((CName (Int.toString count), loc), e) :: exps)
|
adamc@207
|
139
|
adamc@226
|
140 fun amend_group loc (gi, tabs) =
|
adamc@226
|
141 let
|
adamc@226
|
142 val (tx, c) = case gi of
|
adamc@226
|
143 GField (tx, fx) => (tx, (CRecord ([(fx, (CWild (KType, loc), loc))]), loc))
|
adam@1425
|
144 | GFields (tx, fxs) => (tx, fxs)
|
adamc@226
|
145
|
adamc@226
|
146 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
|
adamc@226
|
147 if eqTnames (tx, tx') then
|
adamc@226
|
148 ((tx', (CConcat (c, c'), loc)), true)
|
adamc@226
|
149 else
|
adamc@226
|
150 ((tx', c'), found))
|
adam@1425
|
151 false tabs
|
adamc@226
|
152 in
|
adamc@226
|
153 if found then
|
adamc@226
|
154 ()
|
adamc@226
|
155 else
|
adamc@226
|
156 ErrorMsg.errorAt loc "Select of field from unbound table";
|
adamc@226
|
157
|
adamc@226
|
158 tabs
|
adamc@226
|
159 end
|
adamc@226
|
160
|
adamc@403
|
161 fun sql_inject (v, loc) =
|
adamc@403
|
162 (EApp ((EVar (["Basis"], "sql_inject", Infer), loc), (v, loc)), loc)
|
adamc@209
|
163
|
adamc@220
|
164 fun sql_binary (oper, sqlexp1, sqlexp2, loc) =
|
adamc@220
|
165 let
|
adamc@403
|
166 val e = (EVar (["Basis"], "sql_binary", Infer), loc)
|
adamc@403
|
167 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
|
adamc@220
|
168 val e = (EApp (e, sqlexp1), loc)
|
adamc@220
|
169 in
|
adamc@220
|
170 (EApp (e, sqlexp2), loc)
|
adamc@220
|
171 end
|
adamc@220
|
172
|
adamc@220
|
173 fun sql_unary (oper, sqlexp, loc) =
|
adamc@220
|
174 let
|
adamc@403
|
175 val e = (EVar (["Basis"], "sql_unary", Infer), loc)
|
adamc@403
|
176 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
|
adamc@220
|
177 in
|
adamc@220
|
178 (EApp (e, sqlexp), loc)
|
adamc@219
|
179 end
|
adamc@219
|
180
|
adam@1427
|
181 fun sql_relop (oper, all, sqlexp1, sqlexp2, loc) =
|
adamc@229
|
182 let
|
adamc@403
|
183 val e = (EVar (["Basis"], "sql_relop", Infer), loc)
|
adamc@403
|
184 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
|
adam@1427
|
185 val e = (EApp (e, (EVar (["Basis"], if all then "True" else "False", Infer), loc)), loc)
|
adamc@229
|
186 val e = (EApp (e, sqlexp1), loc)
|
adamc@229
|
187 in
|
adamc@229
|
188 (EApp (e, sqlexp2), loc)
|
adamc@229
|
189 end
|
adamc@229
|
190
|
adamc@441
|
191 fun sql_nfunc (oper, loc) =
|
adamc@441
|
192 let
|
adamc@441
|
193 val e = (EVar (["Basis"], "sql_nfunc", Infer), loc)
|
adamc@441
|
194 in
|
adamc@441
|
195 (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
|
adamc@441
|
196 end
|
adamc@441
|
197
|
adamc@389
|
198 fun native_unop (oper, e1, loc) =
|
adamc@389
|
199 let
|
adamc@403
|
200 val e = (EVar (["Basis"], oper, Infer), loc)
|
adamc@389
|
201 in
|
adamc@389
|
202 (EApp (e, e1), loc)
|
adamc@389
|
203 end
|
adamc@389
|
204
|
adamc@256
|
205 fun native_op (oper, e1, e2, loc) =
|
adamc@256
|
206 let
|
adamc@403
|
207 val e = (EVar (["Basis"], oper, Infer), loc)
|
adamc@256
|
208 val e = (EApp (e, e1), loc)
|
adamc@256
|
209 in
|
adamc@256
|
210 (EApp (e, e2), loc)
|
adamc@256
|
211 end
|
adamc@256
|
212
|
adamc@310
|
213 val inDml = ref false
|
adamc@310
|
214
|
adamc@325
|
215 fun tagIn bt =
|
adamc@325
|
216 case bt of
|
adamc@325
|
217 "table" => "tabl"
|
adamc@325
|
218 | _ => bt
|
adamc@325
|
219
|
adamc@709
|
220 datatype prop_kind = Delete | Update
|
adamc@709
|
221
|
adam@1751
|
222 datatype attr = Class of exp | DynClass of exp | Style of exp | DynStyle of exp | Normal of con * exp
|
adamc@721
|
223
|
adamc@822
|
224 fun patType loc (p : pat) =
|
adamc@822
|
225 case #1 p of
|
adamc@822
|
226 PAnnot (_, t) => t
|
adamc@822
|
227 | _ => (CWild (KType, loc), loc)
|
adamc@822
|
228
|
adamc@1265
|
229 fun tnamesOf (e, _) =
|
adamc@1265
|
230 case e of
|
adamc@1265
|
231 EApp (e1, e2) => tnamesOf e1 @ tnamesOf e2
|
adamc@1265
|
232 | ECApp (e, c as (CName _, _)) =>
|
adamc@1265
|
233 let
|
adamc@1265
|
234 fun isFt (e, _) =
|
adamc@1265
|
235 case e of
|
adamc@1265
|
236 EVar (["Basis"], "sql_from_table", _) => true
|
adamc@1265
|
237 | EVar ([], "sql_from_table", _) => true
|
adamc@1265
|
238 | ECApp (e, _) => isFt e
|
adamc@1265
|
239 | EApp (e, _) => isFt e
|
adamc@1265
|
240 | EDisjointApp e => isFt e
|
adamc@1265
|
241 | _ => false
|
adamc@1265
|
242 in
|
adamc@1265
|
243 (if isFt e then [c] else []) @ tnamesOf e
|
adamc@1265
|
244 end
|
adamc@1265
|
245 | ECApp (e, _) => tnamesOf e
|
adamc@1265
|
246 | EDisjointApp e => tnamesOf e
|
adamc@1265
|
247 | _ => []
|
adamc@1265
|
248
|
adam@1761
|
249 fun classOut (s, pos) =
|
adam@1761
|
250 let
|
adam@1761
|
251 val s = case s of
|
adam@1761
|
252 "table" => "tabl"
|
adam@1761
|
253 | _ => s
|
adam@1761
|
254 in
|
adam@1761
|
255 (EVar ([], String.translate (fn #"-" => "_" | ch => str ch) s, Infer), pos)
|
adam@1761
|
256 end
|
adam@1749
|
257
|
adam@1749
|
258 fun parseClass s pos =
|
adam@1749
|
259 case String.tokens Char.isSpace s of
|
adam@1749
|
260 [] => (EVar (["Basis"], "null", Infer), pos)
|
adam@1749
|
261 | class :: classes =>
|
adam@1749
|
262 foldl (fn (s, e) => (EApp ((EApp ((EVar (["Basis"], "classes", Infer), pos), e), pos), classOut (s, pos)), pos))
|
adam@1749
|
263 (classOut (class, pos)) classes
|
adam@1749
|
264
|
adam@1750
|
265 fun parseValue s pos =
|
adam@1750
|
266 if String.isPrefix "url(" s andalso String.isSuffix ")" s then
|
adam@1750
|
267 let
|
adam@1750
|
268 val s = String.substring (s, 4, size s - 5)
|
adam@1750
|
269
|
adam@1750
|
270 val s = if size s >= 2
|
adam@1750
|
271 andalso ((String.isPrefix "\"" s andalso String.isSuffix "\"" s)
|
adam@1750
|
272 orelse (String.isPrefix "'" s andalso String.isSuffix "'" s)) then
|
adam@1750
|
273 String.substring (s, 1, size s - 2)
|
adam@1750
|
274 else
|
adam@1750
|
275 s
|
adam@1750
|
276 in
|
adam@1750
|
277 (EApp ((EVar (["Basis"], "css_url", Infer), pos),
|
adam@1750
|
278 (EApp ((EVar (["Basis"], "bless", Infer), pos),
|
adam@1750
|
279 (EPrim (Prim.String s), pos)), pos)), pos)
|
adam@1750
|
280 end
|
adam@1750
|
281 else
|
adam@1750
|
282 (EApp ((EVar (["Basis"], "atom", Infer), pos),
|
adam@1750
|
283 (EPrim (Prim.String s), pos)), pos)
|
adam@1750
|
284
|
adam@1750
|
285 fun parseProperty s pos =
|
adam@1750
|
286 let
|
adam@1750
|
287 val (befor, after) = Substring.splitl (fn ch => ch <> #":") (Substring.full s)
|
adam@1750
|
288 in
|
adam@1750
|
289 if Substring.isEmpty after then
|
adam@1750
|
290 (ErrorMsg.errorAt pos ("Invalid CSS property syntax: " ^ s);
|
adam@1750
|
291 (EPrim (Prim.String ""), pos))
|
adam@1750
|
292 else
|
adam@1750
|
293 foldl (fn (value, e) => (EApp ((EApp ((EVar (["Basis"], "value", Infer), pos), e), pos), parseValue value pos), pos))
|
adam@1750
|
294 (EApp ((EVar (["Basis"], "property", Infer), pos),
|
adam@1750
|
295 (EPrim (Prim.String (Substring.string (#2 (Substring.splitl Char.isSpace befor)))), pos)), pos)
|
adam@1750
|
296 (String.tokens Char.isSpace (Substring.string (Substring.slice (after, 1, NONE))))
|
adam@1750
|
297 end
|
adam@1750
|
298
|
adam@1750
|
299 fun parseStyle s pos =
|
adam@1750
|
300 case String.tokens (fn ch => ch = #";") s of
|
adam@1750
|
301 [] => (EVar (["Basis"], "noStyle", Infer), pos)
|
adam@1750
|
302 | props =>
|
adam@1750
|
303 foldl (fn (s, e) => (EApp ((EApp ((EVar (["Basis"], "oneProperty", Infer), pos), e), pos), parseProperty s pos), pos))
|
adam@1750
|
304 (EVar (["Basis"], "noStyle", Infer), pos) props
|
adam@1750
|
305
|
adam@1777
|
306 fun applyWindow loc e window =
|
adam@1777
|
307 let
|
adam@1777
|
308 val (pb, ob) = getOpt (window, ((EVar (["Basis"], "sql_no_partition", Infer), dummy),
|
adam@1777
|
309 (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
|
adam@1777
|
310 (CWild (KRecord (KType, dummy), dummy), dummy)),
|
adam@1777
|
311 dummy)))
|
adam@1777
|
312 val e' = (EVar (["Basis"], "sql_window", Infer), loc)
|
adam@1777
|
313 val e' = (EApp (e', e), loc)
|
adam@1777
|
314 val e' = (EApp (e', pb), loc)
|
adam@1777
|
315 in
|
adam@1777
|
316 (EApp (e', ob), loc)
|
adam@1777
|
317 end
|
adam@1777
|
318
|
adamc@1
|
319 %%
|
adamc@244
|
320 %header (functor UrwebLrValsFn(structure Token : TOKEN))
|
adamc@1
|
321
|
adamc@1
|
322 %term
|
adamc@1
|
323 EOF
|
adamc@821
|
324 | STRING of string | INT of Int64.int | FLOAT of Real64.real | CHAR of char
|
adamc@1
|
325 | SYMBOL of string | CSYMBOL of string
|
adamc@1
|
326 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
|
adam@1306
|
327 | EQ | COMMA | COLON | DCOLON | DCOLONWILD | TCOLON | TCOLONWILD | DOT | HASH | UNDER | UNDERUNDER | BAR
|
adamc@403
|
328 | PLUS | MINUS | DIVIDE | DOTDOTDOT | MOD | AT
|
adamc@623
|
329 | CON | LTYPE | VAL | REC | AND | FUN | MAP | UNIT | KUNIT | CLASS
|
adamc@156
|
330 | DATATYPE | OF
|
adamc@7
|
331 | TYPE | NAME
|
adamc@629
|
332 | ARROW | LARROW | DARROW | STAR | SEMI | KARROW | DKARROW | BANG
|
adamc@674
|
333 | FN | PLUSPLUS | MINUSMINUS | MINUSMINUSMINUS | DOLLAR | TWIDDLE | CARET
|
adamc@446
|
334 | LET | IN
|
adam@1732
|
335 | STRUCTURE | SIGNATURE | STRUCT | SIG | END | FUNCTOR | WHERE | SQL | SELECT1
|
adamc@754
|
336 | INCLUDE | OPEN | CONSTRAINT | CONSTRAINTS | EXPORT | TABLE | SEQUENCE | VIEW
|
adamc@1199
|
337 | COOKIE | STYLE | TASK | POLICY
|
adamc@842
|
338 | CASE | IF | THEN | ELSE | ANDALSO | ORELSE
|
adamc@1
|
339
|
adamc@360
|
340 | XML_BEGIN of string | XML_END | XML_BEGIN_END of string
|
adamc@91
|
341 | NOTAGS of string
|
adamc@91
|
342 | BEGIN_TAG of string | END_TAG of string
|
adamc@91
|
343
|
adamc@993
|
344 | SELECT | DISTINCT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING
|
adamc@229
|
345 | UNION | INTERSECT | EXCEPT
|
adamc@232
|
346 | LIMIT | OFFSET | ALL
|
adamc@220
|
347 | TRUE | FALSE | CAND | OR | NOT
|
adam@1776
|
348 | COUNT | AVG | SUM | MIN | MAX | RANK
|
adam@1682
|
349 | ASC | DESC | RANDOM
|
kkallio@1607
|
350 | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS | COALESCE | LIKE
|
adamc@441
|
351 | CURRENT_TIMESTAMP
|
adamc@219
|
352 | NE | LT | LE | GT | GE
|
adamc@714
|
353 | CCONSTRAINT | UNIQUE | CHECK | PRIMARY | FOREIGN | KEY | ON | NO | ACTION | RESTRICT | CASCADE | REFERENCES
|
adamc@751
|
354 | JOIN | INNER | CROSS | OUTER | LEFT | RIGHT | FULL
|
kkallio@1572
|
355 | CIF | CTHEN | CELSE
|
adam@1776
|
356 | OVER | PARTITION
|
adamc@204
|
357
|
adamc@30
|
358 %nonterm
|
adamc@1
|
359 file of decl list
|
adamc@1
|
360 | decls of decl list
|
adamc@325
|
361 | decl of decl list
|
adamc@123
|
362 | vali of string * con option * exp
|
adamc@123
|
363 | valis of (string * con option * exp) list
|
adamc@242
|
364 | copt of con option
|
adamc@1
|
365
|
adamc@191
|
366 | dargs of string list
|
adamc@156
|
367 | barOpt of unit
|
adamc@156
|
368 | dcons of (string * con option) list
|
adamc@805
|
369 | dtype of string * string list * (string * con option) list
|
adamc@805
|
370 | dtypes of (string * string list * (string * con option) list) list
|
adamc@156
|
371 | dcon of string * con option
|
adamc@156
|
372
|
adamc@707
|
373 | pkopt of exp
|
adam@1722
|
374 | pk of exp
|
adamc@707
|
375 | commaOpt of unit
|
adamc@707
|
376
|
adamc@704
|
377 | cst of exp
|
adamc@704
|
378 | csts of exp
|
adamc@704
|
379 | cstopt of exp
|
adamc@704
|
380
|
adamc@1001
|
381 | ckl of (string * kind option) list
|
adamc@1001
|
382
|
adamc@709
|
383 | pmode of prop_kind * exp
|
adamc@709
|
384 | pkind of prop_kind
|
adamc@709
|
385 | prule of exp
|
adamc@709
|
386 | pmodes of (prop_kind * exp) list
|
adamc@709
|
387
|
adamc@30
|
388 | sgn of sgn
|
adamc@42
|
389 | sgntm of sgn
|
adamc@30
|
390 | sgi of sgn_item
|
adamc@30
|
391 | sgis of sgn_item list
|
adamc@30
|
392
|
adamc@30
|
393 | str of str
|
adamc@30
|
394
|
adamc@1
|
395 | kind of kind
|
adamc@207
|
396 | ktuple of kind list
|
adamc@1
|
397 | kcolon of explicitness
|
adamc@240
|
398 | kopt of kind option
|
adamc@1
|
399
|
adamc@34
|
400 | path of string list * string
|
adamc@156
|
401 | cpath of string list * string
|
adamc@34
|
402 | spath of str
|
adamc@59
|
403 | mpath of string list
|
adamc@34
|
404
|
adamc@1
|
405 | cexp of con
|
adam@1577
|
406 | cexpO of con option
|
adamc@1
|
407 | capps of con
|
adamc@1
|
408 | cterm of con
|
adamc@195
|
409 | ctuple of con list
|
adamc@207
|
410 | ctuplev of con list
|
adamc@1
|
411 | ident of con
|
adamc@200
|
412 | idents of con list
|
adamc@1
|
413 | rcon of (con * con) list
|
adamc@83
|
414 | rconn of (con * con) list
|
adamc@1
|
415 | rcone of (con * con) list
|
adamc@239
|
416 | cargs of con * kind -> con * kind
|
adamc@239
|
417 | cargl of con * kind -> con * kind
|
adamc@240
|
418 | cargl2 of con * kind -> con * kind
|
adamc@239
|
419 | carg of con * kind -> con * kind
|
adamc@239
|
420 | cargp of con * kind -> con * kind
|
adamc@1
|
421
|
adamc@8
|
422 | eexp of exp
|
adamc@8
|
423 | eapps of exp
|
adamc@8
|
424 | eterm of exp
|
adamc@195
|
425 | etuple of exp list
|
adamc@12
|
426 | rexp of (con * exp) list
|
adamc@91
|
427 | xml of exp
|
adamc@91
|
428 | xmlOne of exp
|
adamc@1045
|
429 | xmlOpt of exp
|
adam@1643
|
430 | tag of (string * exp) * exp option * exp option * exp
|
adamc@141
|
431 | tagHead of string * exp
|
adamc@434
|
432 | bind of string * con option * exp
|
adamc@446
|
433 | edecl of edecl
|
adamc@446
|
434 | edecls of edecl list
|
adamc@8
|
435
|
adamc@241
|
436 | earg of exp * con -> exp * con
|
adamc@241
|
437 | eargp of exp * con -> exp * con
|
adamc@822
|
438 | earga of exp * con -> exp * con
|
adamc@241
|
439 | eargs of exp * con -> exp * con
|
adamc@241
|
440 | eargl of exp * con -> exp * con
|
adamc@242
|
441 | eargl2 of exp * con -> exp * con
|
adamc@241
|
442
|
adamc@170
|
443 | branch of pat * exp
|
adamc@170
|
444 | branchs of (pat * exp) list
|
adamc@170
|
445 | pat of pat
|
adamc@822
|
446 | patS of pat
|
adamc@170
|
447 | pterm of pat
|
adamc@174
|
448 | rpat of (string * pat) list * bool
|
adamc@195
|
449 | ptuple of pat list
|
adamc@170
|
450
|
adam@1751
|
451 | attrs of exp option * exp option * exp option * exp option * (con * exp) list
|
adamc@721
|
452 | attr of attr
|
adamc@104
|
453 | attrv of exp
|
adamc@104
|
454
|
adamc@204
|
455 | query of exp
|
adamc@226
|
456 | query1 of exp
|
adamc@993
|
457 | dopt of exp
|
adamc@748
|
458 | tables of con list * exp
|
adamc@749
|
459 | fitem of con list * exp
|
adamc@204
|
460 | tname of con
|
adamc@705
|
461 | tnameW of con * con
|
adamc@705
|
462 | tnames of (con * con) * (con * con) list
|
adamc@705
|
463 | tnames' of (con * con) * (con * con) list
|
adamc@204
|
464 | table of con * exp
|
adamc@748
|
465 | table' of con * exp
|
adamc@207
|
466 | tident of con
|
adamc@207
|
467 | fident of con
|
adamc@207
|
468 | seli of select_item
|
adamc@207
|
469 | selis of select_item list
|
adamc@207
|
470 | select of select
|
adamc@209
|
471 | sqlexp of exp
|
adam@1777
|
472 | window of (exp * exp) option
|
adam@1777
|
473 | pbopt of exp
|
adamc@209
|
474 | wopt of exp
|
adamc@226
|
475 | groupi of group_item
|
adamc@226
|
476 | groupis of group_item list
|
adamc@226
|
477 | gopt of group_item list option
|
adamc@227
|
478 | hopt of exp
|
adamc@230
|
479 | obopt of exp
|
adamc@268
|
480 | obitem of exp * exp
|
adamc@230
|
481 | obexps of exp
|
adam@1682
|
482 | popt of unit
|
adamc@268
|
483 | diropt of exp
|
adamc@231
|
484 | lopt of exp
|
adamc@232
|
485 | ofopt of exp
|
adamc@231
|
486 | sqlint of exp
|
adamc@236
|
487 | sqlagg of string
|
adamc@746
|
488 | fname of exp
|
adamc@207
|
489
|
adamc@302
|
490 | texp of exp
|
adamc@302
|
491 | fields of con list
|
adamc@302
|
492 | sqlexps of exp list
|
adamc@303
|
493 | fsets of (con * exp) list
|
adamc@310
|
494 | enterDml of unit
|
adamc@310
|
495 | leaveDml of unit
|
adamc@302
|
496
|
adamc@204
|
497
|
adamc@1
|
498 %verbose (* print summary of errors *)
|
adamc@1
|
499 %pos int (* positions *)
|
adamc@1
|
500 %start file
|
adamc@1
|
501 %pure
|
adamc@1
|
502 %eop EOF
|
adamc@1
|
503 %noshift EOF
|
adamc@1
|
504
|
adamc@244
|
505 %name Urweb
|
adamc@1
|
506
|
adamc@623
|
507 %right KARROW
|
adamc@623
|
508 %nonassoc DKARROW
|
adamc@243
|
509 %right SEMI
|
adamc@243
|
510 %nonassoc LARROW
|
adamc@195
|
511 %nonassoc IF THEN ELSE
|
adamc@843
|
512 %nonassoc DARROW
|
adamc@842
|
513 %left ANDALSO
|
adamc@842
|
514 %left ORELSE
|
adamc@1
|
515 %nonassoc COLON
|
adam@1306
|
516 %nonassoc DCOLON TCOLON DCOLONWILD TCOLONWILD
|
adam@1427
|
517 %left UNION INTERSECT EXCEPT ALL
|
adamc@1
|
518 %right COMMA
|
adamc@751
|
519 %right JOIN INNER CROSS OUTER LEFT RIGHT FULL
|
adamc@220
|
520 %right OR
|
adamc@220
|
521 %right CAND
|
adamc@470
|
522 %nonassoc EQ NE LT LE GT GE IS
|
adamc@243
|
523 %right ARROW
|
adamc@837
|
524 %right CARET PLUSPLUS
|
adamc@837
|
525 %left MINUSMINUS MINUSMINUSMINUS
|
adamc@389
|
526 %left PLUS MINUS
|
adamc@389
|
527 %left STAR DIVIDE MOD
|
adamc@220
|
528 %left NOT
|
adamc@84
|
529 %nonassoc TWIDDLE
|
adamc@1
|
530 %nonassoc DOLLAR
|
adamc@1
|
531 %left DOT
|
adamc@221
|
532 %nonassoc LBRACE RBRACE
|
adamc@1
|
533
|
adamc@1
|
534 %%
|
adamc@1
|
535
|
adamc@1
|
536 file : decls (decls)
|
adamc@54
|
537 | SIG sgis ([(DSgn ("?", (SgnConst sgis, s (SIGleft, sgisright))),
|
adamc@54
|
538 s (SIGleft, sgisright))])
|
adamc@1
|
539
|
adamc@1
|
540 decls : ([])
|
adamc@325
|
541 | decl decls (decl @ decls)
|
adamc@1
|
542
|
adamc@240
|
543 decl : CON SYMBOL cargl2 kopt EQ cexp (let
|
adamc@240
|
544 val loc = s (CONleft, cexpright)
|
adamc@240
|
545
|
adamc@240
|
546 val k = Option.getOpt (kopt, (KWild, loc))
|
adamc@240
|
547 val (c, k) = cargl2 (cexp, k)
|
adamc@240
|
548 in
|
adamc@325
|
549 [(DCon (SYMBOL, SOME k, c), loc)]
|
adamc@240
|
550 end)
|
adam@1654
|
551 | LTYPE SYMBOL cargl2 EQ cexp (let
|
adam@1654
|
552 val loc = s (LTYPEleft, cexpright)
|
adam@1654
|
553
|
adam@1654
|
554 val k = (KWild, loc)
|
adam@1654
|
555 val (c, k) = cargl2 (cexp, k)
|
adam@1654
|
556 in
|
adam@1654
|
557 [(DCon (SYMBOL, SOME k, c), loc)]
|
adam@1654
|
558 end)
|
adamc@805
|
559 | DATATYPE dtypes ([(DDatatype dtypes, s (DATATYPEleft, dtypesright))])
|
adamc@191
|
560 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
|
adamc@191
|
561 (case dargs of
|
adamc@325
|
562 [] => [(DDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))]
|
adamc@191
|
563 | _ => raise Fail "Arguments specified for imported datatype")
|
adamc@325
|
564 | VAL vali ([(DVal vali, s (VALleft, valiright))])
|
adamc@325
|
565 | VAL REC valis ([(DValRec valis, s (VALleft, valisright))])
|
adamc@325
|
566 | FUN valis ([(DValRec valis, s (FUNleft, valisright))])
|
adamc@1
|
567
|
adamc@325
|
568 | SIGNATURE CSYMBOL EQ sgn ([(DSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))])
|
adam@1732
|
569 | STRUCTURE CSYMBOL EQ str ([(DStr (CSYMBOL, NONE, NONE, str), s (STRUCTUREleft, strright))])
|
adam@1732
|
570 | STRUCTURE CSYMBOL COLON sgn EQ str ([(DStr (CSYMBOL, SOME sgn, NONE, str), s (STRUCTUREleft, strright))])
|
adamc@42
|
571 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN EQ str
|
adam@1732
|
572 ([(DStr (CSYMBOL1, NONE, NONE,
|
adamc@325
|
573 (StrFun (CSYMBOL2, sgn1, NONE, str), s (FUNCTORleft, strright))),
|
adamc@325
|
574 s (FUNCTORleft, strright))])
|
adamc@42
|
575 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn EQ str
|
adam@1732
|
576 ([(DStr (CSYMBOL1, NONE, NONE,
|
adamc@325
|
577 (StrFun (CSYMBOL2, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))),
|
adamc@325
|
578 s (FUNCTORleft, strright))])
|
adamc@61
|
579 | OPEN mpath (case mpath of
|
adamc@61
|
580 [] => raise Fail "Impossible mpath parse [1]"
|
adamc@325
|
581 | m :: ms => [(DOpen (m, ms), s (OPENleft, mpathright))])
|
adamc@325
|
582 | OPEN mpath LPAREN str RPAREN (let
|
adamc@325
|
583 val loc = s (OPENleft, RPARENright)
|
adamc@325
|
584
|
adamc@325
|
585 val m = case mpath of
|
adamc@325
|
586 [] => raise Fail "Impossible mpath parse [4]"
|
adamc@325
|
587 | m :: ms =>
|
adamc@325
|
588 foldl (fn (m, str) => (StrProj (str, m), loc))
|
adamc@325
|
589 (StrVar m, loc) ms
|
adamc@325
|
590 in
|
adam@1732
|
591 [(DStr ("anon", NONE, NONE, (StrApp (m, str), loc)), loc),
|
adamc@325
|
592 (DOpen ("anon", []), loc)]
|
adamc@325
|
593 end)
|
adamc@88
|
594 | OPEN CONSTRAINTS mpath (case mpath of
|
adamc@88
|
595 [] => raise Fail "Impossible mpath parse [3]"
|
adamc@325
|
596 | m :: ms => [(DOpenConstraints (m, ms), s (OPENleft, mpathright))])
|
adamc@325
|
597 | CONSTRAINT cterm TWIDDLE cterm ([(DConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))])
|
adamc@325
|
598 | EXPORT spath ([(DExport spath, s (EXPORTleft, spathright))])
|
adamc@707
|
599 | TABLE SYMBOL COLON cterm pkopt commaOpt cstopt([(DTable (SYMBOL, entable cterm, pkopt, cstopt),
|
adamc@707
|
600 s (TABLEleft, cstoptright))])
|
adamc@338
|
601 | SEQUENCE SYMBOL ([(DSequence SYMBOL, s (SEQUENCEleft, SYMBOLright))])
|
adamc@754
|
602 | VIEW SYMBOL EQ query ([(DView (SYMBOL, query),
|
adamc@754
|
603 s (VIEWleft, queryright))])
|
adamc@754
|
604 | VIEW SYMBOL EQ LBRACE eexp RBRACE ([(DView (SYMBOL, eexp),
|
adamc@754
|
605 s (VIEWleft, RBRACEright))])
|
adamc@563
|
606 | CLASS SYMBOL EQ cexp (let
|
adamc@563
|
607 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
608 in
|
adamc@563
|
609 [(DClass (SYMBOL, (KWild, loc), cexp), loc)]
|
adamc@563
|
610 end)
|
adamc@563
|
611 | CLASS SYMBOL DCOLON kind EQ cexp ([(DClass (SYMBOL, kind, cexp), s (CLASSleft, cexpright))])
|
adamc@211
|
612 | CLASS SYMBOL SYMBOL EQ cexp (let
|
adamc@211
|
613 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
614 val k = (KWild, loc)
|
adamc@211
|
615 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
|
adamc@211
|
616 in
|
adamc@563
|
617 [(DClass (SYMBOL1, k, c), s (CLASSleft, cexpright))]
|
adamc@563
|
618 end)
|
adamc@563
|
619 | CLASS SYMBOL LPAREN SYMBOL DCOLON kind RPAREN EQ cexp (let
|
adamc@563
|
620 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
621 val c = (CAbs (SYMBOL2, SOME kind, cexp), loc)
|
adamc@563
|
622 in
|
adamc@563
|
623 [(DClass (SYMBOL1, kind, c), s (CLASSleft, cexpright))]
|
adamc@211
|
624 end)
|
adamc@459
|
625 | COOKIE SYMBOL COLON cexp ([(DCookie (SYMBOL, cexp), s (COOKIEleft, cexpright))])
|
adamc@720
|
626 | STYLE SYMBOL ([(DStyle SYMBOL, s (STYLEleft, SYMBOLright))])
|
adamc@1075
|
627 | TASK eapps EQ eexp ([(DTask (eapps, eexp), s (TASKleft, eexpright))])
|
adamc@1199
|
628 | POLICY eexp ([(DPolicy eexp, s (POLICYleft, eexpright))])
|
adamc@30
|
629
|
adamc@805
|
630 dtype : SYMBOL dargs EQ barOpt dcons (SYMBOL, dargs, dcons)
|
adamc@805
|
631
|
adamc@805
|
632 dtypes : dtype ([dtype])
|
adamc@805
|
633 | dtype AND dtypes (dtype :: dtypes)
|
adamc@805
|
634
|
adamc@240
|
635 kopt : (NONE)
|
adamc@240
|
636 | DCOLON kind (SOME kind)
|
adam@1302
|
637 | DCOLONWILD (SOME (KWild, s (DCOLONWILDleft, DCOLONWILDright)))
|
adamc@240
|
638
|
adamc@191
|
639 dargs : ([])
|
adamc@191
|
640 | SYMBOL dargs (SYMBOL :: dargs)
|
adamc@191
|
641
|
adamc@156
|
642 barOpt : ()
|
adamc@156
|
643 | BAR ()
|
adamc@156
|
644
|
adamc@156
|
645 dcons : dcon ([dcon])
|
adamc@156
|
646 | dcon BAR dcons (dcon :: dcons)
|
adamc@156
|
647
|
adamc@156
|
648 dcon : CSYMBOL (CSYMBOL, NONE)
|
adamc@156
|
649 | CSYMBOL OF cexp (CSYMBOL, SOME cexp)
|
adamc@156
|
650
|
adamc@242
|
651 vali : SYMBOL eargl2 copt EQ eexp (let
|
adamc@242
|
652 val loc = s (SYMBOLleft, eexpright)
|
adamc@242
|
653 val t = Option.getOpt (copt, (CWild (KType, loc), loc))
|
adamc@242
|
654
|
adamc@242
|
655 val (e, t) = eargl2 (eexp, t)
|
adamc@242
|
656 in
|
adamc@242
|
657 (SYMBOL, SOME t, e)
|
adamc@242
|
658 end)
|
adamc@242
|
659
|
adamc@242
|
660 copt : (NONE)
|
adamc@242
|
661 | COLON cexp (SOME cexp)
|
adamc@123
|
662
|
adamc@704
|
663 cstopt : (EVar (["Basis"], "no_constraint", Infer), dummy)
|
adamc@704
|
664 | csts (csts)
|
adamc@704
|
665
|
adamc@704
|
666 csts : CCONSTRAINT tname cst (let
|
adamc@704
|
667 val loc = s (CCONSTRAINTleft, cstright)
|
adamc@704
|
668
|
adamc@704
|
669 val e = (EVar (["Basis"], "one_constraint", Infer), loc)
|
adamc@704
|
670 val e = (ECApp (e, tname), loc)
|
adamc@704
|
671 in
|
adamc@704
|
672 (EApp (e, cst), loc)
|
adamc@704
|
673 end)
|
adamc@704
|
674 | csts COMMA csts (let
|
adamc@704
|
675 val loc = s (csts1left, csts2right)
|
adamc@704
|
676
|
adamc@704
|
677 val e = (EVar (["Basis"], "join_constraints", Infer), loc)
|
adamc@704
|
678 val e = (EApp (e, csts1), loc)
|
adamc@704
|
679 in
|
adamc@704
|
680 (EApp (e, csts2), loc)
|
adamc@704
|
681 end)
|
adamc@704
|
682 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
|
adamc@704
|
683
|
adamc@704
|
684 cst : UNIQUE tnames (let
|
adamc@704
|
685 val loc = s (UNIQUEleft, tnamesright)
|
adamc@704
|
686
|
adamc@704
|
687 val e = (EVar (["Basis"], "unique", Infer), loc)
|
adamc@705
|
688 val e = (ECApp (e, #1 (#1 tnames)), loc)
|
adamc@705
|
689 val e = (ECApp (e, (CRecord (#2 tnames), loc)), loc)
|
adamc@704
|
690 in
|
adamc@1093
|
691 e
|
adamc@704
|
692 end)
|
adamc@709
|
693
|
adamc@714
|
694 | CHECK sqlexp (let
|
adamc@714
|
695 val loc = s (CHECKleft, sqlexpright)
|
adamc@714
|
696 in
|
adamc@714
|
697 (EApp ((EVar (["Basis"], "check", Infer), loc),
|
adamc@714
|
698 sqlexp), loc)
|
adamc@714
|
699 end)
|
adamc@714
|
700
|
adamc@709
|
701 | FOREIGN KEY tnames REFERENCES texp LPAREN tnames' RPAREN pmodes
|
adamc@709
|
702 (let
|
adamc@709
|
703 val loc = s (FOREIGNleft, pmodesright)
|
adamc@709
|
704
|
adamc@709
|
705 val mat = ListPair.foldrEq
|
adamc@709
|
706 (fn ((nm1, _), (nm2, _), mat) =>
|
adamc@709
|
707 let
|
adamc@709
|
708 val e = (EVar (["Basis"], "mat_cons", Infer), loc)
|
adamc@709
|
709 val e = (ECApp (e, nm1), loc)
|
adamc@709
|
710 val e = (ECApp (e, nm2), loc)
|
adamc@709
|
711 in
|
adamc@709
|
712 (EApp (e, mat), loc)
|
adamc@709
|
713 end)
|
adamc@709
|
714 (EVar (["Basis"], "mat_nil", Infer), loc)
|
adamc@709
|
715 (#1 tnames :: #2 tnames, #1 tnames' :: #2 tnames')
|
adam@1401
|
716 handle ListPair.UnequalLengths =>
|
adam@1401
|
717 (ErrorMsg.errorAt loc ("Unequal foreign key list lengths ("
|
adam@1401
|
718 ^ Int.toString (1 + length (#2 tnames))
|
adam@1401
|
719 ^ " vs. "
|
adam@1401
|
720 ^ Int.toString (1 + length (#2 tnames'))
|
adam@1401
|
721 ^ ")");
|
adam@1401
|
722 (EVar (["Basis"], "mat_nil", Infer), loc))
|
adamc@709
|
723
|
adamc@709
|
724 fun findMode mode =
|
adamc@709
|
725 let
|
adamc@709
|
726 fun findMode' pmodes =
|
adamc@709
|
727 case pmodes of
|
adamc@709
|
728 [] => (EVar (["Basis"], "no_action", Infer), loc)
|
adamc@709
|
729 | (mode', rule) :: pmodes' =>
|
adamc@709
|
730 if mode' = mode then
|
adamc@709
|
731 (if List.exists (fn (mode', _) => mode' = mode)
|
adamc@709
|
732 pmodes' then
|
adamc@709
|
733 ErrorMsg.errorAt loc "Duplicate propagation rule"
|
adamc@709
|
734 else
|
adamc@709
|
735 ();
|
adamc@709
|
736 rule)
|
adamc@709
|
737 else
|
adamc@709
|
738 findMode' pmodes'
|
adamc@709
|
739 in
|
adamc@709
|
740 findMode' pmodes
|
adamc@709
|
741 end
|
adamc@709
|
742
|
adamc@709
|
743 val e = (EVar (["Basis"], "foreign_key", Infer), loc)
|
adamc@709
|
744 val e = (EApp (e, mat), loc)
|
adamc@709
|
745 val e = (EApp (e, texp), loc)
|
adamc@709
|
746 in
|
adamc@709
|
747 (EApp (e, (ERecord [((CName "OnDelete", loc),
|
adamc@709
|
748 findMode Delete),
|
adamc@709
|
749 ((CName "OnUpdate", loc),
|
adamc@709
|
750 findMode Update)], loc)), loc)
|
adamc@709
|
751 end)
|
adamc@709
|
752
|
adamc@704
|
753 | LBRACE eexp RBRACE (eexp)
|
adamc@704
|
754
|
adamc@704
|
755 tnameW : tname (let
|
adamc@704
|
756 val loc = s (tnameleft, tnameright)
|
adamc@704
|
757 in
|
adamc@704
|
758 (tname, (CWild (KType, loc), loc))
|
adamc@704
|
759 end)
|
adamc@704
|
760
|
adamc@705
|
761 tnames : tnameW (tnameW, [])
|
adamc@705
|
762 | LPAREN tnames' RPAREN (tnames')
|
adamc@704
|
763
|
adamc@705
|
764 tnames': tnameW (tnameW, [])
|
adamc@705
|
765 | tnameW COMMA tnames' (#1 tnames', tnameW :: #2 tnames')
|
adamc@704
|
766
|
adamc@709
|
767 pmode : ON pkind prule (pkind, prule)
|
adamc@709
|
768
|
adamc@709
|
769 pkind : DELETE (Delete)
|
adamc@709
|
770 | UPDATE (Update)
|
adamc@709
|
771
|
adamc@709
|
772 prule : NO ACTION (EVar (["Basis"], "no_action", Infer), s (NOleft, ACTIONright))
|
adamc@709
|
773 | RESTRICT (EVar (["Basis"], "restrict", Infer), s (RESTRICTleft, RESTRICTright))
|
adamc@709
|
774 | CASCADE (EVar (["Basis"], "cascade", Infer), s (CASCADEleft, CASCADEright))
|
adamc@709
|
775 | SET NULL (EVar (["Basis"], "set_null", Infer), s (SETleft, NULLright))
|
adamc@709
|
776
|
adamc@709
|
777 pmodes : ([])
|
adamc@709
|
778 | pmode pmodes (pmode :: pmodes)
|
adamc@709
|
779
|
adamc@707
|
780 commaOpt: ()
|
adamc@707
|
781 | COMMA ()
|
adamc@707
|
782
|
adam@1722
|
783 pk : LBRACE LBRACE eexp RBRACE RBRACE (eexp)
|
adam@1722
|
784 | tnames (let
|
adam@1722
|
785 val loc = s (tnamesleft, tnamesright)
|
adamc@707
|
786
|
adamc@1093
|
787 val e = (EVar (["Basis"], "primary_key", TypesOnly), loc)
|
adamc@707
|
788 val e = (ECApp (e, #1 (#1 tnames)), loc)
|
adamc@707
|
789 val e = (ECApp (e, (CRecord (#2 tnames), loc)), loc)
|
adamc@707
|
790 val e = (EDisjointApp e, loc)
|
adamc@707
|
791 val e = (EDisjointApp e, loc)
|
adamc@707
|
792
|
adamc@707
|
793 val witness = map (fn (c, _) =>
|
adamc@707
|
794 (c, (EWild, loc)))
|
adamc@707
|
795 (#1 tnames :: #2 tnames)
|
adamc@707
|
796 val witness = (ERecord witness, loc)
|
adamc@707
|
797 in
|
adamc@707
|
798 (EApp (e, witness), loc)
|
adamc@707
|
799 end)
|
adamc@707
|
800
|
adam@1722
|
801 pkopt : (EVar (["Basis"], "no_primary_key", Infer), dummy)
|
adam@1722
|
802 | PRIMARY KEY pk (pk)
|
adam@1722
|
803
|
adamc@123
|
804 valis : vali ([vali])
|
adamc@123
|
805 | vali AND valis (vali :: valis)
|
adamc@123
|
806
|
adamc@42
|
807 sgn : sgntm (sgntm)
|
adamc@40
|
808 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
|
adamc@40
|
809 (SgnFun (CSYMBOL, sgn1, sgn2), s (FUNCTORleft, sgn2right))
|
adamc@30
|
810
|
adamc@42
|
811 sgntm : SIG sgis END (SgnConst sgis, s (SIGleft, ENDright))
|
adamc@59
|
812 | mpath (case mpath of
|
adamc@61
|
813 [] => raise Fail "Impossible mpath parse [2]"
|
adamc@59
|
814 | [x] => SgnVar x
|
adamc@59
|
815 | m :: ms => SgnProj (m,
|
adamc@59
|
816 List.take (ms, length ms - 1),
|
adamc@59
|
817 List.nth (ms, length ms - 1)),
|
adamc@59
|
818 s (mpathleft, mpathright))
|
adamc@42
|
819 | sgntm WHERE CON SYMBOL EQ cexp (SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
|
adamc@42
|
820 | sgntm WHERE LTYPE SYMBOL EQ cexp(SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
|
adamc@42
|
821 | LPAREN sgn RPAREN (sgn)
|
adamc@42
|
822
|
adam@1577
|
823 cexpO : (NONE)
|
adam@1577
|
824 | EQ cexp (SOME cexp)
|
adam@1577
|
825
|
adam@1577
|
826 sgi : LTYPE SYMBOL ((SgiConAbs (SYMBOL, (KType, s (LTYPEleft, SYMBOLright))),
|
adamc@706
|
827 s (LTYPEleft, SYMBOLright)))
|
adam@1577
|
828 | CON SYMBOL cargl2 kopt cexpO (let
|
adam@1577
|
829 val loc = s (CONleft, cexpOright)
|
adam@1574
|
830
|
adam@1574
|
831 val k = Option.getOpt (kopt, (KWild, loc))
|
adam@1574
|
832 in
|
adam@1577
|
833 case cexpO of
|
adam@1577
|
834 NONE => (SgiConAbs (SYMBOL, k), loc)
|
adam@1577
|
835 | SOME cexp =>
|
adam@1577
|
836 let
|
adam@1577
|
837 val (c, k) = cargl2 (cexp, k)
|
adam@1577
|
838 in
|
adam@1577
|
839 (SgiCon (SYMBOL, SOME k, c), loc)
|
adam@1577
|
840 end
|
adam@1574
|
841 end)
|
adam@1654
|
842 | LTYPE SYMBOL cargl2 cexpO (let
|
adam@1654
|
843 val loc = s (LTYPEleft, cexpOright)
|
adam@1654
|
844
|
adam@1654
|
845 val k = (KWild, loc)
|
adam@1654
|
846 in
|
adam@1654
|
847 case cexpO of
|
adam@1654
|
848 NONE => (SgiConAbs (SYMBOL, k), loc)
|
adam@1654
|
849 | SOME cexp =>
|
adam@1654
|
850 let
|
adam@1654
|
851 val (c, k) = cargl2 (cexp, k)
|
adam@1654
|
852 in
|
adam@1654
|
853 (SgiCon (SYMBOL, SOME k, c), loc)
|
adam@1654
|
854 end
|
adam@1654
|
855 end)
|
adamc@805
|
856 | DATATYPE dtypes ((SgiDatatype dtypes, s (DATATYPEleft, dtypesright)))
|
adamc@191
|
857 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
|
adamc@191
|
858 (case dargs of
|
adamc@191
|
859 [] => (SgiDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
|
adamc@191
|
860 | _ => raise Fail "Arguments specified for imported datatype")
|
adamc@706
|
861 | VAL SYMBOL COLON cexp ((SgiVal (SYMBOL, cexp), s (VALleft, cexpright)))
|
adamc@30
|
862
|
adamc@706
|
863 | STRUCTURE CSYMBOL COLON sgn ((SgiStr (CSYMBOL, sgn), s (STRUCTUREleft, sgnright)))
|
adamc@706
|
864 | SIGNATURE CSYMBOL EQ sgn ((SgiSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright)))
|
adamc@42
|
865 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
|
adamc@706
|
866 ((SgiStr (CSYMBOL1,
|
adamc@706
|
867 (SgnFun (CSYMBOL2, sgn1, sgn2), s (FUNCTORleft, sgn2right))),
|
adamc@706
|
868 s (FUNCTORleft, sgn2right)))
|
adamc@706
|
869 | INCLUDE sgn ((SgiInclude sgn, s (INCLUDEleft, sgnright)))
|
adamc@706
|
870 | CONSTRAINT cterm TWIDDLE cterm ((SgiConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright)))
|
adamc@707
|
871 | TABLE SYMBOL COLON cterm pkopt commaOpt cstopt (let
|
adamc@707
|
872 val loc = s (TABLEleft, ctermright)
|
adamc@707
|
873 in
|
adamc@707
|
874 (SgiTable (SYMBOL, entable cterm, pkopt, cstopt), loc)
|
adamc@707
|
875 end)
|
adamc@460
|
876 | SEQUENCE SYMBOL (let
|
adamc@460
|
877 val loc = s (SEQUENCEleft, SYMBOLright)
|
adamc@460
|
878 val t = (CVar (["Basis"], "sql_sequence"), loc)
|
adamc@460
|
879 in
|
adamc@460
|
880 (SgiVal (SYMBOL, t), loc)
|
adamc@460
|
881 end)
|
adamc@754
|
882 | VIEW SYMBOL COLON cexp (let
|
adamc@754
|
883 val loc = s (VIEWleft, cexpright)
|
adamc@754
|
884 val t = (CVar (["Basis"], "sql_view"), loc)
|
adamc@1076
|
885 val t = (CApp (t, entable cexp), loc)
|
adamc@754
|
886 in
|
adamc@754
|
887 (SgiVal (SYMBOL, t), loc)
|
adamc@754
|
888 end)
|
adamc@563
|
889 | CLASS SYMBOL (let
|
adamc@563
|
890 val loc = s (CLASSleft, SYMBOLright)
|
adamc@711
|
891 val k = (KArrow ((KType, loc), (KType, loc)), loc)
|
adamc@563
|
892 in
|
adamc@711
|
893 (SgiClassAbs (SYMBOL, k), loc)
|
adamc@563
|
894 end)
|
adamc@563
|
895 | CLASS SYMBOL DCOLON kind (let
|
adamc@563
|
896 val loc = s (CLASSleft, kindright)
|
adamc@563
|
897 in
|
adamc@563
|
898 (SgiClassAbs (SYMBOL, kind), loc)
|
adamc@563
|
899 end)
|
adamc@563
|
900 | CLASS SYMBOL EQ cexp (let
|
adamc@563
|
901 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
902 in
|
adamc@563
|
903 (SgiClass (SYMBOL, (KWild, loc), cexp), loc)
|
adamc@563
|
904 end)
|
adamc@563
|
905 | CLASS SYMBOL DCOLON kind EQ cexp (let
|
adamc@563
|
906 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
907 in
|
adamc@563
|
908 (SgiClass (SYMBOL, kind, cexp), loc)
|
adamc@563
|
909 end)
|
adamc@211
|
910 | CLASS SYMBOL SYMBOL EQ cexp (let
|
adamc@211
|
911 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
912 val k = (KWild, loc)
|
adamc@211
|
913 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
|
adamc@211
|
914 in
|
adamc@563
|
915 (SgiClass (SYMBOL1, k, c), s (CLASSleft, cexpright))
|
adamc@563
|
916 end)
|
adamc@563
|
917 | CLASS SYMBOL LPAREN SYMBOL DCOLON kind RPAREN EQ cexp (let
|
adamc@563
|
918 val loc = s (CLASSleft, cexpright)
|
adamc@563
|
919 val c = (CAbs (SYMBOL2, SOME kind, cexp), loc)
|
adamc@563
|
920 in
|
adamc@563
|
921 (SgiClass (SYMBOL1, kind, c), s (CLASSleft, cexpright))
|
adamc@211
|
922 end)
|
adamc@460
|
923 | COOKIE SYMBOL COLON cexp (let
|
adamc@460
|
924 val loc = s (COOKIEleft, cexpright)
|
adamc@460
|
925 val t = (CApp ((CVar (["Basis"], "http_cookie"), loc),
|
adamc@460
|
926 entable cexp), loc)
|
adamc@460
|
927 in
|
adamc@460
|
928 (SgiVal (SYMBOL, t), loc)
|
adamc@460
|
929 end)
|
adamc@720
|
930 | STYLE SYMBOL (let
|
adamc@720
|
931 val loc = s (STYLEleft, SYMBOLright)
|
adamc@720
|
932 val t = (CVar (["Basis"], "css_class"), loc)
|
adamc@718
|
933 in
|
adamc@718
|
934 (SgiVal (SYMBOL, t), loc)
|
adamc@718
|
935 end)
|
adamc@30
|
936
|
adamc@30
|
937 sgis : ([])
|
adamc@30
|
938 | sgi sgis (sgi :: sgis)
|
adamc@30
|
939
|
adamc@30
|
940 str : STRUCT decls END (StrConst decls, s (STRUCTleft, ENDright))
|
adamc@34
|
941 | spath (spath)
|
adamc@40
|
942 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN DARROW str
|
adamc@40
|
943 (StrFun (CSYMBOL, sgn, NONE, str), s (FUNCTORleft, strright))
|
adamc@40
|
944 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn DARROW str
|
adamc@40
|
945 (StrFun (CSYMBOL, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))
|
adamc@44
|
946 | spath LPAREN str RPAREN (StrApp (spath, str), s (spathleft, RPARENright))
|
adamc@34
|
947
|
adamc@34
|
948 spath : CSYMBOL (StrVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@34
|
949 | spath DOT CSYMBOL (StrProj (spath, CSYMBOL), s (spathleft, CSYMBOLright))
|
adamc@30
|
950
|
adamc@1
|
951 kind : TYPE (KType, s (TYPEleft, TYPEright))
|
adamc@1
|
952 | NAME (KName, s (NAMEleft, NAMEright))
|
adamc@1
|
953 | LBRACE kind RBRACE (KRecord kind, s (LBRACEleft, RBRACEright))
|
adamc@1
|
954 | kind ARROW kind (KArrow (kind1, kind2), s (kind1left, kind2right))
|
adamc@1
|
955 | LPAREN kind RPAREN (#1 kind, s (LPARENleft, RPARENright))
|
adamc@82
|
956 | KUNIT (KUnit, s (KUNITleft, KUNITright))
|
adamc@18
|
957 | UNDERUNDER (KWild, s (UNDERUNDERleft, UNDERUNDERright))
|
adamc@207
|
958 | LPAREN ktuple RPAREN (KTuple ktuple, s (LPARENleft, RPARENright))
|
adamc@623
|
959 | CSYMBOL (KVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@623
|
960 | CSYMBOL KARROW kind (KFun (CSYMBOL, kind), s (CSYMBOLleft, kindright))
|
adamc@207
|
961
|
adamc@207
|
962 ktuple : kind STAR kind ([kind1, kind2])
|
adamc@207
|
963 | kind STAR ktuple (kind :: ktuple)
|
adamc@1
|
964
|
adamc@1
|
965 capps : cterm (cterm)
|
adamc@1
|
966 | capps cterm (CApp (capps, cterm), s (cappsleft, ctermright))
|
adamc@1
|
967
|
adamc@1
|
968 cexp : capps (capps)
|
adamc@1
|
969 | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right))
|
adamc@15
|
970 | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright))
|
adamc@623
|
971 | CSYMBOL KARROW cexp (TKFun (CSYMBOL, cexp), s (CSYMBOLleft, cexpright))
|
adamc@1
|
972
|
adamc@1
|
973 | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right))
|
adamc@1
|
974
|
adamc@239
|
975 | FN cargs DARROW cexp (#1 (cargs (cexp, (KWild, s (FNleft, cexpright)))))
|
adamc@628
|
976 | LBRACK cexp TWIDDLE cexp RBRACK DARROW cexp (TDisjoint (cexp1, cexp2, cexp3), s (LBRACKleft, cexp3right))
|
adamc@623
|
977 | CSYMBOL DKARROW cexp (CKAbs (CSYMBOL, cexp), s (CSYMBOLleft, cexpright))
|
adamc@1
|
978
|
adamc@8
|
979 | LPAREN cexp RPAREN DCOLON kind (CAnnot (cexp, kind), s (LPARENleft, kindright))
|
adamc@6
|
980
|
adamc@18
|
981 | UNDER DCOLON kind (CWild kind, s (UNDERleft, UNDERright))
|
adamc@195
|
982 | ctuple (let
|
adamc@195
|
983 val loc = s (ctupleleft, ctupleright)
|
adamc@195
|
984 in
|
adamc@195
|
985 (TRecord (CRecord (ListUtil.mapi (fn (i, c) =>
|
adamc@195
|
986 ((CName (Int.toString (i + 1)), loc),
|
adamc@195
|
987 c)) ctuple),
|
adamc@195
|
988 loc), loc)
|
adamc@195
|
989 end)
|
adamc@18
|
990
|
adamc@1
|
991 kcolon : DCOLON (Explicit)
|
adamc@1
|
992 | TCOLON (Implicit)
|
adamc@1
|
993
|
adamc@239
|
994 cargs : carg (carg)
|
adamc@239
|
995 | cargl (cargl)
|
adamc@239
|
996
|
adamc@239
|
997 cargl : cargp cargp (cargp1 o cargp2)
|
adamc@239
|
998 | cargp cargl (cargp o cargl)
|
adamc@239
|
999
|
adamc@240
|
1000 cargl2 : (fn x => x)
|
adamc@240
|
1001 | cargp cargl2 (cargp o cargl2)
|
adamc@240
|
1002
|
adamc@241
|
1003 carg : SYMBOL DCOLON kind (fn (c, k) =>
|
adamc@239
|
1004 let
|
adamc@239
|
1005 val loc = s (SYMBOLleft, kindright)
|
adamc@239
|
1006 in
|
adamc@239
|
1007 ((CAbs (SYMBOL, SOME kind, c), loc),
|
adamc@239
|
1008 (KArrow (kind, k), loc))
|
adamc@239
|
1009 end)
|
adamc@329
|
1010 | UNDER DCOLON kind (fn (c, k) =>
|
adamc@329
|
1011 let
|
adamc@329
|
1012 val loc = s (UNDERleft, kindright)
|
adamc@329
|
1013 in
|
adamc@329
|
1014 ((CAbs ("_", SOME kind, c), loc),
|
adamc@329
|
1015 (KArrow (kind, k), loc))
|
adamc@329
|
1016 end)
|
adam@1302
|
1017 | SYMBOL DCOLONWILD (fn (c, k) =>
|
adam@1302
|
1018 let
|
adam@1302
|
1019 val loc = s (SYMBOLleft, DCOLONWILDright)
|
adam@1302
|
1020 val kind = (KWild, loc)
|
adam@1302
|
1021 in
|
adam@1302
|
1022 ((CAbs (SYMBOL, NONE, c), loc),
|
adam@1302
|
1023 (KArrow (kind, k), loc))
|
adam@1302
|
1024 end)
|
adam@1302
|
1025 | UNDER DCOLONWILD (fn (c, k) =>
|
adam@1302
|
1026 let
|
adam@1302
|
1027 val loc = s (UNDERleft, DCOLONWILDright)
|
adam@1302
|
1028 val kind = (KWild, loc)
|
adam@1302
|
1029 in
|
adam@1302
|
1030 ((CAbs ("_", NONE, c), loc),
|
adam@1302
|
1031 (KArrow (kind, k), loc))
|
adam@1302
|
1032 end)
|
adamc@241
|
1033 | cargp (cargp)
|
adamc@239
|
1034
|
adamc@239
|
1035 cargp : SYMBOL (fn (c, k) =>
|
adamc@239
|
1036 let
|
adamc@239
|
1037 val loc = s (SYMBOLleft, SYMBOLright)
|
adamc@239
|
1038 in
|
adamc@239
|
1039 ((CAbs (SYMBOL, NONE, c), loc),
|
adamc@239
|
1040 (KArrow ((KWild, loc), k), loc))
|
adamc@239
|
1041 end)
|
adamc@329
|
1042 | UNDER (fn (c, k) =>
|
adamc@329
|
1043 let
|
adamc@329
|
1044 val loc = s (UNDERleft, UNDERright)
|
adamc@329
|
1045 in
|
adamc@329
|
1046 ((CAbs ("_", NONE, c), loc),
|
adamc@329
|
1047 (KArrow ((KWild, loc), k), loc))
|
adamc@329
|
1048 end)
|
adamc@1001
|
1049 | LPAREN SYMBOL kopt ckl RPAREN (fn (c, k) =>
|
adamc@239
|
1050 let
|
adamc@239
|
1051 val loc = s (LPARENleft, RPARENright)
|
adamc@1001
|
1052 val ckl = (SYMBOL, kopt) :: ckl
|
adamc@1001
|
1053 val ckl = map (fn (x, ko) => (x, case ko of
|
adamc@1001
|
1054 NONE => (KWild, loc)
|
adamc@1001
|
1055 | SOME k => k)) ckl
|
adamc@239
|
1056 in
|
adamc@1001
|
1057 case ckl of
|
adamc@1001
|
1058 [(x, k')] => ((CAbs (SYMBOL, SOME k', c), loc),
|
adamc@1001
|
1059 (KArrow (k', k), loc))
|
adamc@1001
|
1060 | _ =>
|
adamc@1001
|
1061 let
|
adamc@1001
|
1062 val k' = (KTuple (map #2 ckl), loc)
|
adamc@1001
|
1063
|
adamc@1001
|
1064 val c = foldr (fn ((x, k), c) =>
|
adamc@1001
|
1065 (CAbs (x, SOME k, c), loc)) c ckl
|
adamc@1001
|
1066 val v = (CVar ([], "$x"), loc)
|
adamc@1001
|
1067 val c = ListUtil.foldli (fn (i, _, c) =>
|
adamc@1001
|
1068 (CApp (c, (CProj (v, i + 1), loc)),
|
adamc@1001
|
1069 loc)) c ckl
|
adamc@1001
|
1070 in
|
adamc@1001
|
1071 ((CAbs ("$x", SOME k', c), loc),
|
adamc@1001
|
1072 (KArrow (k', k), loc))
|
adamc@1001
|
1073 end
|
adamc@239
|
1074 end)
|
adamc@628
|
1075
|
adamc@1001
|
1076 ckl : ([])
|
adamc@1001
|
1077 | COMMA SYMBOL kopt ckl ((SYMBOL, kopt) :: ckl)
|
adamc@239
|
1078
|
adamc@34
|
1079 path : SYMBOL ([], SYMBOL)
|
adamc@34
|
1080 | CSYMBOL DOT path (let val (ms, x) = path in (CSYMBOL :: ms, x) end)
|
adamc@34
|
1081
|
adamc@156
|
1082 cpath : CSYMBOL ([], CSYMBOL)
|
adamc@156
|
1083 | CSYMBOL DOT cpath (let val (ms, x) = cpath in (CSYMBOL :: ms, x) end)
|
adamc@156
|
1084
|
adamc@59
|
1085 mpath : CSYMBOL ([CSYMBOL])
|
adamc@59
|
1086 | CSYMBOL DOT mpath (CSYMBOL :: mpath)
|
adamc@59
|
1087
|
adamc@1
|
1088 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright))
|
adamc@1
|
1089 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright))
|
adamc@83
|
1090 | LBRACK rconn RBRACK (CRecord rconn, s (LBRACKleft, RBRACKright))
|
adamc@1
|
1091 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)),
|
adamc@1
|
1092 s (LBRACEleft, RBRACEright))
|
adamc@1
|
1093 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright))
|
adamc@1
|
1094 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright))
|
adamc@195
|
1095 | HASH INT (CName (Int64.toString INT), s (HASHleft, INTright))
|
adamc@1
|
1096
|
adamc@34
|
1097 | path (CVar path, s (pathleft, pathright))
|
adamc@207
|
1098 | path DOT INT (CProj ((CVar path, s (pathleft, pathright)), Int64.toInt INT),
|
adamc@207
|
1099 s (pathleft, INTright))
|
adamc@18
|
1100 | UNDER (CWild (KWild, s (UNDERleft, UNDERright)), s (UNDERleft, UNDERright))
|
adamc@621
|
1101 | MAP (CMap, s (MAPleft, MAPright))
|
adamc@82
|
1102 | UNIT (CUnit, s (UNITleft, UNITright))
|
adamc@207
|
1103 | LPAREN ctuplev RPAREN (CTuple ctuplev, s (LPARENleft, RPARENright))
|
adamc@207
|
1104
|
adamc@207
|
1105 ctuplev: cexp COMMA cexp ([cexp1, cexp2])
|
adamc@207
|
1106 | cexp COMMA ctuplev (cexp :: ctuplev)
|
adamc@1
|
1107
|
adamc@196
|
1108 ctuple : capps STAR capps ([capps1, capps2])
|
adamc@196
|
1109 | capps STAR ctuple (capps :: ctuple)
|
adamc@195
|
1110
|
adamc@1
|
1111 rcon : ([])
|
adamc@1
|
1112 | ident EQ cexp ([(ident, cexp)])
|
adamc@1
|
1113 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon)
|
adamc@1
|
1114
|
adamc@83
|
1115 rconn : ident ([(ident, (CUnit, s (identleft, identright)))])
|
adamc@83
|
1116 | ident COMMA rconn ((ident, (CUnit, s (identleft, identright))) :: rconn)
|
adamc@83
|
1117
|
adamc@1
|
1118 rcone : ([])
|
adamc@1
|
1119 | ident COLON cexp ([(ident, cexp)])
|
adamc@1
|
1120 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone)
|
adamc@1
|
1121
|
adamc@1
|
1122 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@195
|
1123 | INT (CName (Int64.toString INT), s (INTleft, INTright))
|
adamc@200
|
1124 | SYMBOL (CVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
|
adamc@8
|
1125
|
adamc@8
|
1126 eapps : eterm (eterm)
|
adamc@8
|
1127 | eapps eterm (EApp (eapps, eterm), s (eappsleft, etermright))
|
adamc@8
|
1128 | eapps LBRACK cexp RBRACK (ECApp (eapps, cexp), s (eappsleft, RBRACKright))
|
adamc@629
|
1129 | eapps BANG (EDisjointApp eapps, s (eappsleft, BANGright))
|
adamc@8
|
1130
|
adam@1751
|
1131 eexp : eapps (case #1 eapps of
|
adam@1751
|
1132 EApp ((EVar ([], "CLASS", _), _), (EPrim (Prim.String s), loc)) => parseClass s loc
|
adam@1751
|
1133 | EApp ((EVar ([], "STYLE", _), _), (EPrim (Prim.String s), loc)) => parseStyle s loc
|
adam@1751
|
1134 | _ => eapps)
|
adamc@241
|
1135 | FN eargs DARROW eexp (let
|
adamc@93
|
1136 val loc = s (FNleft, eexpright)
|
adamc@93
|
1137 in
|
adamc@241
|
1138 #1 (eargs (eexp, (CWild (KType, loc), loc)))
|
adamc@93
|
1139 end)
|
adamc@623
|
1140 | CSYMBOL DKARROW eexp (EKAbs (CSYMBOL, eexp), s (CSYMBOLleft, eexpright))
|
adamc@196
|
1141 | eexp COLON cexp (EAnnot (eexp, cexp), s (eexpleft, cexpright))
|
adamc@149
|
1142 | eexp MINUSMINUS cexp (ECut (eexp, cexp), s (eexpleft, cexpright))
|
adamc@493
|
1143 | eexp MINUSMINUSMINUS cexp (ECutMulti (eexp, cexp), s (eexpleft, cexpright))
|
adamc@170
|
1144 | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
|
adamc@190
|
1145 | IF eexp THEN eexp ELSE eexp (let
|
adamc@190
|
1146 val loc = s (IFleft, eexp3right)
|
adamc@190
|
1147 in
|
adamc@190
|
1148 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc), eexp2),
|
adamc@190
|
1149 ((PCon (["Basis"], "False", NONE), loc), eexp3)]), loc)
|
adamc@190
|
1150 end)
|
adamc@434
|
1151 | bind SEMI eexp (let
|
adamc@434
|
1152 val loc = s (bindleft, eexpright)
|
adamc@434
|
1153 val (v, to, e1) = bind
|
adamc@403
|
1154 val e = (EVar (["Basis"], "bind", Infer), loc)
|
adamc@434
|
1155 val e = (EApp (e, e1), loc)
|
adamc@243
|
1156 in
|
adamc@434
|
1157 (EApp (e, (EAbs (v, to, eexp), loc)), loc)
|
adamc@299
|
1158 end)
|
adamc@256
|
1159 | eexp EQ eexp (native_op ("eq", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@257
|
1160 | eexp NE eexp (native_op ("ne", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@389
|
1161 | MINUS eterm (native_unop ("neg", eterm, s (MINUSleft, etermright)))
|
adamc@389
|
1162 | eexp PLUS eexp (native_op ("plus", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@389
|
1163 | eexp MINUS eexp (native_op ("minus", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@1116
|
1164 | eapps STAR eexp (native_op ("times", eapps, eexp, s (eappsleft, eexpright)))
|
adamc@964
|
1165 | eexp DIVIDE eexp (native_op ("divide", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@389
|
1166 | eexp MOD eexp (native_op ("mod", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
1167
|
adamc@391
|
1168 | eexp LT eexp (native_op ("lt", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
1169 | eexp LE eexp (native_op ("le", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
1170 | eexp GT eexp (native_op ("gt", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
1171 | eexp GE eexp (native_op ("ge", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@391
|
1172
|
adamc@842
|
1173 | eexp ANDALSO eexp (let
|
adamc@842
|
1174 val loc = s (eexp1left, eexp2right)
|
adamc@842
|
1175 in
|
adamc@842
|
1176 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc),
|
adamc@842
|
1177 eexp2),
|
adamc@842
|
1178 ((PCon (["Basis"], "False", NONE), loc),
|
adamc@842
|
1179 (EVar (["Basis"], "False", Infer), loc))]), loc)
|
adamc@842
|
1180 end)
|
adamc@842
|
1181 | eexp ORELSE eexp (let
|
adamc@842
|
1182 val loc = s (eexp1left, eexp2right)
|
adamc@842
|
1183 in
|
adamc@842
|
1184 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc),
|
adamc@842
|
1185 (EVar (["Basis"], "True", Infer), loc)),
|
adamc@842
|
1186 ((PCon (["Basis"], "False", NONE), loc),
|
adamc@842
|
1187 eexp2)]), loc)
|
adamc@842
|
1188 end)
|
adamc@842
|
1189
|
adamc@445
|
1190 | eexp PLUSPLUS eexp (EConcat (eexp1, eexp2), s (eexp1left, eexp2right))
|
adamc@8
|
1191
|
adamc@674
|
1192 | eexp CARET eexp (native_op ("strcat", eexp1, eexp2, s (eexp1left, eexp2right)))
|
adamc@674
|
1193
|
adamc@794
|
1194 | eapps DCOLON eexp (let
|
adamc@794
|
1195 val loc = s (eappsleft, eexpright)
|
adamc@762
|
1196 in
|
adamc@762
|
1197 (EApp ((EVar (["Basis"], "Cons", Infer), loc),
|
adamc@762
|
1198 (ERecord [((CName "1", loc),
|
adamc@794
|
1199 eapps),
|
adamc@762
|
1200 ((CName "2", loc),
|
adamc@762
|
1201 eexp)], loc)), loc)
|
adamc@762
|
1202 end)
|
adamc@762
|
1203
|
adamc@434
|
1204 bind : SYMBOL LARROW eapps (SYMBOL, NONE, eapps)
|
adamc@434
|
1205 | eapps (let
|
adamc@434
|
1206 val loc = s (eappsleft, eappsright)
|
adamc@434
|
1207 in
|
adamc@434
|
1208 ("_", SOME (TRecord (CRecord [], loc), loc), eapps)
|
adamc@434
|
1209 end)
|
adamc@434
|
1210
|
adamc@241
|
1211 eargs : earg (earg)
|
adamc@241
|
1212 | eargl (eargl)
|
adamc@241
|
1213
|
adamc@241
|
1214 eargl : eargp eargp (eargp1 o eargp2)
|
adamc@241
|
1215 | eargp eargl (eargp o eargl)
|
adamc@241
|
1216
|
adamc@242
|
1217 eargl2 : (fn x => x)
|
adamc@242
|
1218 | eargp eargl2 (eargp o eargl2)
|
adamc@242
|
1219
|
adamc@822
|
1220 earg : patS (fn (e, t) =>
|
adamc@241
|
1221 let
|
adamc@822
|
1222 val loc = s (patSleft, patSright)
|
adamc@822
|
1223 val pt = patType loc patS
|
adamc@822
|
1224
|
adamc@822
|
1225 val e' = case #1 patS of
|
adamc@822
|
1226 PVar x => (EAbs (x, NONE, e), loc)
|
adamc@823
|
1227 | PAnnot ((PVar x, _), t) => (EAbs (x, SOME t, e), loc)
|
adamc@822
|
1228 | _ => (EAbs ("$x", SOME pt,
|
adamc@822
|
1229 (ECase ((EVar ([], "$x", DontInfer),
|
adamc@822
|
1230 loc),
|
adamc@822
|
1231 [(patS, e)]), loc)), loc)
|
adamc@241
|
1232 in
|
adamc@822
|
1233 (e', (TFun (pt, t), loc))
|
adamc@241
|
1234 end)
|
adamc@822
|
1235 | earga (earga)
|
adamc@822
|
1236
|
adamc@822
|
1237 eargp : pterm (fn (e, t) =>
|
adamc@241
|
1238 let
|
adamc@822
|
1239 val loc = s (ptermleft, ptermright)
|
adamc@822
|
1240 val pt = patType loc pterm
|
adamc@822
|
1241
|
adamc@822
|
1242 val e' = case #1 pterm of
|
adamc@822
|
1243 PVar x => (EAbs (x, NONE, e), loc)
|
adamc@823
|
1244 | PAnnot ((PVar x, _), t) => (EAbs (x, SOME t, e), loc)
|
adamc@822
|
1245 | _ => (EAbs ("$x", SOME pt,
|
adamc@822
|
1246 (ECase ((EVar ([], "$x", DontInfer),
|
adamc@822
|
1247 loc),
|
adamc@822
|
1248 [(pterm, e)]), loc)), loc)
|
adamc@241
|
1249 in
|
adamc@822
|
1250 (e', (TFun (pt, t), loc))
|
adamc@241
|
1251 end)
|
adamc@822
|
1252 | earga (earga)
|
adamc@241
|
1253
|
adamc@822
|
1254 earga : LBRACK SYMBOL RBRACK (fn (e, t) =>
|
adamc@241
|
1255 let
|
adamc@822
|
1256 val loc = s (LBRACKleft, RBRACKright)
|
adamc@822
|
1257 val kind = (KWild, loc)
|
adamc@822
|
1258 in
|
adamc@822
|
1259 ((ECAbs (Implicit, SYMBOL, kind, e), loc),
|
adamc@822
|
1260 (TCFun (Implicit, SYMBOL, kind, t), loc))
|
adamc@822
|
1261 end)
|
adam@1302
|
1262 | LBRACK SYMBOL DCOLONWILD RBRACK (fn (e, t) =>
|
adam@1302
|
1263 let
|
adam@1302
|
1264 val loc = s (LBRACKleft, RBRACKright)
|
adam@1302
|
1265 val kind = (KWild, loc)
|
adam@1302
|
1266 in
|
adam@1302
|
1267 ((ECAbs (Explicit, SYMBOL, kind, e), loc),
|
adam@1302
|
1268 (TCFun (Explicit, SYMBOL, kind, t), loc))
|
adam@1302
|
1269 end)
|
adamc@822
|
1270 | LBRACK SYMBOL kcolon kind RBRACK(fn (e, t) =>
|
adamc@822
|
1271 let
|
adamc@822
|
1272 val loc = s (LBRACKleft, RBRACKright)
|
adamc@241
|
1273 in
|
adamc@241
|
1274 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
|
adamc@241
|
1275 (TCFun (kcolon, SYMBOL, kind, t), loc))
|
adamc@241
|
1276 end)
|
adam@1306
|
1277 | LBRACK SYMBOL TCOLONWILD RBRACK (fn (e, t) =>
|
adam@1306
|
1278 let
|
adam@1306
|
1279 val loc = s (LBRACKleft, RBRACKright)
|
adam@1306
|
1280 val kind = (KWild, loc)
|
adam@1306
|
1281 in
|
adam@1306
|
1282 ((ECAbs (Implicit, SYMBOL, kind, e), loc),
|
adam@1306
|
1283 (TCFun (Implicit, SYMBOL, kind, t), loc))
|
adam@1306
|
1284 end)
|
adamc@478
|
1285 | LBRACK cexp TWIDDLE cexp RBRACK(fn (e, t) =>
|
adamc@356
|
1286 let
|
adamc@356
|
1287 val loc = s (LBRACKleft, RBRACKright)
|
adamc@356
|
1288 in
|
adamc@478
|
1289 ((EDisjoint (cexp1, cexp2, e), loc),
|
adamc@628
|
1290 (TDisjoint (cexp1, cexp2, t), loc))
|
adamc@356
|
1291 end)
|
adamc@822
|
1292 | LBRACK CSYMBOL RBRACK (fn (e, t) =>
|
adamc@623
|
1293 let
|
adamc@623
|
1294 val loc = s (CSYMBOLleft, CSYMBOLright)
|
adamc@623
|
1295 in
|
adamc@623
|
1296 ((EKAbs (CSYMBOL, e), loc),
|
adamc@623
|
1297 (TKFun (CSYMBOL, t), loc))
|
adamc@623
|
1298 end)
|
adamc@241
|
1299
|
adamc@8
|
1300 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
|
adamc@195
|
1301 | LPAREN etuple RPAREN (let
|
adamc@195
|
1302 val loc = s (LPARENleft, RPARENright)
|
adamc@195
|
1303 in
|
adamc@195
|
1304 (ERecord (ListUtil.mapi (fn (i, e) =>
|
adamc@195
|
1305 ((CName (Int.toString (i + 1)), loc),
|
adamc@195
|
1306 e)) etuple), loc)
|
adamc@195
|
1307 end)
|
adamc@8
|
1308
|
adamc@403
|
1309 | path (EVar (#1 path, #2 path, Infer), s (pathleft, pathright))
|
adamc@403
|
1310 | cpath (EVar (#1 cpath, #2 cpath, Infer), s (cpathleft, cpathright))
|
adamc@403
|
1311 | AT path (EVar (#1 path, #2 path, TypesOnly), s (ATleft, pathright))
|
adamc@403
|
1312 | AT AT path (EVar (#1 path, #2 path, DontInfer), s (AT1left, pathright))
|
adamc@403
|
1313 | AT cpath (EVar (#1 cpath, #2 cpath, TypesOnly), s (ATleft, cpathright))
|
adamc@403
|
1314 | AT AT cpath (EVar (#1 cpath, #2 cpath, DontInfer), s (AT1left, cpathright))
|
adamc@12
|
1315 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
|
adamc@110
|
1316 | UNIT (ERecord [], s (UNITleft, UNITright))
|
adamc@12
|
1317
|
adamc@14
|
1318 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@14
|
1319 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
|
adamc@14
|
1320 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@821
|
1321 | CHAR (EPrim (Prim.Char CHAR), s (CHARleft, CHARright))
|
adamc@14
|
1322
|
adamc@200
|
1323 | path DOT idents (let
|
adamc@200
|
1324 val loc = s (pathleft, identsright)
|
adamc@200
|
1325 in
|
adamc@200
|
1326 foldl (fn (ident, e) =>
|
adamc@200
|
1327 (EField (e, ident), loc))
|
adamc@403
|
1328 (EVar (#1 path, #2 path, Infer), s (pathleft, pathright)) idents
|
adamc@403
|
1329 end)
|
adamc@910
|
1330 | LPAREN eexp RPAREN DOT idents (let
|
adamc@910
|
1331 val loc = s (LPARENleft, identsright)
|
adamc@910
|
1332 in
|
adamc@910
|
1333 foldl (fn (ident, e) =>
|
adamc@910
|
1334 (EField (e, ident), loc))
|
adamc@910
|
1335 eexp idents
|
adamc@910
|
1336 end)
|
adamc@403
|
1337 | AT path DOT idents (let
|
adamc@403
|
1338 val loc = s (ATleft, identsright)
|
adamc@403
|
1339 in
|
adamc@403
|
1340 foldl (fn (ident, e) =>
|
adamc@403
|
1341 (EField (e, ident), loc))
|
adamc@403
|
1342 (EVar (#1 path, #2 path, TypesOnly), s (pathleft, pathright)) idents
|
adamc@403
|
1343 end)
|
adamc@403
|
1344 | AT AT path DOT idents (let
|
adamc@403
|
1345 val loc = s (AT1left, identsright)
|
adamc@403
|
1346 in
|
adamc@403
|
1347 foldl (fn (ident, e) =>
|
adamc@403
|
1348 (EField (e, ident), loc))
|
adamc@403
|
1349 (EVar (#1 path, #2 path, DontInfer), s (pathleft, pathright)) idents
|
adamc@200
|
1350 end)
|
adamc@71
|
1351
|
adamc@360
|
1352 | XML_BEGIN xml XML_END (let
|
adamc@360
|
1353 val loc = s (XML_BEGINleft, XML_ENDright)
|
adamc@360
|
1354 in
|
adamc@360
|
1355 if XML_BEGIN = "xml" then
|
adamc@360
|
1356 ()
|
adamc@360
|
1357 else
|
adamc@360
|
1358 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
|
adamc@360
|
1359 xml
|
adamc@360
|
1360 end)
|
adamc@360
|
1361 | XML_BEGIN XML_END (let
|
adamc@360
|
1362 val loc = s (XML_BEGINleft, XML_ENDright)
|
adamc@360
|
1363 in
|
adamc@360
|
1364 if XML_BEGIN = "xml" then
|
adamc@360
|
1365 ()
|
adamc@360
|
1366 else
|
adamc@360
|
1367 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
|
adamc@403
|
1368 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
|
adamc@360
|
1369 (EPrim (Prim.String ""), loc)),
|
adamc@360
|
1370 loc)
|
adamc@360
|
1371 end)
|
adamc@360
|
1372 | XML_BEGIN_END (let
|
adamc@360
|
1373 val loc = s (XML_BEGIN_ENDleft, XML_BEGIN_ENDright)
|
adamc@360
|
1374 in
|
adamc@360
|
1375 if XML_BEGIN_END = "xml" then
|
adamc@360
|
1376 ()
|
adamc@360
|
1377 else
|
adamc@360
|
1378 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
|
adamc@403
|
1379 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
|
adamc@360
|
1380 (EPrim (Prim.String ""), loc)),
|
adamc@360
|
1381 loc)
|
adamc@360
|
1382 end)
|
adamc@302
|
1383
|
adamc@204
|
1384 | LPAREN query RPAREN (query)
|
adamc@300
|
1385 | LPAREN CWHERE sqlexp RPAREN (sqlexp)
|
adamc@339
|
1386 | LPAREN SQL sqlexp RPAREN (sqlexp)
|
adamc@1070
|
1387 | LPAREN FROM tables RPAREN (#2 tables)
|
adamc@1071
|
1388 | LPAREN SELECT1 query1 RPAREN (query1)
|
adamc@302
|
1389
|
adamc@302
|
1390 | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN
|
adamc@302
|
1391 (let
|
adamc@302
|
1392 val loc = s (LPAREN1left, RPAREN3right)
|
adamc@302
|
1393
|
adamc@403
|
1394 val e = (EVar (["Basis"], "insert", Infer), loc)
|
adamc@302
|
1395 val e = (EApp (e, texp), loc)
|
adamc@302
|
1396 in
|
adamc@302
|
1397 if length fields <> length sqlexps then
|
adam@1360
|
1398 ErrorMsg.errorAt loc ("Length mismatch in INSERT field specification ("
|
adam@1360
|
1399 ^ Int.toString (length fields)
|
adam@1360
|
1400 ^ " vs. " ^ Int.toString (length sqlexps) ^ ")")
|
adamc@302
|
1401 else
|
adamc@302
|
1402 ();
|
adamc@302
|
1403 (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
|
adamc@302
|
1404 end)
|
adamc@310
|
1405 | LPAREN enterDml UPDATE texp SET fsets CWHERE sqlexp leaveDml RPAREN
|
adamc@303
|
1406 (let
|
adamc@303
|
1407 val loc = s (LPARENleft, RPARENright)
|
adamc@303
|
1408
|
adamc@403
|
1409 val e = (EVar (["Basis"], "update", Infer), loc)
|
adamc@342
|
1410 val e = (ECApp (e, (CWild (KRecord (KType, loc), loc), loc)), loc)
|
adamc@306
|
1411 val e = (EApp (e, (ERecord fsets, loc)), loc)
|
adamc@305
|
1412 val e = (EApp (e, texp), loc)
|
adamc@303
|
1413 in
|
adamc@303
|
1414 (EApp (e, sqlexp), loc)
|
adamc@303
|
1415 end)
|
adamc@310
|
1416 | LPAREN enterDml DELETE FROM texp CWHERE sqlexp leaveDml RPAREN
|
adamc@304
|
1417 (let
|
adamc@304
|
1418 val loc = s (LPARENleft, RPARENright)
|
adamc@304
|
1419
|
adamc@403
|
1420 val e = (EVar (["Basis"], "delete", Infer), loc)
|
adamc@304
|
1421 val e = (EApp (e, texp), loc)
|
adamc@304
|
1422 in
|
adamc@304
|
1423 (EApp (e, sqlexp), loc)
|
adamc@304
|
1424 end)
|
adamc@302
|
1425
|
adamc@211
|
1426 | UNDER (EWild, s (UNDERleft, UNDERright))
|
adamc@91
|
1427
|
adamc@446
|
1428 | LET edecls IN eexp END (ELet (edecls, eexp), s (LETleft, ENDright))
|
adamc@446
|
1429
|
adamc@762
|
1430 | LBRACK RBRACK (EVar (["Basis"], "Nil", Infer), s (LBRACKleft, RBRACKright))
|
adamc@762
|
1431
|
adamc@446
|
1432 edecls : ([])
|
adamc@446
|
1433 | edecl edecls (edecl :: edecls)
|
adamc@446
|
1434
|
adamc@825
|
1435 edecl : VAL pat EQ eexp ((EDVal (pat, eexp), s (VALleft, eexpright)))
|
adamc@446
|
1436 | VAL REC valis ((EDValRec valis, s (VALleft, valisright)))
|
adamc@446
|
1437 | FUN valis ((EDValRec valis, s (FUNleft, valisright)))
|
adamc@446
|
1438
|
adamc@310
|
1439 enterDml : (inDml := true)
|
adamc@310
|
1440 leaveDml : (inDml := false)
|
adamc@310
|
1441
|
adamc@403
|
1442 texp : SYMBOL (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
|
adamc@302
|
1443 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
|
adamc@302
|
1444
|
adamc@302
|
1445 fields : fident ([fident])
|
adamc@302
|
1446 | fident COMMA fields (fident :: fields)
|
adamc@302
|
1447
|
adamc@302
|
1448 sqlexps: sqlexp ([sqlexp])
|
adamc@302
|
1449 | sqlexp COMMA sqlexps (sqlexp :: sqlexps)
|
adamc@302
|
1450
|
adamc@303
|
1451 fsets : fident EQ sqlexp ([(fident, sqlexp)])
|
adamc@303
|
1452 | fident EQ sqlexp COMMA fsets ((fident, sqlexp) :: fsets)
|
adamc@303
|
1453
|
adamc@200
|
1454 idents : ident ([ident])
|
adamc@200
|
1455 | ident DOT idents (ident :: idents)
|
adamc@200
|
1456
|
adamc@195
|
1457 etuple : eexp COMMA eexp ([eexp1, eexp2])
|
adamc@195
|
1458 | eexp COMMA etuple (eexp :: etuple)
|
adamc@195
|
1459
|
adamc@170
|
1460 branch : pat DARROW eexp (pat, eexp)
|
adamc@170
|
1461
|
adamc@170
|
1462 branchs: ([])
|
adamc@170
|
1463 | BAR branch branchs (branch :: branchs)
|
adamc@170
|
1464
|
adamc@822
|
1465 patS : pterm (pterm)
|
adamc@822
|
1466 | pterm DCOLON patS (let
|
adamc@822
|
1467 val loc = s (ptermleft, patSright)
|
adamc@762
|
1468 in
|
adamc@762
|
1469 (PCon (["Basis"], "Cons", SOME (PRecord ([("1", pterm),
|
adamc@822
|
1470 ("2", patS)], false), loc)),
|
adamc@762
|
1471 loc)
|
adamc@762
|
1472 end)
|
adamc@822
|
1473 | patS COLON cexp (PAnnot (patS, cexp), s (patSleft, cexpright))
|
adamc@822
|
1474
|
adamc@822
|
1475 pat : patS (patS)
|
adamc@822
|
1476 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
|
adamc@170
|
1477
|
adamc@170
|
1478 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
|
adamc@170
|
1479 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
|
adamc@170
|
1480 | UNDER (PWild, s (UNDERleft, UNDERright))
|
adamc@173
|
1481 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
|
adam@1420
|
1482 | MINUS INT (PPrim (Prim.Int (~INT)), s (MINUSleft, INTright))
|
adamc@173
|
1483 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@821
|
1484 | CHAR (PPrim (Prim.Char CHAR), s (CHARleft, CHARright))
|
adamc@170
|
1485 | LPAREN pat RPAREN (pat)
|
adamc@174
|
1486 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
|
adamc@174
|
1487 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
|
adamc@174
|
1488 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
|
adamc@195
|
1489 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
|
adamc@195
|
1490 false),
|
adamc@195
|
1491 s (LPARENleft, RPARENright))
|
adamc@762
|
1492 | LBRACK RBRACK (PCon (["Basis"], "Nil", NONE), s (LBRACKleft, RBRACKright))
|
adamc@174
|
1493
|
adamc@175
|
1494 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
|
adamc@243
|
1495 | INT EQ pat ([(Int64.toString INT, pat)], false)
|
adamc@174
|
1496 | DOTDOTDOT ([], true)
|
adamc@175
|
1497 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
|
adamc@243
|
1498 | INT EQ pat COMMA rpat ((Int64.toString INT, pat) :: #1 rpat, #2 rpat)
|
adamc@170
|
1499
|
adamc@195
|
1500 ptuple : pat COMMA pat ([pat1, pat2])
|
adamc@195
|
1501 | pat COMMA ptuple (pat :: ptuple)
|
adamc@195
|
1502
|
adamc@12
|
1503 rexp : ([])
|
adamc@12
|
1504 | ident EQ eexp ([(ident, eexp)])
|
adamc@12
|
1505 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
|
adamc@91
|
1506
|
adamc@141
|
1507 xml : xmlOne xml (let
|
adamc@141
|
1508 val pos = s (xmlOneleft, xmlright)
|
adamc@141
|
1509 in
|
adamc@720
|
1510 (EApp ((EApp (
|
adamc@720
|
1511 (EVar (["Basis"], "join", Infer), pos),
|
adamc@720
|
1512 xmlOne), pos),
|
adamc@720
|
1513 xml), pos)
|
adamc@141
|
1514 end)
|
adamc@141
|
1515 | xmlOne (xmlOne)
|
adamc@91
|
1516
|
adamc@1045
|
1517 xmlOpt : xml (xml)
|
adamc@1045
|
1518 | (EApp ((EVar (["Basis"], "cdata", Infer), dummy),
|
adamc@1045
|
1519 (EPrim (Prim.String ""), dummy)),
|
adamc@1045
|
1520 dummy)
|
adamc@1045
|
1521
|
adamc@403
|
1522 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata", Infer), s (NOTAGSleft, NOTAGSright)),
|
adamc@141
|
1523 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
|
adamc@141
|
1524 s (NOTAGSleft, NOTAGSright))
|
adamc@141
|
1525 | tag DIVIDE GT (let
|
adamc@141
|
1526 val pos = s (tagleft, GTright)
|
adamc@710
|
1527
|
adamc@710
|
1528 val cdata =
|
adamc@756
|
1529 if #1 (#1 tag) = "submit" orelse #1 (#1 tag) = "dyn" then
|
adamc@710
|
1530 let
|
adamc@710
|
1531 val e = (EVar (["Basis"], "cdata", DontInfer), pos)
|
adamc@710
|
1532 val e = (ECApp (e, (CWild (KWild, pos), pos)), pos)
|
adamc@710
|
1533 in
|
adamc@710
|
1534 (ECApp (e, (CRecord [], pos)), pos)
|
adamc@710
|
1535 end
|
adamc@710
|
1536 else
|
adamc@710
|
1537 (EVar (["Basis"], "cdata", Infer), pos)
|
adamc@710
|
1538
|
adamc@710
|
1539 val cdata = (EApp (cdata,
|
adamc@710
|
1540 (EPrim (Prim.String ""), pos)),
|
adamc@710
|
1541 pos)
|
adamc@141
|
1542 in
|
adam@1643
|
1543 (EApp (#4 tag, cdata), pos)
|
adamc@141
|
1544 end)
|
adamc@141
|
1545
|
adamc@1045
|
1546 | tag GT xmlOpt END_TAG (let
|
adam@1563
|
1547 fun tagOut s =
|
adam@1563
|
1548 case s of
|
adam@1563
|
1549 "tabl" => "table"
|
adam@1563
|
1550 | _ => s
|
adam@1563
|
1551
|
adamc@141
|
1552 val pos = s (tagleft, GTright)
|
adamc@325
|
1553 val et = tagIn END_TAG
|
adamc@141
|
1554 in
|
adamc@756
|
1555 if #1 (#1 tag) = et then
|
adamc@361
|
1556 if et = "form" then
|
adam@1412
|
1557 let
|
adam@1412
|
1558 val e = (EVar (["Basis"], "form", Infer), pos)
|
adam@1412
|
1559 val e = (EApp (e, case #2 tag of
|
adam@1412
|
1560 NONE => (EVar (["Basis"], "None", Infer), pos)
|
adam@1412
|
1561 | SOME c => (EApp ((EVar (["Basis"], "Some", Infer), pos), c), pos)), pos)
|
adam@1412
|
1562 in
|
adam@1651
|
1563 case #3 tag of
|
adam@1651
|
1564 NONE => ()
|
adam@1651
|
1565 | SOME _ => ErrorMsg.errorAt pos "<form> does not support 'dynClass' attribute";
|
adam@1412
|
1566 (EApp (e, xmlOpt), pos)
|
adam@1412
|
1567 end
|
adamc@1093
|
1568 else if et = "subform" orelse et = "subforms" then
|
adamc@1093
|
1569 (EApp (#2 (#1 tag),
|
adamc@1045
|
1570 xmlOpt), pos)
|
adamc@758
|
1571 else if et = "entry" then
|
adamc@758
|
1572 (EApp ((EVar (["Basis"], "entry", Infer), pos),
|
adamc@1045
|
1573 xmlOpt), pos)
|
adamc@141
|
1574 else
|
adam@1643
|
1575 (EApp (#4 tag, xmlOpt), pos)
|
adamc@141
|
1576 else
|
adamc@325
|
1577 (if ErrorMsg.anyErrors () then
|
adamc@325
|
1578 ()
|
adamc@325
|
1579 else
|
adamc@1189
|
1580 ErrorMsg.errorAt pos ("Begin tag <"
|
adam@1563
|
1581 ^ tagOut (#1 (#1 tag))
|
adamc@1189
|
1582 ^ "> and end tag </"
|
adam@1563
|
1583 ^ tagOut et
|
adamc@1189
|
1584 ^ "> don't match.");
|
adamc@623
|
1585 (EWild, pos))
|
adamc@141
|
1586 end)
|
adamc@141
|
1587 | LBRACE eexp RBRACE (eexp)
|
adamc@391
|
1588 | LBRACE LBRACK eexp RBRACK RBRACE (let
|
adamc@391
|
1589 val loc = s (LBRACEleft, RBRACEright)
|
adamc@403
|
1590 val e = (EVar (["Top"], "txt", Infer), loc)
|
adamc@391
|
1591 in
|
adamc@391
|
1592 (EApp (e, eexp), loc)
|
adamc@391
|
1593 end)
|
adamc@92
|
1594
|
adamc@141
|
1595 tag : tagHead attrs (let
|
adamc@141
|
1596 val pos = s (tagHeadleft, attrsright)
|
adamc@721
|
1597
|
adamc@721
|
1598 val e = (EVar (["Basis"], "tag", Infer), pos)
|
adamc@721
|
1599 val eo = case #1 attrs of
|
adam@1749
|
1600 NONE => (EVar (["Basis"], "null", Infer), pos)
|
adam@1749
|
1601 | SOME (EPrim (Prim.String s), pos) => parseClass s pos
|
adam@1749
|
1602 | SOME e => e
|
adamc@721
|
1603 val e = (EApp (e, eo), pos)
|
adam@1643
|
1604 val eo = case #2 attrs of
|
adam@1643
|
1605 NONE => (EVar (["Basis"], "None", Infer), pos)
|
adam@1643
|
1606 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos),
|
adam@1643
|
1607 e), pos)
|
adam@1643
|
1608 val e = (EApp (e, eo), pos)
|
adam@1750
|
1609 val eo = case #3 attrs of
|
adam@1750
|
1610 NONE => (EVar (["Basis"], "noStyle", Infer), pos)
|
adam@1750
|
1611 | SOME (EPrim (Prim.String s), pos) => parseStyle s pos
|
adam@1750
|
1612 | SOME e => e
|
adam@1750
|
1613 val e = (EApp (e, eo), pos)
|
adam@1751
|
1614 val eo = case #4 attrs of
|
adam@1751
|
1615 NONE => (EVar (["Basis"], "None", Infer), pos)
|
adam@1751
|
1616 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos),
|
adam@1751
|
1617 e), pos)
|
adam@1751
|
1618 val e = (EApp (e, eo), pos)
|
adam@1751
|
1619 val e = (EApp (e, (ERecord (#5 attrs), pos)), pos)
|
adamc@721
|
1620 val e = (EApp (e, (EApp (#2 tagHead,
|
adamc@721
|
1621 (ERecord [], pos)), pos)), pos)
|
adamc@141
|
1622 in
|
adam@1643
|
1623 (tagHead, #1 attrs, #2 attrs, e)
|
adamc@141
|
1624 end)
|
adamc@141
|
1625
|
adamc@141
|
1626 tagHead: BEGIN_TAG (let
|
adamc@325
|
1627 val bt = tagIn BEGIN_TAG
|
adamc@141
|
1628 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
|
adamc@141
|
1629 in
|
adamc@325
|
1630 (bt,
|
adamc@473
|
1631 (EVar (["Basis"], bt, Infer), pos))
|
adamc@141
|
1632 end)
|
adamc@141
|
1633 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
|
adamc@92
|
1634
|
adam@1751
|
1635 attrs : (NONE, NONE, NONE, NONE, [])
|
adamc@721
|
1636 | attr attrs (let
|
adamc@721
|
1637 val loc = s (attrleft, attrsright)
|
adamc@721
|
1638 in
|
adamc@721
|
1639 case attr of
|
adamc@721
|
1640 Class e =>
|
adamc@721
|
1641 (case #1 attrs of
|
adamc@721
|
1642 NONE => ()
|
adamc@721
|
1643 | SOME _ => ErrorMsg.errorAt loc "Multiple classes specified for tag";
|
adam@1751
|
1644 (SOME e, #2 attrs, #3 attrs, #4 attrs, #5 attrs))
|
adam@1643
|
1645 | DynClass e =>
|
adam@1643
|
1646 (case #2 attrs of
|
adam@1643
|
1647 NONE => ()
|
adam@1643
|
1648 | SOME _ => ErrorMsg.errorAt loc "Multiple dynamic classes specified for tag";
|
adam@1751
|
1649 (#1 attrs, SOME e, #3 attrs, #4 attrs, #5 attrs))
|
adam@1750
|
1650 | Style e =>
|
adam@1750
|
1651 (case #3 attrs of
|
adam@1750
|
1652 NONE => ()
|
adam@1750
|
1653 | SOME _ => ErrorMsg.errorAt loc "Multiple styles specified for tag";
|
adam@1751
|
1654 (#1 attrs, #2 attrs, SOME e, #4 attrs, #5 attrs))
|
adam@1751
|
1655 | DynStyle e =>
|
adam@1751
|
1656 (case #4 attrs of
|
adam@1751
|
1657 NONE => ()
|
adam@1751
|
1658 | SOME _ => ErrorMsg.errorAt loc "Multiple dynamic classes specified for tag";
|
adam@1751
|
1659 (#1 attrs, #2 attrs, #3 attrs, SOME e, #5 attrs))
|
adamc@721
|
1660 | Normal xe =>
|
adam@1751
|
1661 (#1 attrs, #2 attrs, #3 attrs, #4 attrs, xe :: #5 attrs)
|
adamc@721
|
1662 end)
|
adamc@104
|
1663
|
adam@1643
|
1664 attr : SYMBOL EQ attrv (case SYMBOL of
|
adam@1643
|
1665 "class" => Class attrv
|
adam@1643
|
1666 | "dynClass" => DynClass attrv
|
adam@1750
|
1667 | "style" => Style attrv
|
adam@1751
|
1668 | "dynStyle" => DynStyle attrv
|
adam@1643
|
1669 | _ =>
|
adamc@724
|
1670 let
|
adamc@724
|
1671 val sym =
|
adamc@724
|
1672 case SYMBOL of
|
adamc@724
|
1673 "type" => "Typ"
|
adamc@724
|
1674 | x => capitalize x
|
adamc@724
|
1675 in
|
adamc@724
|
1676 Normal ((CName sym, s (SYMBOLleft, SYMBOLright)),
|
adamc@724
|
1677 if (sym = "Href" orelse sym = "Src")
|
adamc@724
|
1678 andalso (case #1 attrv of
|
adamc@724
|
1679 EPrim _ => true
|
adamc@724
|
1680 | _ => false) then
|
adamc@724
|
1681 let
|
adamc@724
|
1682 val loc = s (attrvleft, attrvright)
|
adamc@724
|
1683 in
|
adamc@724
|
1684 (EApp ((EVar (["Basis"], "bless", Infer), loc),
|
adamc@724
|
1685 attrv), loc)
|
adamc@724
|
1686 end
|
adamc@724
|
1687 else
|
adamc@724
|
1688 attrv)
|
adamc@724
|
1689 end)
|
adamc@204
|
1690
|
adamc@104
|
1691 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@104
|
1692 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
|
adamc@104
|
1693 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@110
|
1694 | LBRACE eexp RBRACE (eexp)
|
adamc@226
|
1695
|
adamc@232
|
1696 query : query1 obopt lopt ofopt (let
|
adamc@229
|
1697 val loc = s (query1left, query1right)
|
adamc@230
|
1698
|
adamc@230
|
1699 val re = (ERecord [((CName "Rows", loc),
|
adamc@230
|
1700 query1),
|
adamc@230
|
1701 ((CName "OrderBy", loc),
|
adamc@231
|
1702 obopt),
|
adamc@231
|
1703 ((CName "Limit", loc),
|
adamc@232
|
1704 lopt),
|
adamc@232
|
1705 ((CName "Offset", loc),
|
adamc@232
|
1706 ofopt)], loc)
|
adamc@229
|
1707 in
|
adamc@403
|
1708 (EApp ((EVar (["Basis"], "sql_query", Infer), loc), re), loc)
|
adamc@229
|
1709 end)
|
adamc@993
|
1710
|
adamc@993
|
1711 dopt : (EVar (["Basis"], "False", Infer), dummy)
|
adamc@993
|
1712 | DISTINCT (EVar (["Basis"], "True", Infer),
|
adamc@993
|
1713 s (DISTINCTleft, DISTINCTright))
|
adamc@993
|
1714
|
adamc@993
|
1715 query1 : SELECT dopt select FROM tables wopt gopt hopt
|
adamc@209
|
1716 (let
|
adamc@204
|
1717 val loc = s (SELECTleft, tablesright)
|
adamc@207
|
1718
|
adamc@1070
|
1719 val (empties, sel, exps) =
|
adamc@207
|
1720 case select of
|
adamc@1070
|
1721 Star => ([],
|
adamc@1070
|
1722 map (fn nm =>
|
adamc@233
|
1723 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
|
adamc@233
|
1724 loc),
|
adamc@233
|
1725 (CRecord [], loc)],
|
adamc@748
|
1726 loc))) (#1 tables),
|
adamc@233
|
1727 [])
|
adamc@207
|
1728 | Items sis =>
|
adamc@207
|
1729 let
|
adam@1627
|
1730 val tabs = map (fn nm => (nm, Unknown)) (#1 tables)
|
adamc@1194
|
1731 val (_, tabs, exps) = foldl (amend_select loc)
|
adamc@1194
|
1732 (1, tabs, []) sis
|
adam@1627
|
1733 val empties = List.mapPartial (fn (nm, c) =>
|
adam@1627
|
1734 case c of
|
adam@1627
|
1735 Unknown => SOME nm
|
adam@1627
|
1736 | Selective (CRecord [], _) => SOME nm
|
adam@1627
|
1737 | _ => NONE) tabs
|
adamc@207
|
1738 in
|
adamc@1070
|
1739 (empties,
|
adamc@1070
|
1740 map (fn (nm, c) => (nm,
|
adam@1627
|
1741 case c of
|
adam@1627
|
1742 Everything =>
|
adam@1627
|
1743 (CTuple [(CWild (KRecord (KType, loc), loc), loc),
|
adam@1627
|
1744 (CRecord [], loc)], loc)
|
adam@1627
|
1745 | _ =>
|
adam@1627
|
1746 let
|
adam@1627
|
1747 val c = case c of
|
adam@1627
|
1748 Selective c => c
|
adam@1627
|
1749 | _ => (CRecord [], loc)
|
adam@1627
|
1750 in
|
adam@1627
|
1751 (CTuple [c,
|
adam@1627
|
1752 (CWild (KRecord (KType, loc), loc),
|
adam@1627
|
1753 loc)], loc)
|
adam@1627
|
1754 end)) tabs,
|
adamc@233
|
1755 exps)
|
adamc@207
|
1756 end
|
adamc@207
|
1757
|
adamc@207
|
1758 val sel = (CRecord sel, loc)
|
adamc@207
|
1759
|
adamc@226
|
1760 val grp = case gopt of
|
adamc@403
|
1761 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all",
|
adamc@403
|
1762 Infer), loc),
|
adamc@226
|
1763 (CWild (KRecord (KRecord (KType, loc), loc),
|
adamc@226
|
1764 loc), loc)), loc)
|
adamc@226
|
1765 | SOME gis =>
|
adamc@226
|
1766 let
|
adamc@748
|
1767 val tabs = map (fn nm =>
|
adamc@748
|
1768 (nm, (CRecord [], loc))) (#1 tables)
|
adamc@226
|
1769 val tabs = foldl (amend_group loc) tabs gis
|
adamc@226
|
1770
|
adamc@226
|
1771 val tabs = map (fn (nm, c) =>
|
adamc@226
|
1772 (nm,
|
adamc@226
|
1773 (CTuple [c,
|
adamc@226
|
1774 (CWild (KRecord (KType, loc),
|
adamc@226
|
1775 loc),
|
adamc@226
|
1776 loc)], loc))) tabs
|
adamc@226
|
1777 in
|
adamc@403
|
1778 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
|
adamc@226
|
1779 (CRecord tabs, loc)), loc)
|
adamc@226
|
1780 end
|
adamc@226
|
1781
|
adamc@403
|
1782 val e = (EVar (["Basis"], "sql_query1", Infer), loc)
|
adamc@1070
|
1783 val e = (ECApp (e, (CRecord (map (fn nm => (nm, (CUnit, loc))) empties),
|
adamc@1070
|
1784 loc)), loc)
|
adamc@993
|
1785 val re = (ERecord [((CName "Distinct", loc),
|
adamc@993
|
1786 dopt),
|
adamc@993
|
1787 ((CName "From", loc),
|
adamc@748
|
1788 #2 tables),
|
adamc@209
|
1789 ((CName "Where", loc),
|
adamc@223
|
1790 wopt),
|
adamc@224
|
1791 ((CName "GroupBy", loc),
|
adamc@226
|
1792 grp),
|
adamc@224
|
1793 ((CName "Having", loc),
|
adamc@224
|
1794 hopt),
|
adamc@223
|
1795 ((CName "SelectFields", loc),
|
adamc@403
|
1796 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
|
adamc@233
|
1797 sel), loc)),
|
adamc@233
|
1798 ((CName "SelectExps", loc),
|
adamc@233
|
1799 (ERecord exps, loc))], loc)
|
adamc@223
|
1800
|
adamc@209
|
1801 val e = (EApp (e, re), loc)
|
adamc@204
|
1802 in
|
adamc@207
|
1803 e
|
adamc@204
|
1804 end)
|
adam@1427
|
1805 | query1 UNION query1 (sql_relop ("union", false, query11, query12, s (query11left, query12right)))
|
adam@1427
|
1806 | query1 INTERSECT query1 (sql_relop ("intersect", false, query11, query12, s (query11left, query12right)))
|
adam@1427
|
1807 | query1 EXCEPT query1 (sql_relop ("except", false, query11, query12, s (query11left, query12right)))
|
adam@1427
|
1808 | query1 UNION ALL query1 (sql_relop ("union", true, query11, query12, s (query11left, query12right)))
|
adam@1427
|
1809 | query1 INTERSECT ALL query1 (sql_relop ("intersect", true, query11, query12, s (query11left, query12right)))
|
adam@1427
|
1810 | query1 EXCEPT ALL query1 (sql_relop ("except", true, query11, query12, s (query11left, query12right)))
|
adamc@1070
|
1811 | LBRACE LBRACE LBRACE eexp RBRACE RBRACE RBRACE (eexp)
|
adamc@204
|
1812
|
adamc@749
|
1813 tables : fitem (fitem)
|
adamc@749
|
1814 | fitem COMMA tables (let
|
adamc@749
|
1815 val loc = s (fitemleft, tablesright)
|
adamc@748
|
1816
|
adamc@748
|
1817 val e = (EVar (["Basis"], "sql_from_comma", Infer), loc)
|
adamc@749
|
1818 val e = (EApp (e, #2 fitem), loc)
|
adamc@748
|
1819 in
|
adamc@749
|
1820 (#1 fitem @ #1 tables,
|
adamc@748
|
1821 (EApp (e, #2 tables), loc))
|
adamc@748
|
1822 end)
|
adamc@204
|
1823
|
adamc@749
|
1824 fitem : table' ([#1 table'], #2 table')
|
adamc@1265
|
1825 | LBRACE LBRACE eexp RBRACE RBRACE (tnamesOf eexp, eexp)
|
adamc@749
|
1826 | fitem JOIN fitem ON sqlexp (let
|
adamc@749
|
1827 val loc = s (fitem1left, sqlexpright)
|
adamc@749
|
1828
|
adamc@749
|
1829 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
|
adamc@749
|
1830 val e = (EApp (e, #2 fitem1), loc)
|
adamc@749
|
1831 val e = (EApp (e, #2 fitem2), loc)
|
adamc@749
|
1832 in
|
adamc@749
|
1833 (#1 fitem1 @ #1 fitem2,
|
adamc@749
|
1834 (EApp (e, sqlexp), loc))
|
adamc@749
|
1835 end)
|
adamc@749
|
1836 | fitem INNER JOIN fitem ON sqlexp (let
|
adamc@749
|
1837 val loc = s (fitem1left, sqlexpright)
|
adamc@749
|
1838
|
adamc@749
|
1839 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
|
adamc@749
|
1840 val e = (EApp (e, #2 fitem1), loc)
|
adamc@749
|
1841 val e = (EApp (e, #2 fitem2), loc)
|
adamc@749
|
1842 in
|
adamc@749
|
1843 (#1 fitem1 @ #1 fitem2,
|
adamc@749
|
1844 (EApp (e, sqlexp), loc))
|
adamc@749
|
1845 end)
|
adamc@749
|
1846 | fitem CROSS JOIN fitem (let
|
adamc@749
|
1847 val loc = s (fitem1left, fitem2right)
|
adamc@749
|
1848
|
adamc@749
|
1849 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
|
adamc@749
|
1850 val e = (EApp (e, #2 fitem1), loc)
|
adamc@749
|
1851 val e = (EApp (e, #2 fitem2), loc)
|
adamc@749
|
1852 val tru = sql_inject (EVar (["Basis"], "True", Infer), loc)
|
adamc@749
|
1853 in
|
adamc@749
|
1854 (#1 fitem1 @ #1 fitem2,
|
adamc@749
|
1855 (EApp (e, tru), loc))
|
adamc@749
|
1856 end)
|
adamc@750
|
1857 | fitem LEFT JOIN fitem ON sqlexp (let
|
adamc@750
|
1858 val loc = s (fitem1left, sqlexpright)
|
adamc@750
|
1859
|
adamc@750
|
1860 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
|
adamc@750
|
1861 val e = (EApp (e, #2 fitem1), loc)
|
adamc@750
|
1862 val e = (EApp (e, #2 fitem2), loc)
|
adamc@750
|
1863 in
|
adamc@750
|
1864 (#1 fitem1 @ #1 fitem2,
|
adamc@750
|
1865 (EApp (e, sqlexp), loc))
|
adamc@750
|
1866 end)
|
adamc@751
|
1867 | fitem LEFT OUTER JOIN fitem ON sqlexp (let
|
adamc@751
|
1868 val loc = s (fitem1left, sqlexpright)
|
adamc@751
|
1869
|
adamc@751
|
1870 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
|
adamc@751
|
1871 val e = (EApp (e, #2 fitem1), loc)
|
adamc@751
|
1872 val e = (EApp (e, #2 fitem2), loc)
|
adamc@751
|
1873 in
|
adamc@751
|
1874 (#1 fitem1 @ #1 fitem2,
|
adamc@751
|
1875 (EApp (e, sqlexp), loc))
|
adamc@751
|
1876 end)
|
adamc@751
|
1877 | fitem RIGHT JOIN fitem ON sqlexp (let
|
adamc@751
|
1878 val loc = s (fitem1left, sqlexpright)
|
adamc@751
|
1879
|
adamc@751
|
1880 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
|
adamc@751
|
1881 val e = (EApp (e, #2 fitem1), loc)
|
adamc@751
|
1882 val e = (EApp (e, #2 fitem2), loc)
|
adamc@751
|
1883 in
|
adamc@751
|
1884 (#1 fitem1 @ #1 fitem2,
|
adamc@751
|
1885 (EApp (e, sqlexp), loc))
|
adamc@751
|
1886 end)
|
adamc@751
|
1887 | fitem RIGHT OUTER JOIN fitem ON sqlexp (let
|
adamc@751
|
1888 val loc = s (fitem1left, sqlexpright)
|
adamc@751
|
1889
|
adamc@751
|
1890 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
|
adamc@751
|
1891 val e = (EApp (e, #2 fitem1), loc)
|
adamc@751
|
1892 val e = (EApp (e, #2 fitem2), loc)
|
adamc@751
|
1893 in
|
adamc@751
|
1894 (#1 fitem1 @ #1 fitem2,
|
adamc@751
|
1895 (EApp (e, sqlexp), loc))
|
adamc@751
|
1896 end)
|
adamc@751
|
1897 | fitem FULL JOIN fitem ON sqlexp (let
|
adamc@751
|
1898 val loc = s (fitem1left, sqlexpright)
|
adamc@751
|
1899
|
adamc@751
|
1900 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
|
adamc@751
|
1901 val e = (EApp (e, #2 fitem1), loc)
|
adamc@751
|
1902 val e = (EApp (e, #2 fitem2), loc)
|
adamc@751
|
1903 in
|
adamc@751
|
1904 (#1 fitem1 @ #1 fitem2,
|
adamc@751
|
1905 (EApp (e, sqlexp), loc))
|
adamc@751
|
1906 end)
|
adamc@751
|
1907 | fitem FULL OUTER JOIN fitem ON sqlexp (let
|
adamc@751
|
1908 val loc = s (fitem1left, sqlexpright)
|
adamc@751
|
1909
|
adamc@751
|
1910 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
|
adamc@751
|
1911 val e = (EApp (e, #2 fitem1), loc)
|
adamc@751
|
1912 val e = (EApp (e, #2 fitem2), loc)
|
adamc@751
|
1913 in
|
adamc@751
|
1914 (#1 fitem1 @ #1 fitem2,
|
adamc@751
|
1915 (EApp (e, sqlexp), loc))
|
adamc@751
|
1916 end)
|
adamc@1192
|
1917 | LPAREN query RPAREN AS tname (let
|
adamc@1192
|
1918 val loc = s (LPARENleft, RPARENright)
|
adamc@1192
|
1919
|
adamc@1192
|
1920 val e = (EVar (["Basis"], "sql_from_query", Infer), loc)
|
adamc@1192
|
1921 val e = (ECApp (e, tname), loc)
|
adamc@1192
|
1922 in
|
adamc@1192
|
1923 ([tname], (EApp (e, query), loc))
|
adamc@1192
|
1924 end)
|
adamc@749
|
1925
|
adamc@204
|
1926 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@204
|
1927 | LBRACE cexp RBRACE (cexp)
|
adamc@204
|
1928
|
adamc@243
|
1929 table : SYMBOL ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)),
|
adamc@403
|
1930 (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
|
adamc@403
|
1931 | SYMBOL AS tname (tname, (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
|
adamc@221
|
1932 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
|
adamc@207
|
1933
|
adamc@748
|
1934 table' : table (let
|
adamc@748
|
1935 val loc = s (tableleft, tableright)
|
adamc@748
|
1936 val e = (EVar (["Basis"], "sql_from_table", Infer), loc)
|
adamc@748
|
1937 val e = (ECApp (e, #1 table), loc)
|
adamc@748
|
1938 in
|
adamc@748
|
1939 (#1 table, (EApp (e, #2 table), loc))
|
adamc@748
|
1940 end)
|
adamc@748
|
1941
|
adamc@243
|
1942 tident : SYMBOL (CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright))
|
adamc@207
|
1943 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@221
|
1944 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
|
adamc@207
|
1945
|
adamc@207
|
1946 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@207
|
1947 | LBRACE cexp RBRACE (cexp)
|
adamc@207
|
1948
|
adamc@207
|
1949 seli : tident DOT fident (Field (tident, fident))
|
adamc@1194
|
1950 | sqlexp (Exp (NONE, sqlexp))
|
adamc@1194
|
1951 | sqlexp AS fident (Exp (SOME fident, sqlexp))
|
adamc@341
|
1952 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (Fields (tident, cexp))
|
adam@1627
|
1953 | tident DOT STAR (StarFields tident)
|
adamc@207
|
1954
|
adamc@207
|
1955 selis : seli ([seli])
|
adamc@207
|
1956 | seli COMMA selis (seli :: selis)
|
adamc@207
|
1957
|
adamc@207
|
1958 select : STAR (Star)
|
adamc@207
|
1959 | selis (Items selis)
|
adamc@209
|
1960
|
adamc@403
|
1961 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", Infer),
|
adamc@209
|
1962 s (TRUEleft, TRUEright)))
|
adamc@403
|
1963 | FALSE (sql_inject (EVar (["Basis"], "False", Infer),
|
adamc@209
|
1964 s (FALSEleft, FALSEright)))
|
adamc@209
|
1965
|
adamc@222
|
1966 | INT (sql_inject (EPrim (Prim.Int INT),
|
adamc@222
|
1967 s (INTleft, INTright)))
|
adamc@222
|
1968 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
|
adamc@222
|
1969 s (FLOATleft, FLOATright)))
|
adamc@229
|
1970 | STRING (sql_inject (EPrim (Prim.String STRING),
|
adamc@229
|
1971 s (STRINGleft, STRINGright)))
|
adamc@441
|
1972 | CURRENT_TIMESTAMP (sql_nfunc ("current_timestamp",
|
adamc@441
|
1973 s (CURRENT_TIMESTAMPleft, CURRENT_TIMESTAMPright)))
|
adamc@222
|
1974
|
adamc@221
|
1975 | tident DOT fident (let
|
adamc@221
|
1976 val loc = s (tidentleft, fidentright)
|
adamc@403
|
1977 val e = (EVar (["Basis"], "sql_field", Infer), loc)
|
adamc@221
|
1978 val e = (ECApp (e, tident), loc)
|
adamc@221
|
1979 in
|
adamc@221
|
1980 (ECApp (e, fident), loc)
|
adamc@221
|
1981 end)
|
adamc@234
|
1982 | CSYMBOL (let
|
adamc@234
|
1983 val loc = s (CSYMBOLleft, CSYMBOLright)
|
adamc@310
|
1984 in
|
adamc@310
|
1985 if !inDml then
|
adamc@310
|
1986 let
|
adamc@403
|
1987 val e = (EVar (["Basis"], "sql_field", Infer), loc)
|
adamc@310
|
1988 val e = (ECApp (e, (CName "T", loc)), loc)
|
adamc@310
|
1989 in
|
adamc@310
|
1990 (ECApp (e, (CName CSYMBOL, loc)), loc)
|
adamc@310
|
1991 end
|
adamc@310
|
1992 else
|
adamc@310
|
1993 let
|
adamc@403
|
1994 val e = (EVar (["Basis"], "sql_exp", Infer), loc)
|
adamc@310
|
1995 in
|
adamc@310
|
1996 (ECApp (e, (CName CSYMBOL, loc)), loc)
|
adamc@310
|
1997 end
|
adamc@310
|
1998 end)
|
adamc@221
|
1999
|
adamc@471
|
2000 | LBRACE eexp RBRACE (eexp)
|
adamc@470
|
2001
|
adamc@559
|
2002 | sqlexp EQ sqlexp (sql_binary ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
2003 | sqlexp NE sqlexp (sql_binary ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
2004 | sqlexp LT sqlexp (sql_binary ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
2005 | sqlexp LE sqlexp (sql_binary ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
2006 | sqlexp GT sqlexp (sql_binary ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
2007 | sqlexp GE sqlexp (sql_binary ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
2008
|
adamc@559
|
2009 | sqlexp PLUS sqlexp (sql_binary ("plus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
2010 | sqlexp MINUS sqlexp (sql_binary ("minus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
2011 | sqlexp STAR sqlexp (sql_binary ("times", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
2012 | sqlexp DIVIDE sqlexp (sql_binary ("div", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
2013 | sqlexp MOD sqlexp (sql_binary ("mod", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
2014
|
adamc@220
|
2015 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@220
|
2016 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@559
|
2017
|
kkallio@1607
|
2018 | sqlexp LIKE sqlexp (sql_binary ("like", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
kkallio@1607
|
2019
|
adamc@220
|
2020 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
|
adamc@559
|
2021 | MINUS sqlexp (sql_unary ("neg", sqlexp, s (MINUSleft, sqlexpright)))
|
adamc@220
|
2022
|
adamc@470
|
2023 | sqlexp IS NULL (let
|
adamc@470
|
2024 val loc = s (sqlexpleft, NULLright)
|
adamc@470
|
2025 in
|
adamc@470
|
2026 (EApp ((EVar (["Basis"], "sql_is_null", Infer), loc),
|
adamc@470
|
2027 sqlexp), loc)
|
adamc@470
|
2028 end)
|
adamc@470
|
2029
|
kkallio@1572
|
2030 | CIF sqlexp CTHEN sqlexp CELSE sqlexp (let
|
kkallio@1572
|
2031 val loc = s (CIFleft, sqlexp3right)
|
kkallio@1572
|
2032 val e = (EVar (["Basis"], "sql_if_then_else", Infer), loc)
|
kkallio@1572
|
2033 in
|
kkallio@1572
|
2034 (EApp ((EApp ((EApp (e, sqlexp1), loc), sqlexp2), loc), sqlexp3), loc)
|
kkallio@1572
|
2035 end)
|
kkallio@1572
|
2036
|
adamc@471
|
2037 | LBRACE LBRACK eexp RBRACK RBRACE (sql_inject (#1 eexp,
|
adamc@471
|
2038 s (LBRACEleft, RBRACEright)))
|
adamc@220
|
2039 | LPAREN sqlexp RPAREN (sqlexp)
|
adamc@210
|
2040
|
adamc@467
|
2041 | NULL (sql_inject ((EVar (["Basis"], "None", Infer),
|
adamc@467
|
2042 s (NULLleft, NULLright))))
|
adamc@467
|
2043
|
adam@1776
|
2044 | COUNT LPAREN STAR RPAREN window (let
|
adam@1776
|
2045 val loc = s (COUNTleft, windowright)
|
adam@1776
|
2046 in
|
adam@1776
|
2047 case window of
|
adam@1776
|
2048 NONE => (EVar (["Basis"], "sql_count", Infer), loc)
|
adam@1776
|
2049 | SOME _ =>
|
adam@1776
|
2050 let
|
adam@1776
|
2051 val e = (EVar (["Basis"], "sql_window_count", Infer), loc)
|
adam@1776
|
2052 in
|
adam@1777
|
2053 applyWindow loc e window
|
adam@1776
|
2054 end
|
adam@1776
|
2055 end)
|
adam@1776
|
2056 | RANK UNIT window (let
|
adam@1776
|
2057 val loc = s (RANKleft, windowright)
|
adam@1776
|
2058 val e = (EVar (["Basis"], "sql_window_rank", Infer), loc)
|
adam@1776
|
2059 in
|
adam@1777
|
2060 applyWindow loc e window
|
adam@1776
|
2061 end)
|
adam@1776
|
2062 | COUNT LPAREN sqlexp RPAREN window (let
|
adam@1776
|
2063 val loc = s (COUNTleft, windowright)
|
adam@1776
|
2064
|
adam@1776
|
2065 val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
|
adam@1776
|
2066 in
|
adam@1776
|
2067 case window of
|
adam@1776
|
2068 NONE =>
|
adam@1776
|
2069 let
|
adam@1776
|
2070 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
|
adam@1776
|
2071 e), loc)
|
adam@1776
|
2072 in
|
adam@1776
|
2073 (EApp (e, sqlexp), loc)
|
adam@1776
|
2074 end
|
adam@1776
|
2075 | SOME _ =>
|
adam@1776
|
2076 let
|
adam@1776
|
2077 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc),
|
adam@1776
|
2078 e), loc)
|
adam@1776
|
2079 val e = (EApp (e, sqlexp), loc)
|
adam@1776
|
2080 in
|
adam@1777
|
2081 applyWindow loc e window
|
adam@1776
|
2082 end
|
adam@1776
|
2083 end)
|
adam@1776
|
2084 | sqlagg LPAREN sqlexp RPAREN window (let
|
adam@1776
|
2085 val loc = s (sqlaggleft, windowright)
|
adamc@1187
|
2086
|
adam@1776
|
2087 val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
|
adam@1776
|
2088 in
|
adam@1776
|
2089 case window of
|
adam@1776
|
2090 NONE =>
|
adam@1776
|
2091 let
|
adam@1776
|
2092 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
|
adam@1776
|
2093 e), loc)
|
adam@1776
|
2094 in
|
adam@1776
|
2095 (EApp (e, sqlexp), loc)
|
adam@1776
|
2096 end
|
adam@1776
|
2097 | SOME _ =>
|
adam@1776
|
2098 let
|
adam@1776
|
2099 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc),
|
adam@1776
|
2100 e), loc)
|
adam@1776
|
2101 val e = (EApp (e, sqlexp), loc)
|
adam@1776
|
2102 in
|
adam@1777
|
2103 applyWindow loc e window
|
adam@1776
|
2104 end
|
adam@1776
|
2105 end)
|
adam@1602
|
2106 | COALESCE LPAREN sqlexp COMMA sqlexp RPAREN
|
adam@1602
|
2107 (let
|
adam@1602
|
2108 val loc = s (COALESCEright, sqlexp2right)
|
adam@1602
|
2109 val e = (EVar (["Basis"], "sql_coalesce", Infer), loc)
|
adam@1602
|
2110 val e = (EApp (e, sqlexp1), loc)
|
adam@1602
|
2111 in
|
adam@1602
|
2112 (EApp (e, sqlexp2), loc)
|
adam@1602
|
2113 end)
|
adamc@746
|
2114 | fname LPAREN sqlexp RPAREN (let
|
adamc@746
|
2115 val loc = s (fnameleft, RPARENright)
|
adamc@746
|
2116
|
adamc@746
|
2117 val e = (EVar (["Basis"], "sql_ufunc", Infer), loc)
|
adamc@746
|
2118 val e = (EApp (e, fname), loc)
|
adamc@746
|
2119 in
|
adamc@746
|
2120 (EApp (e, sqlexp), loc)
|
adamc@746
|
2121 end)
|
adamc@1191
|
2122 | LPAREN query RPAREN (let
|
adamc@1191
|
2123 val loc = s (LPARENleft, RPARENright)
|
adamc@1191
|
2124
|
adamc@1191
|
2125 val e = (EVar (["Basis"], "sql_subquery", Infer), loc)
|
adamc@1191
|
2126 in
|
adamc@1191
|
2127 (EApp (e, query), loc)
|
adamc@1191
|
2128 end)
|
adamc@746
|
2129
|
adam@1776
|
2130 window : (NONE)
|
adam@1777
|
2131 | OVER LPAREN pbopt obopt RPAREN (SOME (pbopt, obopt))
|
adam@1777
|
2132
|
adam@1777
|
2133 pbopt : ((EVar (["Basis"], "sql_no_partition", Infer), dummy))
|
adam@1777
|
2134 | PARTITION BY sqlexp (let
|
adam@1777
|
2135 val loc = s (PARTITIONleft, sqlexpright)
|
adam@1777
|
2136
|
adam@1777
|
2137 val e = (EVar (["Basis"], "sql_partition", Infer), loc)
|
adam@1777
|
2138 in
|
adam@1777
|
2139 (EApp (e, sqlexp), loc)
|
adam@1777
|
2140 end)
|
adam@1776
|
2141
|
adamc@746
|
2142 fname : SYMBOL (EVar (["Basis"], "sql_" ^ SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
|
adamc@746
|
2143 | LBRACE eexp RBRACE (eexp)
|
adamc@235
|
2144
|
adamc@403
|
2145 wopt : (sql_inject (EVar (["Basis"], "True", Infer),
|
adamc@230
|
2146 dummy))
|
adamc@209
|
2147 | CWHERE sqlexp (sqlexp)
|
adamc@226
|
2148
|
adamc@226
|
2149 groupi : tident DOT fident (GField (tident, fident))
|
adam@1425
|
2150 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (GFields (tident, cexp))
|
adamc@226
|
2151
|
adamc@226
|
2152 groupis: groupi ([groupi])
|
adamc@226
|
2153 | groupi COMMA groupis (groupi :: groupis)
|
adamc@226
|
2154
|
adamc@226
|
2155 gopt : (NONE)
|
adamc@226
|
2156 | GROUP BY groupis (SOME groupis)
|
adamc@227
|
2157
|
adamc@403
|
2158 hopt : (sql_inject (EVar (["Basis"], "True", Infer),
|
adamc@230
|
2159 dummy))
|
adamc@227
|
2160 | HAVING sqlexp (sqlexp)
|
adamc@230
|
2161
|
adamc@403
|
2162 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
|
adamc@234
|
2163 (CWild (KRecord (KType, dummy), dummy), dummy)),
|
adamc@230
|
2164 dummy)
|
adamc@230
|
2165 | ORDER BY obexps (obexps)
|
adamc@230
|
2166
|
adamc@268
|
2167 obitem : sqlexp diropt (sqlexp, diropt)
|
adamc@268
|
2168
|
adamc@268
|
2169 obexps : obitem (let
|
adamc@268
|
2170 val loc = s (obitemleft, obitemright)
|
adamc@230
|
2171
|
adamc@403
|
2172 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), loc),
|
adamc@234
|
2173 (CWild (KRecord (KType, loc), loc), loc)),
|
adamc@230
|
2174 loc)
|
adamc@403
|
2175 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
|
adamc@268
|
2176 #1 obitem), loc)
|
adamc@268
|
2177 val e = (EApp (e, #2 obitem), loc)
|
adamc@230
|
2178 in
|
adamc@230
|
2179 (EApp (e, e'), loc)
|
adamc@230
|
2180 end)
|
adamc@268
|
2181 | obitem COMMA obexps (let
|
adamc@268
|
2182 val loc = s (obitemleft, obexpsright)
|
adamc@230
|
2183
|
adamc@403
|
2184 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
|
adamc@268
|
2185 #1 obitem), loc)
|
adamc@268
|
2186 val e = (EApp (e, #2 obitem), loc)
|
adamc@230
|
2187 in
|
adamc@230
|
2188 (EApp (e, obexps), loc)
|
adamc@230
|
2189 end)
|
adam@1682
|
2190 | RANDOM popt (EVar (["Basis"], "sql_order_by_random", Infer), s (RANDOMleft, poptright))
|
adam@1682
|
2191
|
adam@1682
|
2192 popt : ()
|
adam@1682
|
2193 | LPAREN RPAREN ()
|
adam@1684
|
2194 | UNIT ()
|
adamc@231
|
2195
|
adamc@403
|
2196 diropt : (EVar (["Basis"], "sql_asc", Infer), dummy)
|
adamc@403
|
2197 | ASC (EVar (["Basis"], "sql_asc", Infer), s (ASCleft, ASCright))
|
adamc@403
|
2198 | DESC (EVar (["Basis"], "sql_desc", Infer), s (DESCleft, DESCright))
|
adam@1543
|
2199 | LBRACE eexp RBRACE (eexp)
|
adamc@268
|
2200
|
adamc@403
|
2201 lopt : (EVar (["Basis"], "sql_no_limit", Infer), dummy)
|
adamc@403
|
2202 | LIMIT ALL (EVar (["Basis"], "sql_no_limit", Infer), dummy)
|
adamc@231
|
2203 | LIMIT sqlint (let
|
adamc@231
|
2204 val loc = s (LIMITleft, sqlintright)
|
adamc@231
|
2205 in
|
adamc@403
|
2206 (EApp ((EVar (["Basis"], "sql_limit", Infer), loc), sqlint), loc)
|
adamc@231
|
2207 end)
|
adamc@231
|
2208
|
adamc@403
|
2209 ofopt : (EVar (["Basis"], "sql_no_offset", Infer), dummy)
|
adamc@232
|
2210 | OFFSET sqlint (let
|
adamc@232
|
2211 val loc = s (OFFSETleft, sqlintright)
|
adamc@232
|
2212 in
|
adamc@403
|
2213 (EApp ((EVar (["Basis"], "sql_offset", Infer), loc), sqlint), loc)
|
adamc@232
|
2214 end)
|
adamc@232
|
2215
|
adamc@231
|
2216 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@231
|
2217 | LBRACE eexp RBRACE (eexp)
|
adamc@236
|
2218
|
adamc@236
|
2219 sqlagg : AVG ("avg")
|
adamc@236
|
2220 | SUM ("sum")
|
adamc@236
|
2221 | MIN ("min")
|
adamc@236
|
2222 | MAX ("max")
|