adamc@1
|
1 (* Copyright (c) 2008, Adam Chlipala
|
adamc@1
|
2 * All rights reserved.
|
adamc@1
|
3 *
|
adamc@1
|
4 * Redistribution and use in source and binary forms, with or without
|
adamc@1
|
5 * modification, are permitted provided that the following conditions are met:
|
adamc@1
|
6 *
|
adamc@1
|
7 * - Redistributions of source code must retain the above copyright notice,
|
adamc@1
|
8 * this list of conditions and the following disclaimer.
|
adamc@1
|
9 * - Redistributions in binary form must reproduce the above copyright notice,
|
adamc@1
|
10 * this list of conditions and the following disclaimer in the documentation
|
adamc@1
|
11 * and/or other materials provided with the distribution.
|
adamc@1
|
12 * - The names of contributors may not be used to endorse or promote products
|
adamc@1
|
13 * derived from this software without specific prior written permission.
|
adamc@1
|
14 *
|
adamc@1
|
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
adamc@1
|
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
adamc@1
|
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
adamc@1
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
adamc@1
|
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
adamc@1
|
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
adamc@1
|
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
adamc@1
|
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
adamc@1
|
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
adamc@1
|
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
adamc@1
|
25 * POSSIBILITY OF SUCH DAMAGE.
|
adamc@1
|
26 *)
|
adamc@1
|
27
|
adamc@1
|
28 (* Grammar for Laconic/Web programs *)
|
adamc@1
|
29
|
adamc@4
|
30 open Source
|
adamc@1
|
31
|
adamc@1
|
32 val s = ErrorMsg.spanOf
|
adamc@1
|
33
|
adamc@204
|
34 fun capitalize "" = ""
|
adamc@204
|
35 | capitalize s = str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE)
|
adamc@104
|
36
|
adamc@203
|
37 fun entable t =
|
adamc@203
|
38 case #1 t of
|
adamc@203
|
39 TRecord c => c
|
adamc@203
|
40 | _ => t
|
adamc@203
|
41
|
adamc@207
|
42 datatype select_item =
|
adamc@207
|
43 Field of con * con
|
adamc@207
|
44
|
adamc@207
|
45 datatype select =
|
adamc@207
|
46 Star
|
adamc@207
|
47 | Items of select_item list
|
adamc@207
|
48
|
adamc@226
|
49 datatype group_item =
|
adamc@226
|
50 GField of con * con
|
adamc@226
|
51
|
adamc@207
|
52 fun eqTnames ((c1, _), (c2, _)) =
|
adamc@207
|
53 case (c1, c2) of
|
adamc@207
|
54 (CVar (ms1, x1), CVar (ms2, x2)) => ms1 = ms2 andalso x1 = x2
|
adamc@207
|
55 | (CName x1, CName x2) => x1 = x2
|
adamc@207
|
56 | _ => false
|
adamc@207
|
57
|
adamc@207
|
58 fun amend_select loc (si, tabs) =
|
adamc@207
|
59 let
|
adamc@207
|
60 val (tx, c) = case si of
|
adamc@207
|
61 Field (tx, fx) => (tx, (CRecord ([(fx, (CWild (KType, loc), loc))]), loc))
|
adamc@207
|
62
|
adamc@207
|
63 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
|
adamc@207
|
64 if eqTnames (tx, tx') then
|
adamc@207
|
65 ((tx', (CConcat (c, c'), loc)), true)
|
adamc@207
|
66 else
|
adamc@207
|
67 ((tx', c'), found))
|
adamc@207
|
68 false tabs
|
adamc@207
|
69 in
|
adamc@207
|
70 if found then
|
adamc@207
|
71 ()
|
adamc@207
|
72 else
|
adamc@207
|
73 ErrorMsg.errorAt loc "Select of field from unbound table";
|
adamc@207
|
74
|
adamc@207
|
75 tabs
|
adamc@207
|
76 end
|
adamc@207
|
77
|
adamc@226
|
78 fun amend_group loc (gi, tabs) =
|
adamc@226
|
79 let
|
adamc@226
|
80 val (tx, c) = case gi of
|
adamc@226
|
81 GField (tx, fx) => (tx, (CRecord ([(fx, (CWild (KType, loc), loc))]), loc))
|
adamc@226
|
82
|
adamc@226
|
83 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
|
adamc@226
|
84 if eqTnames (tx, tx') then
|
adamc@226
|
85 ((tx', (CConcat (c, c'), loc)), true)
|
adamc@226
|
86 else
|
adamc@226
|
87 ((tx', c'), found))
|
adamc@226
|
88 false tabs
|
adamc@226
|
89 in
|
adamc@226
|
90 if found then
|
adamc@226
|
91 ()
|
adamc@226
|
92 else
|
adamc@226
|
93 ErrorMsg.errorAt loc "Select of field from unbound table";
|
adamc@226
|
94
|
adamc@226
|
95 tabs
|
adamc@226
|
96 end
|
adamc@226
|
97
|
adamc@209
|
98 fun sql_inject (v, t, loc) =
|
adamc@209
|
99 let
|
adamc@209
|
100 val e = (EApp ((EVar (["Basis"], "sql_inject"), loc), (v, loc)), loc)
|
adamc@209
|
101 in
|
adamc@209
|
102 (EApp (e, (t, loc)), loc)
|
adamc@209
|
103 end
|
adamc@209
|
104
|
adamc@219
|
105 fun sql_compare (oper, sqlexp1, sqlexp2, loc) =
|
adamc@219
|
106 let
|
adamc@219
|
107 val e = (EVar (["Basis"], "sql_comparison"), loc)
|
adamc@219
|
108 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper), loc)), loc)
|
adamc@219
|
109 val e = (EApp (e, sqlexp1), loc)
|
adamc@219
|
110 val e = (EApp (e, sqlexp2), loc)
|
adamc@219
|
111 in
|
adamc@220
|
112 (EApp (e, (EWild, loc)), loc)
|
adamc@220
|
113 end
|
adamc@220
|
114
|
adamc@220
|
115 fun sql_binary (oper, sqlexp1, sqlexp2, loc) =
|
adamc@220
|
116 let
|
adamc@220
|
117 val e = (EVar (["Basis"], "sql_binary"), loc)
|
adamc@220
|
118 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper), loc)), loc)
|
adamc@220
|
119 val e = (EApp (e, sqlexp1), loc)
|
adamc@220
|
120 in
|
adamc@220
|
121 (EApp (e, sqlexp2), loc)
|
adamc@220
|
122 end
|
adamc@220
|
123
|
adamc@220
|
124 fun sql_unary (oper, sqlexp, loc) =
|
adamc@220
|
125 let
|
adamc@220
|
126 val e = (EVar (["Basis"], "sql_unary"), loc)
|
adamc@220
|
127 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper), loc)), loc)
|
adamc@220
|
128 in
|
adamc@220
|
129 (EApp (e, sqlexp), loc)
|
adamc@219
|
130 end
|
adamc@219
|
131
|
adamc@1
|
132 %%
|
adamc@1
|
133 %header (functor LacwebLrValsFn(structure Token : TOKEN))
|
adamc@1
|
134
|
adamc@1
|
135 %term
|
adamc@1
|
136 EOF
|
adamc@14
|
137 | STRING of string | INT of Int64.int | FLOAT of Real64.real
|
adamc@1
|
138 | SYMBOL of string | CSYMBOL of string
|
adamc@1
|
139 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
|
adamc@156
|
140 | EQ | COMMA | COLON | DCOLON | TCOLON | DOT | HASH | UNDER | UNDERUNDER | BAR
|
adamc@219
|
141 | DIVIDE | DOTDOTDOT
|
adamc@211
|
142 | CON | LTYPE | VAL | REC | AND | FOLD | UNIT | KUNIT | CLASS
|
adamc@156
|
143 | DATATYPE | OF
|
adamc@7
|
144 | TYPE | NAME
|
adamc@195
|
145 | ARROW | LARROW | DARROW | STAR
|
adamc@149
|
146 | FN | PLUSPLUS | MINUSMINUS | DOLLAR | TWIDDLE
|
adamc@88
|
147 | STRUCTURE | SIGNATURE | STRUCT | SIG | END | FUNCTOR | WHERE | EXTERN
|
adamc@203
|
148 | INCLUDE | OPEN | CONSTRAINT | CONSTRAINTS | EXPORT | TABLE
|
adamc@190
|
149 | CASE | IF | THEN | ELSE
|
adamc@1
|
150
|
adamc@91
|
151 | XML_BEGIN of string | XML_END
|
adamc@91
|
152 | NOTAGS of string
|
adamc@91
|
153 | BEGIN_TAG of string | END_TAG of string
|
adamc@91
|
154
|
adamc@227
|
155 | SELECT | FROM | AS | CWHERE | GROUP | BY | HAVING
|
adamc@220
|
156 | TRUE | FALSE | CAND | OR | NOT
|
adamc@219
|
157 | NE | LT | LE | GT | GE
|
adamc@204
|
158
|
adamc@30
|
159 %nonterm
|
adamc@1
|
160 file of decl list
|
adamc@1
|
161 | decls of decl list
|
adamc@1
|
162 | decl of decl
|
adamc@123
|
163 | vali of string * con option * exp
|
adamc@123
|
164 | valis of (string * con option * exp) list
|
adamc@1
|
165
|
adamc@191
|
166 | dargs of string list
|
adamc@156
|
167 | barOpt of unit
|
adamc@156
|
168 | dcons of (string * con option) list
|
adamc@156
|
169 | dcon of string * con option
|
adamc@156
|
170
|
adamc@30
|
171 | sgn of sgn
|
adamc@42
|
172 | sgntm of sgn
|
adamc@30
|
173 | sgi of sgn_item
|
adamc@30
|
174 | sgis of sgn_item list
|
adamc@30
|
175
|
adamc@30
|
176 | str of str
|
adamc@30
|
177
|
adamc@1
|
178 | kind of kind
|
adamc@207
|
179 | ktuple of kind list
|
adamc@1
|
180 | kcolon of explicitness
|
adamc@1
|
181
|
adamc@34
|
182 | path of string list * string
|
adamc@156
|
183 | cpath of string list * string
|
adamc@34
|
184 | spath of str
|
adamc@59
|
185 | mpath of string list
|
adamc@34
|
186
|
adamc@1
|
187 | cexp of con
|
adamc@1
|
188 | capps of con
|
adamc@1
|
189 | cterm of con
|
adamc@195
|
190 | ctuple of con list
|
adamc@207
|
191 | ctuplev of con list
|
adamc@1
|
192 | ident of con
|
adamc@200
|
193 | idents of con list
|
adamc@1
|
194 | rcon of (con * con) list
|
adamc@83
|
195 | rconn of (con * con) list
|
adamc@1
|
196 | rcone of (con * con) list
|
adamc@1
|
197
|
adamc@8
|
198 | eexp of exp
|
adamc@8
|
199 | eapps of exp
|
adamc@8
|
200 | eterm of exp
|
adamc@195
|
201 | etuple of exp list
|
adamc@12
|
202 | rexp of (con * exp) list
|
adamc@91
|
203 | xml of exp
|
adamc@91
|
204 | xmlOne of exp
|
adamc@141
|
205 | tag of string * exp
|
adamc@141
|
206 | tagHead of string * exp
|
adamc@8
|
207
|
adamc@170
|
208 | branch of pat * exp
|
adamc@170
|
209 | branchs of (pat * exp) list
|
adamc@170
|
210 | pat of pat
|
adamc@170
|
211 | pterm of pat
|
adamc@174
|
212 | rpat of (string * pat) list * bool
|
adamc@195
|
213 | ptuple of pat list
|
adamc@170
|
214
|
adamc@104
|
215 | attrs of (con * exp) list
|
adamc@104
|
216 | attr of con * exp
|
adamc@104
|
217 | attrv of exp
|
adamc@104
|
218
|
adamc@204
|
219 | query of exp
|
adamc@226
|
220 | query1 of exp
|
adamc@204
|
221 | tables of (con * exp) list
|
adamc@204
|
222 | tname of con
|
adamc@204
|
223 | table of con * exp
|
adamc@207
|
224 | tident of con
|
adamc@207
|
225 | fident of con
|
adamc@207
|
226 | seli of select_item
|
adamc@207
|
227 | selis of select_item list
|
adamc@207
|
228 | select of select
|
adamc@209
|
229 | sqlexp of exp
|
adamc@209
|
230 | wopt of exp
|
adamc@226
|
231 | groupi of group_item
|
adamc@226
|
232 | groupis of group_item list
|
adamc@226
|
233 | gopt of group_item list option
|
adamc@227
|
234 | hopt of exp
|
adamc@207
|
235
|
adamc@204
|
236
|
adamc@1
|
237 %verbose (* print summary of errors *)
|
adamc@1
|
238 %pos int (* positions *)
|
adamc@1
|
239 %start file
|
adamc@1
|
240 %pure
|
adamc@1
|
241 %eop EOF
|
adamc@1
|
242 %noshift EOF
|
adamc@1
|
243
|
adamc@1
|
244 %name Lacweb
|
adamc@1
|
245
|
adamc@195
|
246 %nonassoc IF THEN ELSE
|
adamc@1
|
247 %nonassoc DARROW
|
adamc@1
|
248 %nonassoc COLON
|
adamc@6
|
249 %nonassoc DCOLON TCOLON
|
adamc@1
|
250 %right COMMA
|
adamc@220
|
251 %right OR
|
adamc@220
|
252 %right CAND
|
adamc@219
|
253 %nonassoc EQ NE LT LE GT GE
|
adamc@1
|
254 %right ARROW LARROW
|
adamc@149
|
255 %right PLUSPLUS MINUSMINUS
|
adamc@195
|
256 %right STAR
|
adamc@220
|
257 %left NOT
|
adamc@84
|
258 %nonassoc TWIDDLE
|
adamc@1
|
259 %nonassoc DOLLAR
|
adamc@1
|
260 %left DOT
|
adamc@221
|
261 %nonassoc LBRACE RBRACE
|
adamc@1
|
262
|
adamc@1
|
263 %%
|
adamc@1
|
264
|
adamc@1
|
265 file : decls (decls)
|
adamc@54
|
266 | SIG sgis ([(DSgn ("?", (SgnConst sgis, s (SIGleft, sgisright))),
|
adamc@54
|
267 s (SIGleft, sgisright))])
|
adamc@1
|
268
|
adamc@1
|
269 decls : ([])
|
adamc@1
|
270 | decl decls (decl :: decls)
|
adamc@1
|
271
|
adamc@1
|
272 decl : CON SYMBOL EQ cexp (DCon (SYMBOL, NONE, cexp), s (CONleft, cexpright))
|
adamc@1
|
273 | CON SYMBOL DCOLON kind EQ cexp (DCon (SYMBOL, SOME kind, cexp), s (CONleft, cexpright))
|
adamc@7
|
274 | LTYPE SYMBOL EQ cexp (DCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
|
adamc@7
|
275 s (LTYPEleft, cexpright))
|
adamc@191
|
276 | DATATYPE SYMBOL dargs EQ barOpt dcons(DDatatype (SYMBOL, dargs, dcons), s (DATATYPEleft, dconsright))
|
adamc@191
|
277 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
|
adamc@191
|
278 (case dargs of
|
adamc@191
|
279 [] => (DDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
|
adamc@191
|
280 | _ => raise Fail "Arguments specified for imported datatype")
|
adamc@123
|
281 | VAL vali (DVal vali, s (VALleft, valiright))
|
adamc@123
|
282 | VAL REC valis (DValRec valis, s (VALleft, valisright))
|
adamc@1
|
283
|
adamc@30
|
284 | SIGNATURE CSYMBOL EQ sgn (DSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))
|
adamc@30
|
285 | STRUCTURE CSYMBOL EQ str (DStr (CSYMBOL, NONE, str), s (STRUCTUREleft, strright))
|
adamc@30
|
286 | STRUCTURE CSYMBOL COLON sgn EQ str (DStr (CSYMBOL, SOME sgn, str), s (STRUCTUREleft, strright))
|
adamc@42
|
287 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN EQ str
|
adamc@42
|
288 (DStr (CSYMBOL1, NONE,
|
adamc@42
|
289 (StrFun (CSYMBOL2, sgn1, NONE, str), s (FUNCTORleft, strright))),
|
adamc@42
|
290 s (FUNCTORleft, strright))
|
adamc@42
|
291 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn EQ str
|
adamc@42
|
292 (DStr (CSYMBOL1, NONE,
|
adamc@42
|
293 (StrFun (CSYMBOL2, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))),
|
adamc@42
|
294 s (FUNCTORleft, strright))
|
adamc@48
|
295 | EXTERN STRUCTURE CSYMBOL COLON sgn (DFfiStr (CSYMBOL, sgn), s (EXTERNleft, sgnright))
|
adamc@61
|
296 | OPEN mpath (case mpath of
|
adamc@61
|
297 [] => raise Fail "Impossible mpath parse [1]"
|
adamc@61
|
298 | m :: ms => (DOpen (m, ms), s (OPENleft, mpathright)))
|
adamc@88
|
299 | OPEN CONSTRAINTS mpath (case mpath of
|
adamc@88
|
300 [] => raise Fail "Impossible mpath parse [3]"
|
adamc@88
|
301 | m :: ms => (DOpenConstraints (m, ms), s (OPENleft, mpathright)))
|
adamc@88
|
302 | CONSTRAINT cterm TWIDDLE cterm (DConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))
|
adamc@109
|
303 | EXPORT spath (DExport spath, s (EXPORTleft, spathright))
|
adamc@203
|
304 | TABLE SYMBOL COLON cexp (DTable (SYMBOL, entable cexp), s (TABLEleft, cexpright))
|
adamc@211
|
305 | CLASS SYMBOL EQ cexp (DClass (SYMBOL, cexp), s (CLASSleft, cexpright))
|
adamc@211
|
306 | CLASS SYMBOL SYMBOL EQ cexp (let
|
adamc@211
|
307 val loc = s (CLASSleft, cexpright)
|
adamc@211
|
308 val k = (KType, loc)
|
adamc@211
|
309 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
|
adamc@211
|
310 in
|
adamc@211
|
311 (DClass (SYMBOL1, c), s (CLASSleft, cexpright))
|
adamc@211
|
312 end)
|
adamc@30
|
313
|
adamc@191
|
314 dargs : ([])
|
adamc@191
|
315 | SYMBOL dargs (SYMBOL :: dargs)
|
adamc@191
|
316
|
adamc@156
|
317 barOpt : ()
|
adamc@156
|
318 | BAR ()
|
adamc@156
|
319
|
adamc@156
|
320 dcons : dcon ([dcon])
|
adamc@156
|
321 | dcon BAR dcons (dcon :: dcons)
|
adamc@156
|
322
|
adamc@156
|
323 dcon : CSYMBOL (CSYMBOL, NONE)
|
adamc@156
|
324 | CSYMBOL OF cexp (CSYMBOL, SOME cexp)
|
adamc@156
|
325
|
adamc@123
|
326 vali : SYMBOL EQ eexp (SYMBOL, NONE, eexp)
|
adamc@123
|
327 | SYMBOL COLON cexp EQ eexp (SYMBOL, SOME cexp, eexp)
|
adamc@123
|
328
|
adamc@123
|
329 valis : vali ([vali])
|
adamc@123
|
330 | vali AND valis (vali :: valis)
|
adamc@123
|
331
|
adamc@42
|
332 sgn : sgntm (sgntm)
|
adamc@40
|
333 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
|
adamc@40
|
334 (SgnFun (CSYMBOL, sgn1, sgn2), s (FUNCTORleft, sgn2right))
|
adamc@30
|
335
|
adamc@42
|
336 sgntm : SIG sgis END (SgnConst sgis, s (SIGleft, ENDright))
|
adamc@59
|
337 | mpath (case mpath of
|
adamc@61
|
338 [] => raise Fail "Impossible mpath parse [2]"
|
adamc@59
|
339 | [x] => SgnVar x
|
adamc@59
|
340 | m :: ms => SgnProj (m,
|
adamc@59
|
341 List.take (ms, length ms - 1),
|
adamc@59
|
342 List.nth (ms, length ms - 1)),
|
adamc@59
|
343 s (mpathleft, mpathright))
|
adamc@42
|
344 | sgntm WHERE CON SYMBOL EQ cexp (SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
|
adamc@42
|
345 | sgntm WHERE LTYPE SYMBOL EQ cexp(SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
|
adamc@42
|
346 | LPAREN sgn RPAREN (sgn)
|
adamc@42
|
347
|
adamc@30
|
348 sgi : CON SYMBOL DCOLON kind (SgiConAbs (SYMBOL, kind), s (CONleft, kindright))
|
adamc@30
|
349 | LTYPE SYMBOL (SgiConAbs (SYMBOL, (KType, s (LTYPEleft, SYMBOLright))),
|
adamc@30
|
350 s (LTYPEleft, SYMBOLright))
|
adamc@30
|
351 | CON SYMBOL EQ cexp (SgiCon (SYMBOL, NONE, cexp), s (CONleft, cexpright))
|
adamc@30
|
352 | CON SYMBOL DCOLON kind EQ cexp (SgiCon (SYMBOL, SOME kind, cexp), s (CONleft, cexpright))
|
adamc@30
|
353 | LTYPE SYMBOL EQ cexp (SgiCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
|
adamc@30
|
354 s (LTYPEleft, cexpright))
|
adamc@191
|
355 | DATATYPE SYMBOL dargs EQ barOpt dcons(SgiDatatype (SYMBOL, dargs, dcons), s (DATATYPEleft, dconsright))
|
adamc@191
|
356 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
|
adamc@191
|
357 (case dargs of
|
adamc@191
|
358 [] => (SgiDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
|
adamc@191
|
359 | _ => raise Fail "Arguments specified for imported datatype")
|
adamc@30
|
360 | VAL SYMBOL COLON cexp (SgiVal (SYMBOL, cexp), s (VALleft, cexpright))
|
adamc@30
|
361
|
adamc@30
|
362 | STRUCTURE CSYMBOL COLON sgn (SgiStr (CSYMBOL, sgn), s (STRUCTUREleft, sgnright))
|
adamc@59
|
363 | SIGNATURE CSYMBOL EQ sgn (SgiSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))
|
adamc@42
|
364 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
|
adamc@42
|
365 (SgiStr (CSYMBOL1,
|
adamc@42
|
366 (SgnFun (CSYMBOL2, sgn1, sgn2), s (FUNCTORleft, sgn2right))),
|
adamc@42
|
367 s (FUNCTORleft, sgn2right))
|
adamc@58
|
368 | INCLUDE sgn (SgiInclude sgn, s (INCLUDEleft, sgnright))
|
adamc@88
|
369 | CONSTRAINT cterm TWIDDLE cterm (SgiConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))
|
adamc@203
|
370 | TABLE SYMBOL COLON cexp (SgiTable (SYMBOL, entable cexp), s (TABLEleft, cexpright))
|
adamc@211
|
371 | CLASS SYMBOL (SgiClassAbs SYMBOL, s (CLASSleft, SYMBOLright))
|
adamc@211
|
372 | CLASS SYMBOL EQ cexp (SgiClass (SYMBOL, cexp), s (CLASSleft, cexpright))
|
adamc@211
|
373 | CLASS SYMBOL SYMBOL EQ cexp (let
|
adamc@211
|
374 val loc = s (CLASSleft, cexpright)
|
adamc@211
|
375 val k = (KType, loc)
|
adamc@211
|
376 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
|
adamc@211
|
377 in
|
adamc@211
|
378 (SgiClass (SYMBOL1, c), s (CLASSleft, cexpright))
|
adamc@211
|
379 end)
|
adamc@30
|
380
|
adamc@30
|
381 sgis : ([])
|
adamc@30
|
382 | sgi sgis (sgi :: sgis)
|
adamc@30
|
383
|
adamc@30
|
384 str : STRUCT decls END (StrConst decls, s (STRUCTleft, ENDright))
|
adamc@34
|
385 | spath (spath)
|
adamc@40
|
386 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN DARROW str
|
adamc@40
|
387 (StrFun (CSYMBOL, sgn, NONE, str), s (FUNCTORleft, strright))
|
adamc@40
|
388 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn DARROW str
|
adamc@40
|
389 (StrFun (CSYMBOL, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))
|
adamc@44
|
390 | spath LPAREN str RPAREN (StrApp (spath, str), s (spathleft, RPARENright))
|
adamc@34
|
391
|
adamc@34
|
392 spath : CSYMBOL (StrVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@34
|
393 | spath DOT CSYMBOL (StrProj (spath, CSYMBOL), s (spathleft, CSYMBOLright))
|
adamc@30
|
394
|
adamc@1
|
395 kind : TYPE (KType, s (TYPEleft, TYPEright))
|
adamc@1
|
396 | NAME (KName, s (NAMEleft, NAMEright))
|
adamc@1
|
397 | LBRACE kind RBRACE (KRecord kind, s (LBRACEleft, RBRACEright))
|
adamc@1
|
398 | kind ARROW kind (KArrow (kind1, kind2), s (kind1left, kind2right))
|
adamc@1
|
399 | LPAREN kind RPAREN (#1 kind, s (LPARENleft, RPARENright))
|
adamc@82
|
400 | KUNIT (KUnit, s (KUNITleft, KUNITright))
|
adamc@18
|
401 | UNDERUNDER (KWild, s (UNDERUNDERleft, UNDERUNDERright))
|
adamc@207
|
402 | LPAREN ktuple RPAREN (KTuple ktuple, s (LPARENleft, RPARENright))
|
adamc@207
|
403
|
adamc@207
|
404 ktuple : kind STAR kind ([kind1, kind2])
|
adamc@207
|
405 | kind STAR ktuple (kind :: ktuple)
|
adamc@1
|
406
|
adamc@1
|
407 capps : cterm (cterm)
|
adamc@1
|
408 | capps cterm (CApp (capps, cterm), s (cappsleft, ctermright))
|
adamc@1
|
409
|
adamc@1
|
410 cexp : capps (capps)
|
adamc@1
|
411 | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right))
|
adamc@15
|
412 | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright))
|
adamc@1
|
413
|
adamc@1
|
414 | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right))
|
adamc@1
|
415
|
adamc@67
|
416 | FN SYMBOL DARROW cexp (CAbs (SYMBOL, NONE, cexp), s (FNleft, cexpright))
|
adamc@67
|
417 | FN SYMBOL DCOLON kind DARROW cexp (CAbs (SYMBOL, SOME kind, cexp), s (FNleft, cexpright))
|
adamc@84
|
418 | cterm TWIDDLE cterm DARROW cexp(CDisjoint (cterm1, cterm2, cexp), s (cterm1left, cexpright))
|
adamc@85
|
419 | cterm TWIDDLE cterm ARROW cexp (TDisjoint (cterm1, cterm2, cexp), s (cterm1left, cexpright))
|
adamc@1
|
420
|
adamc@8
|
421 | LPAREN cexp RPAREN DCOLON kind (CAnnot (cexp, kind), s (LPARENleft, kindright))
|
adamc@6
|
422
|
adamc@18
|
423 | UNDER DCOLON kind (CWild kind, s (UNDERleft, UNDERright))
|
adamc@195
|
424 | ctuple (let
|
adamc@195
|
425 val loc = s (ctupleleft, ctupleright)
|
adamc@195
|
426 in
|
adamc@195
|
427 (TRecord (CRecord (ListUtil.mapi (fn (i, c) =>
|
adamc@195
|
428 ((CName (Int.toString (i + 1)), loc),
|
adamc@195
|
429 c)) ctuple),
|
adamc@195
|
430 loc), loc)
|
adamc@195
|
431 end)
|
adamc@18
|
432
|
adamc@1
|
433 kcolon : DCOLON (Explicit)
|
adamc@1
|
434 | TCOLON (Implicit)
|
adamc@1
|
435
|
adamc@34
|
436 path : SYMBOL ([], SYMBOL)
|
adamc@34
|
437 | CSYMBOL DOT path (let val (ms, x) = path in (CSYMBOL :: ms, x) end)
|
adamc@34
|
438
|
adamc@156
|
439 cpath : CSYMBOL ([], CSYMBOL)
|
adamc@156
|
440 | CSYMBOL DOT cpath (let val (ms, x) = cpath in (CSYMBOL :: ms, x) end)
|
adamc@156
|
441
|
adamc@59
|
442 mpath : CSYMBOL ([CSYMBOL])
|
adamc@59
|
443 | CSYMBOL DOT mpath (CSYMBOL :: mpath)
|
adamc@59
|
444
|
adamc@1
|
445 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright))
|
adamc@1
|
446 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright))
|
adamc@83
|
447 | LBRACK rconn RBRACK (CRecord rconn, s (LBRACKleft, RBRACKright))
|
adamc@1
|
448 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)),
|
adamc@1
|
449 s (LBRACEleft, RBRACEright))
|
adamc@1
|
450 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright))
|
adamc@1
|
451 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright))
|
adamc@195
|
452 | HASH INT (CName (Int64.toString INT), s (HASHleft, INTright))
|
adamc@1
|
453
|
adamc@34
|
454 | path (CVar path, s (pathleft, pathright))
|
adamc@207
|
455 | path DOT INT (CProj ((CVar path, s (pathleft, pathright)), Int64.toInt INT),
|
adamc@207
|
456 s (pathleft, INTright))
|
adamc@18
|
457 | UNDER (CWild (KWild, s (UNDERleft, UNDERright)), s (UNDERleft, UNDERright))
|
adamc@67
|
458 | FOLD (CFold, s (FOLDleft, FOLDright))
|
adamc@82
|
459 | UNIT (CUnit, s (UNITleft, UNITright))
|
adamc@207
|
460 | LPAREN ctuplev RPAREN (CTuple ctuplev, s (LPARENleft, RPARENright))
|
adamc@207
|
461
|
adamc@207
|
462 ctuplev: cexp COMMA cexp ([cexp1, cexp2])
|
adamc@207
|
463 | cexp COMMA ctuplev (cexp :: ctuplev)
|
adamc@1
|
464
|
adamc@196
|
465 ctuple : capps STAR capps ([capps1, capps2])
|
adamc@196
|
466 | capps STAR ctuple (capps :: ctuple)
|
adamc@195
|
467
|
adamc@1
|
468 rcon : ([])
|
adamc@1
|
469 | ident EQ cexp ([(ident, cexp)])
|
adamc@1
|
470 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon)
|
adamc@1
|
471
|
adamc@83
|
472 rconn : ident ([(ident, (CUnit, s (identleft, identright)))])
|
adamc@83
|
473 | ident COMMA rconn ((ident, (CUnit, s (identleft, identright))) :: rconn)
|
adamc@83
|
474
|
adamc@1
|
475 rcone : ([])
|
adamc@1
|
476 | ident COLON cexp ([(ident, cexp)])
|
adamc@1
|
477 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone)
|
adamc@1
|
478
|
adamc@1
|
479 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@195
|
480 | INT (CName (Int64.toString INT), s (INTleft, INTright))
|
adamc@200
|
481 | SYMBOL (CVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
|
adamc@8
|
482
|
adamc@8
|
483 eapps : eterm (eterm)
|
adamc@8
|
484 | eapps eterm (EApp (eapps, eterm), s (eappsleft, etermright))
|
adamc@8
|
485 | eapps LBRACK cexp RBRACK (ECApp (eapps, cexp), s (eappsleft, RBRACKright))
|
adamc@8
|
486
|
adamc@8
|
487 eexp : eapps (eapps)
|
adamc@8
|
488 | FN SYMBOL kcolon kind DARROW eexp (ECAbs (kcolon, SYMBOL, kind, eexp), s (FNleft, eexpright))
|
adamc@8
|
489 | FN SYMBOL COLON cexp DARROW eexp (EAbs (SYMBOL, SOME cexp, eexp), s (FNleft, eexpright))
|
adamc@8
|
490 | FN SYMBOL DARROW eexp (EAbs (SYMBOL, NONE, eexp), s (FNleft, eexpright))
|
adamc@212
|
491 | FN UNDER COLON cexp DARROW eexp (EAbs ("_", SOME cexp, eexp), s (FNleft, eexpright))
|
adamc@93
|
492 | LBRACK cterm TWIDDLE cterm RBRACK DARROW eexp(EDisjoint (cterm1, cterm2, eexp), s (LBRACKleft, RBRACKright))
|
adamc@93
|
493 | FN UNIT DARROW eexp (let
|
adamc@93
|
494 val loc = s (FNleft, eexpright)
|
adamc@93
|
495 in
|
adamc@93
|
496 (EAbs ("_", SOME (TRecord (CRecord [], loc), loc), eexp), loc)
|
adamc@93
|
497 end)
|
adamc@8
|
498
|
adamc@196
|
499 | eexp COLON cexp (EAnnot (eexp, cexp), s (eexpleft, cexpright))
|
adamc@149
|
500 | eexp MINUSMINUS cexp (ECut (eexp, cexp), s (eexpleft, cexpright))
|
adamc@170
|
501 | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
|
adamc@190
|
502 | IF eexp THEN eexp ELSE eexp (let
|
adamc@190
|
503 val loc = s (IFleft, eexp3right)
|
adamc@190
|
504 in
|
adamc@190
|
505 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc), eexp2),
|
adamc@190
|
506 ((PCon (["Basis"], "False", NONE), loc), eexp3)]), loc)
|
adamc@190
|
507 end)
|
adamc@8
|
508
|
adamc@8
|
509 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
|
adamc@195
|
510 | LPAREN etuple RPAREN (let
|
adamc@195
|
511 val loc = s (LPARENleft, RPARENright)
|
adamc@195
|
512 in
|
adamc@195
|
513 (ERecord (ListUtil.mapi (fn (i, e) =>
|
adamc@195
|
514 ((CName (Int.toString (i + 1)), loc),
|
adamc@195
|
515 e)) etuple), loc)
|
adamc@195
|
516 end)
|
adamc@8
|
517
|
adamc@34
|
518 | path (EVar path, s (pathleft, pathright))
|
adamc@156
|
519 | cpath (EVar cpath, s (cpathleft, cpathright))
|
adamc@12
|
520 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
|
adamc@110
|
521 | UNIT (ERecord [], s (UNITleft, UNITright))
|
adamc@12
|
522
|
adamc@14
|
523 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@14
|
524 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
|
adamc@14
|
525 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@14
|
526
|
adamc@200
|
527 | path DOT idents (let
|
adamc@200
|
528 val loc = s (pathleft, identsright)
|
adamc@200
|
529 in
|
adamc@200
|
530 foldl (fn (ident, e) =>
|
adamc@200
|
531 (EField (e, ident), loc))
|
adamc@200
|
532 (EVar path, s (pathleft, pathright)) idents
|
adamc@200
|
533 end)
|
adamc@71
|
534 | FOLD (EFold, s (FOLDleft, FOLDright))
|
adamc@71
|
535
|
adamc@91
|
536 | XML_BEGIN xml XML_END (xml)
|
adamc@91
|
537 | XML_BEGIN XML_END (EApp ((EVar (["Basis"], "cdata"), s (XML_BEGINleft, XML_ENDright)),
|
adamc@91
|
538 (EPrim (Prim.String ""), s (XML_BEGINleft, XML_ENDright))),
|
adamc@91
|
539 s (XML_BEGINleft, XML_ENDright))
|
adamc@204
|
540 | LPAREN query RPAREN (query)
|
adamc@211
|
541 | UNDER (EWild, s (UNDERleft, UNDERright))
|
adamc@91
|
542
|
adamc@200
|
543 idents : ident ([ident])
|
adamc@200
|
544 | ident DOT idents (ident :: idents)
|
adamc@200
|
545
|
adamc@195
|
546 etuple : eexp COMMA eexp ([eexp1, eexp2])
|
adamc@195
|
547 | eexp COMMA etuple (eexp :: etuple)
|
adamc@195
|
548
|
adamc@170
|
549 branch : pat DARROW eexp (pat, eexp)
|
adamc@170
|
550
|
adamc@170
|
551 branchs: ([])
|
adamc@170
|
552 | BAR branch branchs (branch :: branchs)
|
adamc@170
|
553
|
adamc@170
|
554 pat : pterm (pterm)
|
adamc@170
|
555 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
|
adamc@170
|
556
|
adamc@170
|
557 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
|
adamc@170
|
558 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
|
adamc@170
|
559 | UNDER (PWild, s (UNDERleft, UNDERright))
|
adamc@173
|
560 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@173
|
561 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@170
|
562 | LPAREN pat RPAREN (pat)
|
adamc@174
|
563 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
|
adamc@174
|
564 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
|
adamc@174
|
565 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
|
adamc@195
|
566 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
|
adamc@195
|
567 false),
|
adamc@195
|
568 s (LPARENleft, RPARENright))
|
adamc@174
|
569
|
adamc@175
|
570 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
|
adamc@174
|
571 | DOTDOTDOT ([], true)
|
adamc@175
|
572 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
|
adamc@170
|
573
|
adamc@195
|
574 ptuple : pat COMMA pat ([pat1, pat2])
|
adamc@195
|
575 | pat COMMA ptuple (pat :: ptuple)
|
adamc@195
|
576
|
adamc@12
|
577 rexp : ([])
|
adamc@12
|
578 | ident EQ eexp ([(ident, eexp)])
|
adamc@12
|
579 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
|
adamc@91
|
580
|
adamc@141
|
581 xml : xmlOne xml (let
|
adamc@141
|
582 val pos = s (xmlOneleft, xmlright)
|
adamc@141
|
583 in
|
adamc@141
|
584 (EApp ((EApp (
|
adamc@141
|
585 (EVar (["Basis"], "join"), pos),
|
adamc@91
|
586 xmlOne), pos),
|
adamc@141
|
587 xml), pos)
|
adamc@141
|
588 end)
|
adamc@141
|
589 | xmlOne (xmlOne)
|
adamc@91
|
590
|
adamc@141
|
591 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata"), s (NOTAGSleft, NOTAGSright)),
|
adamc@141
|
592 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
|
adamc@141
|
593 s (NOTAGSleft, NOTAGSright))
|
adamc@141
|
594 | tag DIVIDE GT (let
|
adamc@141
|
595 val pos = s (tagleft, GTright)
|
adamc@141
|
596 in
|
adamc@141
|
597 (EApp (#2 tag,
|
adamc@141
|
598 (EApp ((EVar (["Basis"], "cdata"), pos),
|
adamc@141
|
599 (EPrim (Prim.String ""), pos)),
|
adamc@141
|
600 pos)), pos)
|
adamc@141
|
601 end)
|
adamc@141
|
602
|
adamc@141
|
603 | tag GT xml END_TAG (let
|
adamc@141
|
604 val pos = s (tagleft, GTright)
|
adamc@141
|
605 in
|
adamc@141
|
606 if #1 tag = END_TAG then
|
adamc@141
|
607 if END_TAG = "lform" then
|
adamc@141
|
608 (EApp ((EVar (["Basis"], "lform"), pos),
|
adamc@141
|
609 xml), pos)
|
adamc@141
|
610 else
|
adamc@141
|
611 (EApp (#2 tag, xml), pos)
|
adamc@141
|
612 else
|
adamc@141
|
613 (ErrorMsg.errorAt pos "Begin and end tags don't match.";
|
adamc@141
|
614 (EFold, pos))
|
adamc@141
|
615 end)
|
adamc@141
|
616 | LBRACE eexp RBRACE (eexp)
|
adamc@92
|
617
|
adamc@141
|
618 tag : tagHead attrs (let
|
adamc@141
|
619 val pos = s (tagHeadleft, attrsright)
|
adamc@141
|
620 in
|
adamc@141
|
621 (#1 tagHead,
|
adamc@141
|
622 (EApp ((EApp ((EVar (["Basis"], "tag"), pos),
|
adamc@141
|
623 (ERecord attrs, pos)), pos),
|
adamc@141
|
624 (EApp (#2 tagHead,
|
adamc@141
|
625 (ERecord [], pos)), pos)),
|
adamc@141
|
626 pos))
|
adamc@141
|
627 end)
|
adamc@141
|
628
|
adamc@141
|
629 tagHead: BEGIN_TAG (let
|
adamc@141
|
630 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
|
adamc@141
|
631 in
|
adamc@141
|
632 (BEGIN_TAG,
|
adamc@141
|
633 (EVar ([], BEGIN_TAG), pos))
|
adamc@141
|
634 end)
|
adamc@141
|
635 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
|
adamc@92
|
636
|
adamc@104
|
637 attrs : ([])
|
adamc@104
|
638 | attr attrs (attr :: attrs)
|
adamc@104
|
639
|
adamc@204
|
640 attr : SYMBOL EQ attrv ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)), attrv)
|
adamc@204
|
641
|
adamc@104
|
642 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
|
adamc@104
|
643 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
|
adamc@104
|
644 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
|
adamc@110
|
645 | LBRACE eexp RBRACE (eexp)
|
adamc@226
|
646
|
adamc@226
|
647 query : query1 (query1)
|
adamc@204
|
648
|
adamc@227
|
649 query1 : SELECT select FROM tables wopt gopt hopt
|
adamc@209
|
650 (let
|
adamc@204
|
651 val loc = s (SELECTleft, tablesright)
|
adamc@207
|
652
|
adamc@207
|
653 val sel =
|
adamc@207
|
654 case select of
|
adamc@207
|
655 Star => map (fn (nm, _) =>
|
adamc@207
|
656 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
|
adamc@207
|
657 loc),
|
adamc@207
|
658 (CRecord [], loc)],
|
adamc@207
|
659 loc))) tables
|
adamc@207
|
660 | Items sis =>
|
adamc@207
|
661 let
|
adamc@207
|
662 val tabs = map (fn (nm, _) => (nm, (CRecord [], loc))) tables
|
adamc@207
|
663 val tabs = foldl (amend_select loc) tabs sis
|
adamc@207
|
664 in
|
adamc@207
|
665 map (fn (nm, c) => (nm,
|
adamc@207
|
666 (CTuple [c,
|
adamc@207
|
667 (CWild (KRecord (KType, loc), loc),
|
adamc@207
|
668 loc)], loc))) tabs
|
adamc@207
|
669 end
|
adamc@207
|
670
|
adamc@207
|
671 val sel = (CRecord sel, loc)
|
adamc@207
|
672
|
adamc@226
|
673 val grp = case gopt of
|
adamc@226
|
674 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all"), loc),
|
adamc@226
|
675 (CWild (KRecord (KRecord (KType, loc), loc),
|
adamc@226
|
676 loc), loc)), loc)
|
adamc@226
|
677 | SOME gis =>
|
adamc@226
|
678 let
|
adamc@226
|
679 val tabs = map (fn (nm, _) =>
|
adamc@226
|
680 (nm, (CRecord [], loc))) tables
|
adamc@226
|
681 val tabs = foldl (amend_group loc) tabs gis
|
adamc@226
|
682
|
adamc@226
|
683 val tabs = map (fn (nm, c) =>
|
adamc@226
|
684 (nm,
|
adamc@226
|
685 (CTuple [c,
|
adamc@226
|
686 (CWild (KRecord (KType, loc),
|
adamc@226
|
687 loc),
|
adamc@226
|
688 loc)], loc))) tabs
|
adamc@226
|
689 in
|
adamc@226
|
690 (ECApp ((EVar (["Basis"], "sql_subset"), loc),
|
adamc@226
|
691 (CRecord tabs, loc)), loc)
|
adamc@226
|
692 end
|
adamc@226
|
693
|
adamc@207
|
694 val e = (EVar (["Basis"], "sql_query"), loc)
|
adamc@209
|
695 val re = (ERecord [((CName "From", loc),
|
adamc@209
|
696 (ERecord tables, loc)),
|
adamc@209
|
697 ((CName "Where", loc),
|
adamc@223
|
698 wopt),
|
adamc@224
|
699 ((CName "GroupBy", loc),
|
adamc@226
|
700 grp),
|
adamc@224
|
701 ((CName "Having", loc),
|
adamc@224
|
702 hopt),
|
adamc@223
|
703 ((CName "SelectFields", loc),
|
adamc@223
|
704 (ECApp ((EVar (["Basis"], "sql_subset"), loc),
|
adamc@223
|
705 sel), loc))], loc)
|
adamc@223
|
706
|
adamc@209
|
707 val e = (EApp (e, re), loc)
|
adamc@204
|
708 in
|
adamc@207
|
709 e
|
adamc@204
|
710 end)
|
adamc@204
|
711
|
adamc@204
|
712 tables : table ([table])
|
adamc@204
|
713 | table COMMA tables (table :: tables)
|
adamc@204
|
714
|
adamc@204
|
715 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@204
|
716 | LBRACE cexp RBRACE (cexp)
|
adamc@204
|
717
|
adamc@207
|
718 table : SYMBOL ((CName SYMBOL, s (SYMBOLleft, SYMBOLright)),
|
adamc@204
|
719 (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright)))
|
adamc@204
|
720 | SYMBOL AS tname (tname, (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright)))
|
adamc@221
|
721 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
|
adamc@207
|
722
|
adamc@207
|
723 tident : SYMBOL (CName SYMBOL, s (SYMBOLleft, SYMBOLright))
|
adamc@207
|
724 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@221
|
725 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
|
adamc@207
|
726
|
adamc@207
|
727 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
|
adamc@207
|
728 | LBRACE cexp RBRACE (cexp)
|
adamc@207
|
729
|
adamc@207
|
730 seli : tident DOT fident (Field (tident, fident))
|
adamc@207
|
731
|
adamc@207
|
732 selis : seli ([seli])
|
adamc@207
|
733 | seli COMMA selis (seli :: selis)
|
adamc@207
|
734
|
adamc@207
|
735 select : STAR (Star)
|
adamc@207
|
736 | selis (Items selis)
|
adamc@209
|
737
|
adamc@209
|
738 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True"),
|
adamc@209
|
739 EVar (["Basis"], "sql_bool"),
|
adamc@209
|
740 s (TRUEleft, TRUEright)))
|
adamc@209
|
741 | FALSE (sql_inject (EVar (["Basis"], "False"),
|
adamc@209
|
742 EVar (["Basis"], "sql_bool"),
|
adamc@209
|
743 s (FALSEleft, FALSEright)))
|
adamc@209
|
744
|
adamc@222
|
745 | INT (sql_inject (EPrim (Prim.Int INT),
|
adamc@222
|
746 EVar (["Basis"], "sql_int"),
|
adamc@222
|
747 s (INTleft, INTright)))
|
adamc@222
|
748 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
|
adamc@222
|
749 EVar (["Basis"], "sql_float"),
|
adamc@222
|
750 s (FLOATleft, FLOATright)))
|
adamc@222
|
751
|
adamc@221
|
752 | tident DOT fident (let
|
adamc@221
|
753 val loc = s (tidentleft, fidentright)
|
adamc@221
|
754 val e = (EVar (["Basis"], "sql_field"), loc)
|
adamc@221
|
755 val e = (ECApp (e, tident), loc)
|
adamc@221
|
756 in
|
adamc@221
|
757 (ECApp (e, fident), loc)
|
adamc@221
|
758 end)
|
adamc@221
|
759
|
adamc@219
|
760 | sqlexp EQ sqlexp (sql_compare ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
761 | sqlexp NE sqlexp (sql_compare ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
762 | sqlexp LT sqlexp (sql_compare ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
763 | sqlexp LE sqlexp (sql_compare ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
764 | sqlexp GT sqlexp (sql_compare ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
765 | sqlexp GE sqlexp (sql_compare ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@219
|
766
|
adamc@220
|
767 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@220
|
768 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
|
adamc@220
|
769 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
|
adamc@220
|
770
|
adamc@210
|
771 | LBRACE eexp RBRACE (sql_inject (#1 eexp,
|
adamc@211
|
772 EWild,
|
adamc@210
|
773 s (LBRACEleft, RBRACEright)))
|
adamc@220
|
774 | LPAREN sqlexp RPAREN (sqlexp)
|
adamc@210
|
775
|
adamc@209
|
776 wopt : (sql_inject (EVar (["Basis"], "True"),
|
adamc@209
|
777 EVar (["Basis"], "sql_bool"),
|
adamc@209
|
778 ErrorMsg.dummySpan))
|
adamc@209
|
779 | CWHERE sqlexp (sqlexp)
|
adamc@226
|
780
|
adamc@226
|
781 groupi : tident DOT fident (GField (tident, fident))
|
adamc@226
|
782
|
adamc@226
|
783 groupis: groupi ([groupi])
|
adamc@226
|
784 | groupi COMMA groupis (groupi :: groupis)
|
adamc@226
|
785
|
adamc@226
|
786 gopt : (NONE)
|
adamc@226
|
787 | GROUP BY groupis (SOME groupis)
|
adamc@227
|
788
|
adamc@227
|
789 hopt : (sql_inject (EVar (["Basis"], "True"),
|
adamc@227
|
790 EVar (["Basis"], "sql_bool"),
|
adamc@227
|
791 ErrorMsg.dummySpan))
|
adamc@227
|
792 | HAVING sqlexp (sqlexp)
|