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