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