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