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