annotate src/urweb.grm @ 1732:4a03aa3251cb

Initial support for reusing elaboration results
author Adam Chlipala <adam@chlipala.net>
date Sun, 29 Apr 2012 13:17:31 -0400
parents f7d9dc5d57eb
children f9e5a8e09cdf
rev   line source
adam@1643 1 (* Copyright (c) 2008-2011, 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@339 15 * THIS SOFTARE 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@244 28 (* Grammar for Ur/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@1194 45 | Exp of con option * exp
adamc@341 46 | Fields of con * con
adam@1627 47 | StarFields of con
adamc@207 48
adamc@207 49 datatype select =
adamc@207 50 Star
adamc@207 51 | Items of select_item list
adamc@207 52
adamc@226 53 datatype group_item =
adamc@226 54 GField of con * con
adam@1425 55 | GFields of con * con
adamc@226 56
adamc@207 57 fun eqTnames ((c1, _), (c2, _)) =
adamc@207 58 case (c1, c2) of
adamc@207 59 (CVar (ms1, x1), CVar (ms2, x2)) => ms1 = ms2 andalso x1 = x2
adamc@207 60 | (CName x1, CName x2) => x1 = x2
adamc@207 61 | _ => false
adamc@207 62
adam@1424 63 fun nameString (c, _) =
adam@1424 64 case c of
adam@1424 65 CName s => s
adam@1424 66 | CVar (_, x) => x
adam@1424 67 | _ => "?"
adam@1424 68
adam@1627 69 datatype tableMode =
adam@1627 70 Unknown
adam@1627 71 | Everything
adam@1627 72 | Selective of con
adam@1627 73
adamc@1194 74 fun amend_select loc (si, (count, tabs, exps)) =
adamc@233 75 case si of
adamc@233 76 Field (tx, fx) =>
adamc@233 77 let
adamc@233 78 val c = (CRecord ([(fx, (CWild (KType, loc), loc))]), loc)
adamc@207 79
adamc@233 80 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
adamc@233 81 if eqTnames (tx, tx') then
adam@1627 82 case c' of
adam@1627 83 Everything =>
adam@1627 84 (ErrorMsg.errorAt loc
adam@1627 85 "Mixing specific-field and '*' selection of fields from same table";
adam@1627 86 ((tx', c'), found))
adam@1627 87 | Unknown =>
adam@1627 88 ((tx', Selective c), true)
adam@1627 89 | Selective c' =>
adam@1627 90 ((tx', Selective (CConcat (c, c'), loc)), true)
adamc@233 91 else
adamc@233 92 ((tx', c'), found))
adamc@233 93 false tabs
adamc@233 94 in
adamc@233 95 if found then
adamc@233 96 ()
adamc@233 97 else
adam@1424 98 ErrorMsg.errorAt loc ("Select of field " ^ nameString fx ^ " from unbound table " ^ nameString tx);
adamc@233 99
adamc@1194 100 (count, tabs, exps)
adamc@233 101 end
adamc@341 102 | Fields (tx, fs) =>
adamc@341 103 let
adamc@341 104 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
adamc@341 105 if eqTnames (tx, tx') then
adam@1627 106 case c' of
adam@1627 107 Everything =>
adam@1627 108 (ErrorMsg.errorAt loc
adam@1627 109 "Mixing specific-field and '*' selection of fields from same table";
adam@1627 110 ((tx', c'), found))
adam@1627 111 | Selective c' =>
adam@1627 112 ((tx', Selective (CConcat (fs, c'), loc)), true)
adam@1627 113 | Unknown =>
adam@1627 114 ((tx', Selective fs), true)
adamc@341 115 else
adamc@341 116 ((tx', c'), found))
adamc@341 117 false tabs
adamc@341 118 in
adamc@341 119 if found then
adamc@341 120 ()
adamc@341 121 else
adamc@341 122 ErrorMsg.errorAt loc "Select of field from unbound table";
adamc@341 123
adamc@1194 124 (count, tabs, exps)
adamc@341 125 end
adam@1627 126 | StarFields tx =>
adam@1627 127 if List.exists (fn (tx', c') => eqTnames (tx, tx') andalso case c' of
adam@1627 128 Unknown => false
adam@1627 129 | _ => true) tabs then
adam@1627 130 (ErrorMsg.errorAt loc "Selection with '*' from table already mentioned in same SELECT clause";
adam@1627 131 (count, tabs, exps))
adam@1627 132 else if List.all (fn (tx', c') => not (eqTnames (tx, tx'))) tabs then
adam@1627 133 (ErrorMsg.errorAt loc "Select of all fields from unbound table";
adam@1627 134 (count, tabs, exps))
adam@1627 135 else
adam@1627 136 (count, map (fn (tx', c') => (tx', if eqTnames (tx, tx') then Everything else c')) tabs, exps)
adamc@1194 137 | Exp (SOME c, e) => (count, tabs, (c, e) :: exps)
adamc@1194 138 | Exp (NONE, e) => (count+1, tabs, ((CName (Int.toString count), loc), e) :: exps)
adamc@207 139
adamc@226 140 fun amend_group loc (gi, tabs) =
adamc@226 141 let
adamc@226 142 val (tx, c) = case gi of
adamc@226 143 GField (tx, fx) => (tx, (CRecord ([(fx, (CWild (KType, loc), loc))]), loc))
adam@1425 144 | GFields (tx, fxs) => (tx, fxs)
adamc@226 145
adamc@226 146 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
adamc@226 147 if eqTnames (tx, tx') then
adamc@226 148 ((tx', (CConcat (c, c'), loc)), true)
adamc@226 149 else
adamc@226 150 ((tx', c'), found))
adam@1425 151 false tabs
adamc@226 152 in
adamc@226 153 if found then
adamc@226 154 ()
adamc@226 155 else
adamc@226 156 ErrorMsg.errorAt loc "Select of field from unbound table";
adamc@226 157
adamc@226 158 tabs
adamc@226 159 end
adamc@226 160
adamc@403 161 fun sql_inject (v, loc) =
adamc@403 162 (EApp ((EVar (["Basis"], "sql_inject", Infer), loc), (v, loc)), loc)
adamc@209 163
adamc@220 164 fun sql_binary (oper, sqlexp1, sqlexp2, loc) =
adamc@220 165 let
adamc@403 166 val e = (EVar (["Basis"], "sql_binary", Infer), loc)
adamc@403 167 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adamc@220 168 val e = (EApp (e, sqlexp1), loc)
adamc@220 169 in
adamc@220 170 (EApp (e, sqlexp2), loc)
adamc@220 171 end
adamc@220 172
adamc@220 173 fun sql_unary (oper, sqlexp, loc) =
adamc@220 174 let
adamc@403 175 val e = (EVar (["Basis"], "sql_unary", Infer), loc)
adamc@403 176 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adamc@220 177 in
adamc@220 178 (EApp (e, sqlexp), loc)
adamc@219 179 end
adamc@219 180
adam@1427 181 fun sql_relop (oper, all, sqlexp1, sqlexp2, loc) =
adamc@229 182 let
adamc@403 183 val e = (EVar (["Basis"], "sql_relop", Infer), loc)
adamc@403 184 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adam@1427 185 val e = (EApp (e, (EVar (["Basis"], if all then "True" else "False", Infer), loc)), loc)
adamc@229 186 val e = (EApp (e, sqlexp1), loc)
adamc@229 187 in
adamc@229 188 (EApp (e, sqlexp2), loc)
adamc@229 189 end
adamc@229 190
adamc@441 191 fun sql_nfunc (oper, loc) =
adamc@441 192 let
adamc@441 193 val e = (EVar (["Basis"], "sql_nfunc", Infer), loc)
adamc@441 194 in
adamc@441 195 (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adamc@441 196 end
adamc@441 197
adamc@389 198 fun native_unop (oper, e1, loc) =
adamc@389 199 let
adamc@403 200 val e = (EVar (["Basis"], oper, Infer), loc)
adamc@389 201 in
adamc@389 202 (EApp (e, e1), loc)
adamc@389 203 end
adamc@389 204
adamc@256 205 fun native_op (oper, e1, e2, loc) =
adamc@256 206 let
adamc@403 207 val e = (EVar (["Basis"], oper, Infer), loc)
adamc@256 208 val e = (EApp (e, e1), loc)
adamc@256 209 in
adamc@256 210 (EApp (e, e2), loc)
adamc@256 211 end
adamc@256 212
adamc@310 213 val inDml = ref false
adamc@310 214
adamc@325 215 fun tagIn bt =
adamc@325 216 case bt of
adamc@325 217 "table" => "tabl"
adamc@325 218 | _ => bt
adamc@325 219
adamc@709 220 datatype prop_kind = Delete | Update
adamc@709 221
adam@1643 222 datatype attr = Class of exp | DynClass of exp | Normal of con * exp
adamc@721 223
adamc@822 224 fun patType loc (p : pat) =
adamc@822 225 case #1 p of
adamc@822 226 PAnnot (_, t) => t
adamc@822 227 | _ => (CWild (KType, loc), loc)
adamc@822 228
adamc@1265 229 fun tnamesOf (e, _) =
adamc@1265 230 case e of
adamc@1265 231 EApp (e1, e2) => tnamesOf e1 @ tnamesOf e2
adamc@1265 232 | ECApp (e, c as (CName _, _)) =>
adamc@1265 233 let
adamc@1265 234 fun isFt (e, _) =
adamc@1265 235 case e of
adamc@1265 236 EVar (["Basis"], "sql_from_table", _) => true
adamc@1265 237 | EVar ([], "sql_from_table", _) => true
adamc@1265 238 | ECApp (e, _) => isFt e
adamc@1265 239 | EApp (e, _) => isFt e
adamc@1265 240 | EDisjointApp e => isFt e
adamc@1265 241 | _ => false
adamc@1265 242 in
adamc@1265 243 (if isFt e then [c] else []) @ tnamesOf e
adamc@1265 244 end
adamc@1265 245 | ECApp (e, _) => tnamesOf e
adamc@1265 246 | EDisjointApp e => tnamesOf e
adamc@1265 247 | _ => []
adamc@1265 248
adamc@1 249 %%
adamc@244 250 %header (functor UrwebLrValsFn(structure Token : TOKEN))
adamc@1 251
adamc@1 252 %term
adamc@1 253 EOF
adamc@821 254 | STRING of string | INT of Int64.int | FLOAT of Real64.real | CHAR of char
adamc@1 255 | SYMBOL of string | CSYMBOL of string
adamc@1 256 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
adam@1306 257 | EQ | COMMA | COLON | DCOLON | DCOLONWILD | TCOLON | TCOLONWILD | DOT | HASH | UNDER | UNDERUNDER | BAR
adamc@403 258 | PLUS | MINUS | DIVIDE | DOTDOTDOT | MOD | AT
adamc@623 259 | CON | LTYPE | VAL | REC | AND | FUN | MAP | UNIT | KUNIT | CLASS
adamc@156 260 | DATATYPE | OF
adamc@7 261 | TYPE | NAME
adamc@629 262 | ARROW | LARROW | DARROW | STAR | SEMI | KARROW | DKARROW | BANG
adamc@674 263 | FN | PLUSPLUS | MINUSMINUS | MINUSMINUSMINUS | DOLLAR | TWIDDLE | CARET
adamc@446 264 | LET | IN
adam@1732 265 | STRUCTURE | SIGNATURE | STRUCT | SIG | END | FUNCTOR | WHERE | SQL | SELECT1
adamc@754 266 | INCLUDE | OPEN | CONSTRAINT | CONSTRAINTS | EXPORT | TABLE | SEQUENCE | VIEW
adamc@1199 267 | COOKIE | STYLE | TASK | POLICY
adamc@842 268 | CASE | IF | THEN | ELSE | ANDALSO | ORELSE
adamc@1 269
adamc@360 270 | XML_BEGIN of string | XML_END | XML_BEGIN_END of string
adamc@91 271 | NOTAGS of string
adamc@91 272 | BEGIN_TAG of string | END_TAG of string
adamc@91 273
adamc@993 274 | SELECT | DISTINCT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING
adamc@229 275 | UNION | INTERSECT | EXCEPT
adamc@232 276 | LIMIT | OFFSET | ALL
adamc@220 277 | TRUE | FALSE | CAND | OR | NOT
adamc@236 278 | COUNT | AVG | SUM | MIN | MAX
adam@1682 279 | ASC | DESC | RANDOM
kkallio@1607 280 | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS | COALESCE | LIKE
adamc@441 281 | CURRENT_TIMESTAMP
adamc@219 282 | NE | LT | LE | GT | GE
adamc@714 283 | CCONSTRAINT | UNIQUE | CHECK | PRIMARY | FOREIGN | KEY | ON | NO | ACTION | RESTRICT | CASCADE | REFERENCES
adamc@751 284 | JOIN | INNER | CROSS | OUTER | LEFT | RIGHT | FULL
kkallio@1572 285 | CIF | CTHEN | CELSE
adamc@204 286
adamc@30 287 %nonterm
adamc@1 288 file of decl list
adamc@1 289 | decls of decl list
adamc@325 290 | decl of decl list
adamc@123 291 | vali of string * con option * exp
adamc@123 292 | valis of (string * con option * exp) list
adamc@242 293 | copt of con option
adamc@1 294
adamc@191 295 | dargs of string list
adamc@156 296 | barOpt of unit
adamc@156 297 | dcons of (string * con option) list
adamc@805 298 | dtype of string * string list * (string * con option) list
adamc@805 299 | dtypes of (string * string list * (string * con option) list) list
adamc@156 300 | dcon of string * con option
adamc@156 301
adamc@707 302 | pkopt of exp
adam@1722 303 | pk of exp
adamc@707 304 | commaOpt of unit
adamc@707 305
adamc@704 306 | cst of exp
adamc@704 307 | csts of exp
adamc@704 308 | cstopt of exp
adamc@704 309
adamc@1001 310 | ckl of (string * kind option) list
adamc@1001 311
adamc@709 312 | pmode of prop_kind * exp
adamc@709 313 | pkind of prop_kind
adamc@709 314 | prule of exp
adamc@709 315 | pmodes of (prop_kind * exp) list
adamc@709 316
adamc@30 317 | sgn of sgn
adamc@42 318 | sgntm of sgn
adamc@30 319 | sgi of sgn_item
adamc@30 320 | sgis of sgn_item list
adamc@30 321
adamc@30 322 | str of str
adamc@30 323
adamc@1 324 | kind of kind
adamc@207 325 | ktuple of kind list
adamc@1 326 | kcolon of explicitness
adamc@240 327 | kopt of kind option
adamc@1 328
adamc@34 329 | path of string list * string
adamc@156 330 | cpath of string list * string
adamc@34 331 | spath of str
adamc@59 332 | mpath of string list
adamc@34 333
adamc@1 334 | cexp of con
adam@1577 335 | cexpO of con option
adamc@1 336 | capps of con
adamc@1 337 | cterm of con
adamc@195 338 | ctuple of con list
adamc@207 339 | ctuplev of con list
adamc@1 340 | ident of con
adamc@200 341 | idents of con list
adamc@1 342 | rcon of (con * con) list
adamc@83 343 | rconn of (con * con) list
adamc@1 344 | rcone of (con * con) list
adamc@239 345 | cargs of con * kind -> con * kind
adamc@239 346 | cargl of con * kind -> con * kind
adamc@240 347 | cargl2 of con * kind -> con * kind
adamc@239 348 | carg of con * kind -> con * kind
adamc@239 349 | cargp of con * kind -> con * kind
adamc@1 350
adamc@8 351 | eexp of exp
adamc@8 352 | eapps of exp
adamc@8 353 | eterm of exp
adamc@195 354 | etuple of exp list
adamc@12 355 | rexp of (con * exp) list
adamc@91 356 | xml of exp
adamc@91 357 | xmlOne of exp
adamc@1045 358 | xmlOpt of exp
adam@1643 359 | tag of (string * exp) * exp option * exp option * exp
adamc@141 360 | tagHead of string * exp
adamc@434 361 | bind of string * con option * exp
adamc@446 362 | edecl of edecl
adamc@446 363 | edecls of edecl list
adamc@8 364
adamc@241 365 | earg of exp * con -> exp * con
adamc@241 366 | eargp of exp * con -> exp * con
adamc@822 367 | earga of exp * con -> exp * con
adamc@241 368 | eargs of exp * con -> exp * con
adamc@241 369 | eargl of exp * con -> exp * con
adamc@242 370 | eargl2 of exp * con -> exp * con
adamc@241 371
adamc@170 372 | branch of pat * exp
adamc@170 373 | branchs of (pat * exp) list
adamc@170 374 | pat of pat
adamc@822 375 | patS of pat
adamc@170 376 | pterm of pat
adamc@174 377 | rpat of (string * pat) list * bool
adamc@195 378 | ptuple of pat list
adamc@170 379
adam@1643 380 | attrs of exp option * exp option * (con * exp) list
adamc@721 381 | attr of attr
adamc@104 382 | attrv of exp
adamc@104 383
adamc@204 384 | query of exp
adamc@226 385 | query1 of exp
adamc@993 386 | dopt of exp
adamc@748 387 | tables of con list * exp
adamc@749 388 | fitem of con list * exp
adamc@204 389 | tname of con
adamc@705 390 | tnameW of con * con
adamc@705 391 | tnames of (con * con) * (con * con) list
adamc@705 392 | tnames' of (con * con) * (con * con) list
adamc@204 393 | table of con * exp
adamc@748 394 | table' of con * exp
adamc@207 395 | tident of con
adamc@207 396 | fident of con
adamc@207 397 | seli of select_item
adamc@207 398 | selis of select_item list
adamc@207 399 | select of select
adamc@209 400 | sqlexp of exp
adamc@209 401 | wopt of exp
adamc@226 402 | groupi of group_item
adamc@226 403 | groupis of group_item list
adamc@226 404 | gopt of group_item list option
adamc@227 405 | hopt of exp
adamc@230 406 | obopt of exp
adamc@268 407 | obitem of exp * exp
adamc@230 408 | obexps of exp
adam@1682 409 | popt of unit
adamc@268 410 | diropt of exp
adamc@231 411 | lopt of exp
adamc@232 412 | ofopt of exp
adamc@231 413 | sqlint of exp
adamc@236 414 | sqlagg of string
adamc@746 415 | fname of exp
adamc@207 416
adamc@302 417 | texp of exp
adamc@302 418 | fields of con list
adamc@302 419 | sqlexps of exp list
adamc@303 420 | fsets of (con * exp) list
adamc@310 421 | enterDml of unit
adamc@310 422 | leaveDml of unit
adamc@302 423
adamc@204 424
adamc@1 425 %verbose (* print summary of errors *)
adamc@1 426 %pos int (* positions *)
adamc@1 427 %start file
adamc@1 428 %pure
adamc@1 429 %eop EOF
adamc@1 430 %noshift EOF
adamc@1 431
adamc@244 432 %name Urweb
adamc@1 433
adamc@623 434 %right KARROW
adamc@623 435 %nonassoc DKARROW
adamc@243 436 %right SEMI
adamc@243 437 %nonassoc LARROW
adamc@195 438 %nonassoc IF THEN ELSE
adamc@843 439 %nonassoc DARROW
adamc@842 440 %left ANDALSO
adamc@842 441 %left ORELSE
adamc@1 442 %nonassoc COLON
adam@1306 443 %nonassoc DCOLON TCOLON DCOLONWILD TCOLONWILD
adam@1427 444 %left UNION INTERSECT EXCEPT ALL
adamc@1 445 %right COMMA
adamc@751 446 %right JOIN INNER CROSS OUTER LEFT RIGHT FULL
adamc@220 447 %right OR
adamc@220 448 %right CAND
adamc@470 449 %nonassoc EQ NE LT LE GT GE IS
adamc@243 450 %right ARROW
adamc@837 451 %right CARET PLUSPLUS
adamc@837 452 %left MINUSMINUS MINUSMINUSMINUS
adamc@389 453 %left PLUS MINUS
adamc@389 454 %left STAR DIVIDE MOD
adamc@220 455 %left NOT
adamc@84 456 %nonassoc TWIDDLE
adamc@1 457 %nonassoc DOLLAR
adamc@1 458 %left DOT
adamc@221 459 %nonassoc LBRACE RBRACE
adamc@1 460
adamc@1 461 %%
adamc@1 462
adamc@1 463 file : decls (decls)
adamc@54 464 | SIG sgis ([(DSgn ("?", (SgnConst sgis, s (SIGleft, sgisright))),
adamc@54 465 s (SIGleft, sgisright))])
adamc@1 466
adamc@1 467 decls : ([])
adamc@325 468 | decl decls (decl @ decls)
adamc@1 469
adamc@240 470 decl : CON SYMBOL cargl2 kopt EQ cexp (let
adamc@240 471 val loc = s (CONleft, cexpright)
adamc@240 472
adamc@240 473 val k = Option.getOpt (kopt, (KWild, loc))
adamc@240 474 val (c, k) = cargl2 (cexp, k)
adamc@240 475 in
adamc@325 476 [(DCon (SYMBOL, SOME k, c), loc)]
adamc@240 477 end)
adam@1654 478 | LTYPE SYMBOL cargl2 EQ cexp (let
adam@1654 479 val loc = s (LTYPEleft, cexpright)
adam@1654 480
adam@1654 481 val k = (KWild, loc)
adam@1654 482 val (c, k) = cargl2 (cexp, k)
adam@1654 483 in
adam@1654 484 [(DCon (SYMBOL, SOME k, c), loc)]
adam@1654 485 end)
adamc@805 486 | DATATYPE dtypes ([(DDatatype dtypes, s (DATATYPEleft, dtypesright))])
adamc@191 487 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
adamc@191 488 (case dargs of
adamc@325 489 [] => [(DDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))]
adamc@191 490 | _ => raise Fail "Arguments specified for imported datatype")
adamc@325 491 | VAL vali ([(DVal vali, s (VALleft, valiright))])
adamc@325 492 | VAL REC valis ([(DValRec valis, s (VALleft, valisright))])
adamc@325 493 | FUN valis ([(DValRec valis, s (FUNleft, valisright))])
adamc@1 494
adamc@325 495 | SIGNATURE CSYMBOL EQ sgn ([(DSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))])
adam@1732 496 | STRUCTURE CSYMBOL EQ str ([(DStr (CSYMBOL, NONE, NONE, str), s (STRUCTUREleft, strright))])
adam@1732 497 | STRUCTURE CSYMBOL COLON sgn EQ str ([(DStr (CSYMBOL, SOME sgn, NONE, str), s (STRUCTUREleft, strright))])
adamc@42 498 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN EQ str
adam@1732 499 ([(DStr (CSYMBOL1, NONE, NONE,
adamc@325 500 (StrFun (CSYMBOL2, sgn1, NONE, str), s (FUNCTORleft, strright))),
adamc@325 501 s (FUNCTORleft, strright))])
adamc@42 502 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn EQ str
adam@1732 503 ([(DStr (CSYMBOL1, NONE, NONE,
adamc@325 504 (StrFun (CSYMBOL2, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))),
adamc@325 505 s (FUNCTORleft, strright))])
adamc@61 506 | OPEN mpath (case mpath of
adamc@61 507 [] => raise Fail "Impossible mpath parse [1]"
adamc@325 508 | m :: ms => [(DOpen (m, ms), s (OPENleft, mpathright))])
adamc@325 509 | OPEN mpath LPAREN str RPAREN (let
adamc@325 510 val loc = s (OPENleft, RPARENright)
adamc@325 511
adamc@325 512 val m = case mpath of
adamc@325 513 [] => raise Fail "Impossible mpath parse [4]"
adamc@325 514 | m :: ms =>
adamc@325 515 foldl (fn (m, str) => (StrProj (str, m), loc))
adamc@325 516 (StrVar m, loc) ms
adamc@325 517 in
adam@1732 518 [(DStr ("anon", NONE, NONE, (StrApp (m, str), loc)), loc),
adamc@325 519 (DOpen ("anon", []), loc)]
adamc@325 520 end)
adamc@88 521 | OPEN CONSTRAINTS mpath (case mpath of
adamc@88 522 [] => raise Fail "Impossible mpath parse [3]"
adamc@325 523 | m :: ms => [(DOpenConstraints (m, ms), s (OPENleft, mpathright))])
adamc@325 524 | CONSTRAINT cterm TWIDDLE cterm ([(DConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))])
adamc@325 525 | EXPORT spath ([(DExport spath, s (EXPORTleft, spathright))])
adamc@707 526 | TABLE SYMBOL COLON cterm pkopt commaOpt cstopt([(DTable (SYMBOL, entable cterm, pkopt, cstopt),
adamc@707 527 s (TABLEleft, cstoptright))])
adamc@338 528 | SEQUENCE SYMBOL ([(DSequence SYMBOL, s (SEQUENCEleft, SYMBOLright))])
adamc@754 529 | VIEW SYMBOL EQ query ([(DView (SYMBOL, query),
adamc@754 530 s (VIEWleft, queryright))])
adamc@754 531 | VIEW SYMBOL EQ LBRACE eexp RBRACE ([(DView (SYMBOL, eexp),
adamc@754 532 s (VIEWleft, RBRACEright))])
adamc@563 533 | CLASS SYMBOL EQ cexp (let
adamc@563 534 val loc = s (CLASSleft, cexpright)
adamc@563 535 in
adamc@563 536 [(DClass (SYMBOL, (KWild, loc), cexp), loc)]
adamc@563 537 end)
adamc@563 538 | CLASS SYMBOL DCOLON kind EQ cexp ([(DClass (SYMBOL, kind, cexp), s (CLASSleft, cexpright))])
adamc@211 539 | CLASS SYMBOL SYMBOL EQ cexp (let
adamc@211 540 val loc = s (CLASSleft, cexpright)
adamc@563 541 val k = (KWild, loc)
adamc@211 542 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
adamc@211 543 in
adamc@563 544 [(DClass (SYMBOL1, k, c), s (CLASSleft, cexpright))]
adamc@563 545 end)
adamc@563 546 | CLASS SYMBOL LPAREN SYMBOL DCOLON kind RPAREN EQ cexp (let
adamc@563 547 val loc = s (CLASSleft, cexpright)
adamc@563 548 val c = (CAbs (SYMBOL2, SOME kind, cexp), loc)
adamc@563 549 in
adamc@563 550 [(DClass (SYMBOL1, kind, c), s (CLASSleft, cexpright))]
adamc@211 551 end)
adamc@459 552 | COOKIE SYMBOL COLON cexp ([(DCookie (SYMBOL, cexp), s (COOKIEleft, cexpright))])
adamc@720 553 | STYLE SYMBOL ([(DStyle SYMBOL, s (STYLEleft, SYMBOLright))])
adamc@1075 554 | TASK eapps EQ eexp ([(DTask (eapps, eexp), s (TASKleft, eexpright))])
adamc@1199 555 | POLICY eexp ([(DPolicy eexp, s (POLICYleft, eexpright))])
adamc@30 556
adamc@805 557 dtype : SYMBOL dargs EQ barOpt dcons (SYMBOL, dargs, dcons)
adamc@805 558
adamc@805 559 dtypes : dtype ([dtype])
adamc@805 560 | dtype AND dtypes (dtype :: dtypes)
adamc@805 561
adamc@240 562 kopt : (NONE)
adamc@240 563 | DCOLON kind (SOME kind)
adam@1302 564 | DCOLONWILD (SOME (KWild, s (DCOLONWILDleft, DCOLONWILDright)))
adamc@240 565
adamc@191 566 dargs : ([])
adamc@191 567 | SYMBOL dargs (SYMBOL :: dargs)
adamc@191 568
adamc@156 569 barOpt : ()
adamc@156 570 | BAR ()
adamc@156 571
adamc@156 572 dcons : dcon ([dcon])
adamc@156 573 | dcon BAR dcons (dcon :: dcons)
adamc@156 574
adamc@156 575 dcon : CSYMBOL (CSYMBOL, NONE)
adamc@156 576 | CSYMBOL OF cexp (CSYMBOL, SOME cexp)
adamc@156 577
adamc@242 578 vali : SYMBOL eargl2 copt EQ eexp (let
adamc@242 579 val loc = s (SYMBOLleft, eexpright)
adamc@242 580 val t = Option.getOpt (copt, (CWild (KType, loc), loc))
adamc@242 581
adamc@242 582 val (e, t) = eargl2 (eexp, t)
adamc@242 583 in
adamc@242 584 (SYMBOL, SOME t, e)
adamc@242 585 end)
adamc@242 586
adamc@242 587 copt : (NONE)
adamc@242 588 | COLON cexp (SOME cexp)
adamc@123 589
adamc@704 590 cstopt : (EVar (["Basis"], "no_constraint", Infer), dummy)
adamc@704 591 | csts (csts)
adamc@704 592
adamc@704 593 csts : CCONSTRAINT tname cst (let
adamc@704 594 val loc = s (CCONSTRAINTleft, cstright)
adamc@704 595
adamc@704 596 val e = (EVar (["Basis"], "one_constraint", Infer), loc)
adamc@704 597 val e = (ECApp (e, tname), loc)
adamc@704 598 in
adamc@704 599 (EApp (e, cst), loc)
adamc@704 600 end)
adamc@704 601 | csts COMMA csts (let
adamc@704 602 val loc = s (csts1left, csts2right)
adamc@704 603
adamc@704 604 val e = (EVar (["Basis"], "join_constraints", Infer), loc)
adamc@704 605 val e = (EApp (e, csts1), loc)
adamc@704 606 in
adamc@704 607 (EApp (e, csts2), loc)
adamc@704 608 end)
adamc@704 609 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
adamc@704 610
adamc@704 611 cst : UNIQUE tnames (let
adamc@704 612 val loc = s (UNIQUEleft, tnamesright)
adamc@704 613
adamc@704 614 val e = (EVar (["Basis"], "unique", Infer), loc)
adamc@705 615 val e = (ECApp (e, #1 (#1 tnames)), loc)
adamc@705 616 val e = (ECApp (e, (CRecord (#2 tnames), loc)), loc)
adamc@704 617 in
adamc@1093 618 e
adamc@704 619 end)
adamc@709 620
adamc@714 621 | CHECK sqlexp (let
adamc@714 622 val loc = s (CHECKleft, sqlexpright)
adamc@714 623 in
adamc@714 624 (EApp ((EVar (["Basis"], "check", Infer), loc),
adamc@714 625 sqlexp), loc)
adamc@714 626 end)
adamc@714 627
adamc@709 628 | FOREIGN KEY tnames REFERENCES texp LPAREN tnames' RPAREN pmodes
adamc@709 629 (let
adamc@709 630 val loc = s (FOREIGNleft, pmodesright)
adamc@709 631
adamc@709 632 val mat = ListPair.foldrEq
adamc@709 633 (fn ((nm1, _), (nm2, _), mat) =>
adamc@709 634 let
adamc@709 635 val e = (EVar (["Basis"], "mat_cons", Infer), loc)
adamc@709 636 val e = (ECApp (e, nm1), loc)
adamc@709 637 val e = (ECApp (e, nm2), loc)
adamc@709 638 in
adamc@709 639 (EApp (e, mat), loc)
adamc@709 640 end)
adamc@709 641 (EVar (["Basis"], "mat_nil", Infer), loc)
adamc@709 642 (#1 tnames :: #2 tnames, #1 tnames' :: #2 tnames')
adam@1401 643 handle ListPair.UnequalLengths =>
adam@1401 644 (ErrorMsg.errorAt loc ("Unequal foreign key list lengths ("
adam@1401 645 ^ Int.toString (1 + length (#2 tnames))
adam@1401 646 ^ " vs. "
adam@1401 647 ^ Int.toString (1 + length (#2 tnames'))
adam@1401 648 ^ ")");
adam@1401 649 (EVar (["Basis"], "mat_nil", Infer), loc))
adamc@709 650
adamc@709 651 fun findMode mode =
adamc@709 652 let
adamc@709 653 fun findMode' pmodes =
adamc@709 654 case pmodes of
adamc@709 655 [] => (EVar (["Basis"], "no_action", Infer), loc)
adamc@709 656 | (mode', rule) :: pmodes' =>
adamc@709 657 if mode' = mode then
adamc@709 658 (if List.exists (fn (mode', _) => mode' = mode)
adamc@709 659 pmodes' then
adamc@709 660 ErrorMsg.errorAt loc "Duplicate propagation rule"
adamc@709 661 else
adamc@709 662 ();
adamc@709 663 rule)
adamc@709 664 else
adamc@709 665 findMode' pmodes'
adamc@709 666 in
adamc@709 667 findMode' pmodes
adamc@709 668 end
adamc@709 669
adamc@709 670 val e = (EVar (["Basis"], "foreign_key", Infer), loc)
adamc@709 671 val e = (EApp (e, mat), loc)
adamc@709 672 val e = (EApp (e, texp), loc)
adamc@709 673 in
adamc@709 674 (EApp (e, (ERecord [((CName "OnDelete", loc),
adamc@709 675 findMode Delete),
adamc@709 676 ((CName "OnUpdate", loc),
adamc@709 677 findMode Update)], loc)), loc)
adamc@709 678 end)
adamc@709 679
adamc@704 680 | LBRACE eexp RBRACE (eexp)
adamc@704 681
adamc@704 682 tnameW : tname (let
adamc@704 683 val loc = s (tnameleft, tnameright)
adamc@704 684 in
adamc@704 685 (tname, (CWild (KType, loc), loc))
adamc@704 686 end)
adamc@704 687
adamc@705 688 tnames : tnameW (tnameW, [])
adamc@705 689 | LPAREN tnames' RPAREN (tnames')
adamc@704 690
adamc@705 691 tnames': tnameW (tnameW, [])
adamc@705 692 | tnameW COMMA tnames' (#1 tnames', tnameW :: #2 tnames')
adamc@704 693
adamc@709 694 pmode : ON pkind prule (pkind, prule)
adamc@709 695
adamc@709 696 pkind : DELETE (Delete)
adamc@709 697 | UPDATE (Update)
adamc@709 698
adamc@709 699 prule : NO ACTION (EVar (["Basis"], "no_action", Infer), s (NOleft, ACTIONright))
adamc@709 700 | RESTRICT (EVar (["Basis"], "restrict", Infer), s (RESTRICTleft, RESTRICTright))
adamc@709 701 | CASCADE (EVar (["Basis"], "cascade", Infer), s (CASCADEleft, CASCADEright))
adamc@709 702 | SET NULL (EVar (["Basis"], "set_null", Infer), s (SETleft, NULLright))
adamc@709 703
adamc@709 704 pmodes : ([])
adamc@709 705 | pmode pmodes (pmode :: pmodes)
adamc@709 706
adamc@707 707 commaOpt: ()
adamc@707 708 | COMMA ()
adamc@707 709
adam@1722 710 pk : LBRACE LBRACE eexp RBRACE RBRACE (eexp)
adam@1722 711 | tnames (let
adam@1722 712 val loc = s (tnamesleft, tnamesright)
adamc@707 713
adamc@1093 714 val e = (EVar (["Basis"], "primary_key", TypesOnly), loc)
adamc@707 715 val e = (ECApp (e, #1 (#1 tnames)), loc)
adamc@707 716 val e = (ECApp (e, (CRecord (#2 tnames), loc)), loc)
adamc@707 717 val e = (EDisjointApp e, loc)
adamc@707 718 val e = (EDisjointApp e, loc)
adamc@707 719
adamc@707 720 val witness = map (fn (c, _) =>
adamc@707 721 (c, (EWild, loc)))
adamc@707 722 (#1 tnames :: #2 tnames)
adamc@707 723 val witness = (ERecord witness, loc)
adamc@707 724 in
adamc@707 725 (EApp (e, witness), loc)
adamc@707 726 end)
adamc@707 727
adam@1722 728 pkopt : (EVar (["Basis"], "no_primary_key", Infer), dummy)
adam@1722 729 | PRIMARY KEY pk (pk)
adam@1722 730
adamc@123 731 valis : vali ([vali])
adamc@123 732 | vali AND valis (vali :: valis)
adamc@123 733
adamc@42 734 sgn : sgntm (sgntm)
adamc@40 735 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@40 736 (SgnFun (CSYMBOL, sgn1, sgn2), s (FUNCTORleft, sgn2right))
adamc@30 737
adamc@42 738 sgntm : SIG sgis END (SgnConst sgis, s (SIGleft, ENDright))
adamc@59 739 | mpath (case mpath of
adamc@61 740 [] => raise Fail "Impossible mpath parse [2]"
adamc@59 741 | [x] => SgnVar x
adamc@59 742 | m :: ms => SgnProj (m,
adamc@59 743 List.take (ms, length ms - 1),
adamc@59 744 List.nth (ms, length ms - 1)),
adamc@59 745 s (mpathleft, mpathright))
adamc@42 746 | sgntm WHERE CON SYMBOL EQ cexp (SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
adamc@42 747 | sgntm WHERE LTYPE SYMBOL EQ cexp(SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
adamc@42 748 | LPAREN sgn RPAREN (sgn)
adamc@42 749
adam@1577 750 cexpO : (NONE)
adam@1577 751 | EQ cexp (SOME cexp)
adam@1577 752
adam@1577 753 sgi : LTYPE SYMBOL ((SgiConAbs (SYMBOL, (KType, s (LTYPEleft, SYMBOLright))),
adamc@706 754 s (LTYPEleft, SYMBOLright)))
adam@1577 755 | CON SYMBOL cargl2 kopt cexpO (let
adam@1577 756 val loc = s (CONleft, cexpOright)
adam@1574 757
adam@1574 758 val k = Option.getOpt (kopt, (KWild, loc))
adam@1574 759 in
adam@1577 760 case cexpO of
adam@1577 761 NONE => (SgiConAbs (SYMBOL, k), loc)
adam@1577 762 | SOME cexp =>
adam@1577 763 let
adam@1577 764 val (c, k) = cargl2 (cexp, k)
adam@1577 765 in
adam@1577 766 (SgiCon (SYMBOL, SOME k, c), loc)
adam@1577 767 end
adam@1574 768 end)
adam@1654 769 | LTYPE SYMBOL cargl2 cexpO (let
adam@1654 770 val loc = s (LTYPEleft, cexpOright)
adam@1654 771
adam@1654 772 val k = (KWild, loc)
adam@1654 773 in
adam@1654 774 case cexpO of
adam@1654 775 NONE => (SgiConAbs (SYMBOL, k), loc)
adam@1654 776 | SOME cexp =>
adam@1654 777 let
adam@1654 778 val (c, k) = cargl2 (cexp, k)
adam@1654 779 in
adam@1654 780 (SgiCon (SYMBOL, SOME k, c), loc)
adam@1654 781 end
adam@1654 782 end)
adamc@805 783 | DATATYPE dtypes ((SgiDatatype dtypes, s (DATATYPEleft, dtypesright)))
adamc@191 784 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
adamc@191 785 (case dargs of
adamc@191 786 [] => (SgiDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
adamc@191 787 | _ => raise Fail "Arguments specified for imported datatype")
adamc@706 788 | VAL SYMBOL COLON cexp ((SgiVal (SYMBOL, cexp), s (VALleft, cexpright)))
adamc@30 789
adamc@706 790 | STRUCTURE CSYMBOL COLON sgn ((SgiStr (CSYMBOL, sgn), s (STRUCTUREleft, sgnright)))
adamc@706 791 | SIGNATURE CSYMBOL EQ sgn ((SgiSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright)))
adamc@42 792 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@706 793 ((SgiStr (CSYMBOL1,
adamc@706 794 (SgnFun (CSYMBOL2, sgn1, sgn2), s (FUNCTORleft, sgn2right))),
adamc@706 795 s (FUNCTORleft, sgn2right)))
adamc@706 796 | INCLUDE sgn ((SgiInclude sgn, s (INCLUDEleft, sgnright)))
adamc@706 797 | CONSTRAINT cterm TWIDDLE cterm ((SgiConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright)))
adamc@707 798 | TABLE SYMBOL COLON cterm pkopt commaOpt cstopt (let
adamc@707 799 val loc = s (TABLEleft, ctermright)
adamc@707 800 in
adamc@707 801 (SgiTable (SYMBOL, entable cterm, pkopt, cstopt), loc)
adamc@707 802 end)
adamc@460 803 | SEQUENCE SYMBOL (let
adamc@460 804 val loc = s (SEQUENCEleft, SYMBOLright)
adamc@460 805 val t = (CVar (["Basis"], "sql_sequence"), loc)
adamc@460 806 in
adamc@460 807 (SgiVal (SYMBOL, t), loc)
adamc@460 808 end)
adamc@754 809 | VIEW SYMBOL COLON cexp (let
adamc@754 810 val loc = s (VIEWleft, cexpright)
adamc@754 811 val t = (CVar (["Basis"], "sql_view"), loc)
adamc@1076 812 val t = (CApp (t, entable cexp), loc)
adamc@754 813 in
adamc@754 814 (SgiVal (SYMBOL, t), loc)
adamc@754 815 end)
adamc@563 816 | CLASS SYMBOL (let
adamc@563 817 val loc = s (CLASSleft, SYMBOLright)
adamc@711 818 val k = (KArrow ((KType, loc), (KType, loc)), loc)
adamc@563 819 in
adamc@711 820 (SgiClassAbs (SYMBOL, k), loc)
adamc@563 821 end)
adamc@563 822 | CLASS SYMBOL DCOLON kind (let
adamc@563 823 val loc = s (CLASSleft, kindright)
adamc@563 824 in
adamc@563 825 (SgiClassAbs (SYMBOL, kind), loc)
adamc@563 826 end)
adamc@563 827 | CLASS SYMBOL EQ cexp (let
adamc@563 828 val loc = s (CLASSleft, cexpright)
adamc@563 829 in
adamc@563 830 (SgiClass (SYMBOL, (KWild, loc), cexp), loc)
adamc@563 831 end)
adamc@563 832 | CLASS SYMBOL DCOLON kind EQ cexp (let
adamc@563 833 val loc = s (CLASSleft, cexpright)
adamc@563 834 in
adamc@563 835 (SgiClass (SYMBOL, kind, cexp), loc)
adamc@563 836 end)
adamc@211 837 | CLASS SYMBOL SYMBOL EQ cexp (let
adamc@211 838 val loc = s (CLASSleft, cexpright)
adamc@563 839 val k = (KWild, loc)
adamc@211 840 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
adamc@211 841 in
adamc@563 842 (SgiClass (SYMBOL1, k, c), s (CLASSleft, cexpright))
adamc@563 843 end)
adamc@563 844 | CLASS SYMBOL LPAREN SYMBOL DCOLON kind RPAREN EQ cexp (let
adamc@563 845 val loc = s (CLASSleft, cexpright)
adamc@563 846 val c = (CAbs (SYMBOL2, SOME kind, cexp), loc)
adamc@563 847 in
adamc@563 848 (SgiClass (SYMBOL1, kind, c), s (CLASSleft, cexpright))
adamc@211 849 end)
adamc@460 850 | COOKIE SYMBOL COLON cexp (let
adamc@460 851 val loc = s (COOKIEleft, cexpright)
adamc@460 852 val t = (CApp ((CVar (["Basis"], "http_cookie"), loc),
adamc@460 853 entable cexp), loc)
adamc@460 854 in
adamc@460 855 (SgiVal (SYMBOL, t), loc)
adamc@460 856 end)
adamc@720 857 | STYLE SYMBOL (let
adamc@720 858 val loc = s (STYLEleft, SYMBOLright)
adamc@720 859 val t = (CVar (["Basis"], "css_class"), loc)
adamc@718 860 in
adamc@718 861 (SgiVal (SYMBOL, t), loc)
adamc@718 862 end)
adamc@30 863
adamc@30 864 sgis : ([])
adamc@30 865 | sgi sgis (sgi :: sgis)
adamc@30 866
adamc@30 867 str : STRUCT decls END (StrConst decls, s (STRUCTleft, ENDright))
adamc@34 868 | spath (spath)
adamc@40 869 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN DARROW str
adamc@40 870 (StrFun (CSYMBOL, sgn, NONE, str), s (FUNCTORleft, strright))
adamc@40 871 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn DARROW str
adamc@40 872 (StrFun (CSYMBOL, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))
adamc@44 873 | spath LPAREN str RPAREN (StrApp (spath, str), s (spathleft, RPARENright))
adamc@34 874
adamc@34 875 spath : CSYMBOL (StrVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@34 876 | spath DOT CSYMBOL (StrProj (spath, CSYMBOL), s (spathleft, CSYMBOLright))
adamc@30 877
adamc@1 878 kind : TYPE (KType, s (TYPEleft, TYPEright))
adamc@1 879 | NAME (KName, s (NAMEleft, NAMEright))
adamc@1 880 | LBRACE kind RBRACE (KRecord kind, s (LBRACEleft, RBRACEright))
adamc@1 881 | kind ARROW kind (KArrow (kind1, kind2), s (kind1left, kind2right))
adamc@1 882 | LPAREN kind RPAREN (#1 kind, s (LPARENleft, RPARENright))
adamc@82 883 | KUNIT (KUnit, s (KUNITleft, KUNITright))
adamc@18 884 | UNDERUNDER (KWild, s (UNDERUNDERleft, UNDERUNDERright))
adamc@207 885 | LPAREN ktuple RPAREN (KTuple ktuple, s (LPARENleft, RPARENright))
adamc@623 886 | CSYMBOL (KVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@623 887 | CSYMBOL KARROW kind (KFun (CSYMBOL, kind), s (CSYMBOLleft, kindright))
adamc@207 888
adamc@207 889 ktuple : kind STAR kind ([kind1, kind2])
adamc@207 890 | kind STAR ktuple (kind :: ktuple)
adamc@1 891
adamc@1 892 capps : cterm (cterm)
adamc@1 893 | capps cterm (CApp (capps, cterm), s (cappsleft, ctermright))
adamc@1 894
adamc@1 895 cexp : capps (capps)
adamc@1 896 | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right))
adamc@15 897 | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright))
adamc@623 898 | CSYMBOL KARROW cexp (TKFun (CSYMBOL, cexp), s (CSYMBOLleft, cexpright))
adamc@1 899
adamc@1 900 | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right))
adamc@1 901
adamc@239 902 | FN cargs DARROW cexp (#1 (cargs (cexp, (KWild, s (FNleft, cexpright)))))
adamc@628 903 | LBRACK cexp TWIDDLE cexp RBRACK DARROW cexp (TDisjoint (cexp1, cexp2, cexp3), s (LBRACKleft, cexp3right))
adamc@623 904 | CSYMBOL DKARROW cexp (CKAbs (CSYMBOL, cexp), s (CSYMBOLleft, cexpright))
adamc@1 905
adamc@8 906 | LPAREN cexp RPAREN DCOLON kind (CAnnot (cexp, kind), s (LPARENleft, kindright))
adamc@6 907
adamc@18 908 | UNDER DCOLON kind (CWild kind, s (UNDERleft, UNDERright))
adamc@195 909 | ctuple (let
adamc@195 910 val loc = s (ctupleleft, ctupleright)
adamc@195 911 in
adamc@195 912 (TRecord (CRecord (ListUtil.mapi (fn (i, c) =>
adamc@195 913 ((CName (Int.toString (i + 1)), loc),
adamc@195 914 c)) ctuple),
adamc@195 915 loc), loc)
adamc@195 916 end)
adamc@18 917
adamc@1 918 kcolon : DCOLON (Explicit)
adamc@1 919 | TCOLON (Implicit)
adamc@1 920
adamc@239 921 cargs : carg (carg)
adamc@239 922 | cargl (cargl)
adamc@239 923
adamc@239 924 cargl : cargp cargp (cargp1 o cargp2)
adamc@239 925 | cargp cargl (cargp o cargl)
adamc@239 926
adamc@240 927 cargl2 : (fn x => x)
adamc@240 928 | cargp cargl2 (cargp o cargl2)
adamc@240 929
adamc@241 930 carg : SYMBOL DCOLON kind (fn (c, k) =>
adamc@239 931 let
adamc@239 932 val loc = s (SYMBOLleft, kindright)
adamc@239 933 in
adamc@239 934 ((CAbs (SYMBOL, SOME kind, c), loc),
adamc@239 935 (KArrow (kind, k), loc))
adamc@239 936 end)
adamc@329 937 | UNDER DCOLON kind (fn (c, k) =>
adamc@329 938 let
adamc@329 939 val loc = s (UNDERleft, kindright)
adamc@329 940 in
adamc@329 941 ((CAbs ("_", SOME kind, c), loc),
adamc@329 942 (KArrow (kind, k), loc))
adamc@329 943 end)
adam@1302 944 | SYMBOL DCOLONWILD (fn (c, k) =>
adam@1302 945 let
adam@1302 946 val loc = s (SYMBOLleft, DCOLONWILDright)
adam@1302 947 val kind = (KWild, loc)
adam@1302 948 in
adam@1302 949 ((CAbs (SYMBOL, NONE, c), loc),
adam@1302 950 (KArrow (kind, k), loc))
adam@1302 951 end)
adam@1302 952 | UNDER DCOLONWILD (fn (c, k) =>
adam@1302 953 let
adam@1302 954 val loc = s (UNDERleft, DCOLONWILDright)
adam@1302 955 val kind = (KWild, loc)
adam@1302 956 in
adam@1302 957 ((CAbs ("_", NONE, c), loc),
adam@1302 958 (KArrow (kind, k), loc))
adam@1302 959 end)
adamc@241 960 | cargp (cargp)
adamc@239 961
adamc@239 962 cargp : SYMBOL (fn (c, k) =>
adamc@239 963 let
adamc@239 964 val loc = s (SYMBOLleft, SYMBOLright)
adamc@239 965 in
adamc@239 966 ((CAbs (SYMBOL, NONE, c), loc),
adamc@239 967 (KArrow ((KWild, loc), k), loc))
adamc@239 968 end)
adamc@329 969 | UNDER (fn (c, k) =>
adamc@329 970 let
adamc@329 971 val loc = s (UNDERleft, UNDERright)
adamc@329 972 in
adamc@329 973 ((CAbs ("_", NONE, c), loc),
adamc@329 974 (KArrow ((KWild, loc), k), loc))
adamc@329 975 end)
adamc@1001 976 | LPAREN SYMBOL kopt ckl RPAREN (fn (c, k) =>
adamc@239 977 let
adamc@239 978 val loc = s (LPARENleft, RPARENright)
adamc@1001 979 val ckl = (SYMBOL, kopt) :: ckl
adamc@1001 980 val ckl = map (fn (x, ko) => (x, case ko of
adamc@1001 981 NONE => (KWild, loc)
adamc@1001 982 | SOME k => k)) ckl
adamc@239 983 in
adamc@1001 984 case ckl of
adamc@1001 985 [(x, k')] => ((CAbs (SYMBOL, SOME k', c), loc),
adamc@1001 986 (KArrow (k', k), loc))
adamc@1001 987 | _ =>
adamc@1001 988 let
adamc@1001 989 val k' = (KTuple (map #2 ckl), loc)
adamc@1001 990
adamc@1001 991 val c = foldr (fn ((x, k), c) =>
adamc@1001 992 (CAbs (x, SOME k, c), loc)) c ckl
adamc@1001 993 val v = (CVar ([], "$x"), loc)
adamc@1001 994 val c = ListUtil.foldli (fn (i, _, c) =>
adamc@1001 995 (CApp (c, (CProj (v, i + 1), loc)),
adamc@1001 996 loc)) c ckl
adamc@1001 997 in
adamc@1001 998 ((CAbs ("$x", SOME k', c), loc),
adamc@1001 999 (KArrow (k', k), loc))
adamc@1001 1000 end
adamc@239 1001 end)
adamc@628 1002
adamc@1001 1003 ckl : ([])
adamc@1001 1004 | COMMA SYMBOL kopt ckl ((SYMBOL, kopt) :: ckl)
adamc@239 1005
adamc@34 1006 path : SYMBOL ([], SYMBOL)
adamc@34 1007 | CSYMBOL DOT path (let val (ms, x) = path in (CSYMBOL :: ms, x) end)
adamc@34 1008
adamc@156 1009 cpath : CSYMBOL ([], CSYMBOL)
adamc@156 1010 | CSYMBOL DOT cpath (let val (ms, x) = cpath in (CSYMBOL :: ms, x) end)
adamc@156 1011
adamc@59 1012 mpath : CSYMBOL ([CSYMBOL])
adamc@59 1013 | CSYMBOL DOT mpath (CSYMBOL :: mpath)
adamc@59 1014
adamc@1 1015 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright))
adamc@1 1016 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright))
adamc@83 1017 | LBRACK rconn RBRACK (CRecord rconn, s (LBRACKleft, RBRACKright))
adamc@1 1018 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)),
adamc@1 1019 s (LBRACEleft, RBRACEright))
adamc@1 1020 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright))
adamc@1 1021 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright))
adamc@195 1022 | HASH INT (CName (Int64.toString INT), s (HASHleft, INTright))
adamc@1 1023
adamc@34 1024 | path (CVar path, s (pathleft, pathright))
adamc@207 1025 | path DOT INT (CProj ((CVar path, s (pathleft, pathright)), Int64.toInt INT),
adamc@207 1026 s (pathleft, INTright))
adamc@18 1027 | UNDER (CWild (KWild, s (UNDERleft, UNDERright)), s (UNDERleft, UNDERright))
adamc@621 1028 | MAP (CMap, s (MAPleft, MAPright))
adamc@82 1029 | UNIT (CUnit, s (UNITleft, UNITright))
adamc@207 1030 | LPAREN ctuplev RPAREN (CTuple ctuplev, s (LPARENleft, RPARENright))
adamc@207 1031
adamc@207 1032 ctuplev: cexp COMMA cexp ([cexp1, cexp2])
adamc@207 1033 | cexp COMMA ctuplev (cexp :: ctuplev)
adamc@1 1034
adamc@196 1035 ctuple : capps STAR capps ([capps1, capps2])
adamc@196 1036 | capps STAR ctuple (capps :: ctuple)
adamc@195 1037
adamc@1 1038 rcon : ([])
adamc@1 1039 | ident EQ cexp ([(ident, cexp)])
adamc@1 1040 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon)
adamc@1 1041
adamc@83 1042 rconn : ident ([(ident, (CUnit, s (identleft, identright)))])
adamc@83 1043 | ident COMMA rconn ((ident, (CUnit, s (identleft, identright))) :: rconn)
adamc@83 1044
adamc@1 1045 rcone : ([])
adamc@1 1046 | ident COLON cexp ([(ident, cexp)])
adamc@1 1047 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone)
adamc@1 1048
adamc@1 1049 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@195 1050 | INT (CName (Int64.toString INT), s (INTleft, INTright))
adamc@200 1051 | SYMBOL (CVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@8 1052
adamc@8 1053 eapps : eterm (eterm)
adamc@8 1054 | eapps eterm (EApp (eapps, eterm), s (eappsleft, etermright))
adamc@8 1055 | eapps LBRACK cexp RBRACK (ECApp (eapps, cexp), s (eappsleft, RBRACKright))
adamc@629 1056 | eapps BANG (EDisjointApp eapps, s (eappsleft, BANGright))
adamc@8 1057
adamc@8 1058 eexp : eapps (eapps)
adamc@241 1059 | FN eargs DARROW eexp (let
adamc@93 1060 val loc = s (FNleft, eexpright)
adamc@93 1061 in
adamc@241 1062 #1 (eargs (eexp, (CWild (KType, loc), loc)))
adamc@93 1063 end)
adamc@623 1064 | CSYMBOL DKARROW eexp (EKAbs (CSYMBOL, eexp), s (CSYMBOLleft, eexpright))
adamc@196 1065 | eexp COLON cexp (EAnnot (eexp, cexp), s (eexpleft, cexpright))
adamc@149 1066 | eexp MINUSMINUS cexp (ECut (eexp, cexp), s (eexpleft, cexpright))
adamc@493 1067 | eexp MINUSMINUSMINUS cexp (ECutMulti (eexp, cexp), s (eexpleft, cexpright))
adamc@170 1068 | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
adamc@190 1069 | IF eexp THEN eexp ELSE eexp (let
adamc@190 1070 val loc = s (IFleft, eexp3right)
adamc@190 1071 in
adamc@190 1072 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc), eexp2),
adamc@190 1073 ((PCon (["Basis"], "False", NONE), loc), eexp3)]), loc)
adamc@190 1074 end)
adamc@434 1075 | bind SEMI eexp (let
adamc@434 1076 val loc = s (bindleft, eexpright)
adamc@434 1077 val (v, to, e1) = bind
adamc@403 1078 val e = (EVar (["Basis"], "bind", Infer), loc)
adamc@434 1079 val e = (EApp (e, e1), loc)
adamc@243 1080 in
adamc@434 1081 (EApp (e, (EAbs (v, to, eexp), loc)), loc)
adamc@299 1082 end)
adamc@256 1083 | eexp EQ eexp (native_op ("eq", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@257 1084 | eexp NE eexp (native_op ("ne", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 1085 | MINUS eterm (native_unop ("neg", eterm, s (MINUSleft, etermright)))
adamc@389 1086 | eexp PLUS eexp (native_op ("plus", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 1087 | eexp MINUS eexp (native_op ("minus", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@1116 1088 | eapps STAR eexp (native_op ("times", eapps, eexp, s (eappsleft, eexpright)))
adamc@964 1089 | eexp DIVIDE eexp (native_op ("divide", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 1090 | eexp MOD eexp (native_op ("mod", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1091
adamc@391 1092 | eexp LT eexp (native_op ("lt", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1093 | eexp LE eexp (native_op ("le", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1094 | eexp GT eexp (native_op ("gt", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1095 | eexp GE eexp (native_op ("ge", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1096
adamc@842 1097 | eexp ANDALSO eexp (let
adamc@842 1098 val loc = s (eexp1left, eexp2right)
adamc@842 1099 in
adamc@842 1100 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc),
adamc@842 1101 eexp2),
adamc@842 1102 ((PCon (["Basis"], "False", NONE), loc),
adamc@842 1103 (EVar (["Basis"], "False", Infer), loc))]), loc)
adamc@842 1104 end)
adamc@842 1105 | eexp ORELSE eexp (let
adamc@842 1106 val loc = s (eexp1left, eexp2right)
adamc@842 1107 in
adamc@842 1108 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc),
adamc@842 1109 (EVar (["Basis"], "True", Infer), loc)),
adamc@842 1110 ((PCon (["Basis"], "False", NONE), loc),
adamc@842 1111 eexp2)]), loc)
adamc@842 1112 end)
adamc@842 1113
adamc@445 1114 | eexp PLUSPLUS eexp (EConcat (eexp1, eexp2), s (eexp1left, eexp2right))
adamc@8 1115
adamc@674 1116 | eexp CARET eexp (native_op ("strcat", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@674 1117
adamc@794 1118 | eapps DCOLON eexp (let
adamc@794 1119 val loc = s (eappsleft, eexpright)
adamc@762 1120 in
adamc@762 1121 (EApp ((EVar (["Basis"], "Cons", Infer), loc),
adamc@762 1122 (ERecord [((CName "1", loc),
adamc@794 1123 eapps),
adamc@762 1124 ((CName "2", loc),
adamc@762 1125 eexp)], loc)), loc)
adamc@762 1126 end)
adamc@762 1127
adamc@434 1128 bind : SYMBOL LARROW eapps (SYMBOL, NONE, eapps)
adamc@434 1129 | eapps (let
adamc@434 1130 val loc = s (eappsleft, eappsright)
adamc@434 1131 in
adamc@434 1132 ("_", SOME (TRecord (CRecord [], loc), loc), eapps)
adamc@434 1133 end)
adamc@434 1134
adamc@241 1135 eargs : earg (earg)
adamc@241 1136 | eargl (eargl)
adamc@241 1137
adamc@241 1138 eargl : eargp eargp (eargp1 o eargp2)
adamc@241 1139 | eargp eargl (eargp o eargl)
adamc@241 1140
adamc@242 1141 eargl2 : (fn x => x)
adamc@242 1142 | eargp eargl2 (eargp o eargl2)
adamc@242 1143
adamc@822 1144 earg : patS (fn (e, t) =>
adamc@241 1145 let
adamc@822 1146 val loc = s (patSleft, patSright)
adamc@822 1147 val pt = patType loc patS
adamc@822 1148
adamc@822 1149 val e' = case #1 patS of
adamc@822 1150 PVar x => (EAbs (x, NONE, e), loc)
adamc@823 1151 | PAnnot ((PVar x, _), t) => (EAbs (x, SOME t, e), loc)
adamc@822 1152 | _ => (EAbs ("$x", SOME pt,
adamc@822 1153 (ECase ((EVar ([], "$x", DontInfer),
adamc@822 1154 loc),
adamc@822 1155 [(patS, e)]), loc)), loc)
adamc@241 1156 in
adamc@822 1157 (e', (TFun (pt, t), loc))
adamc@241 1158 end)
adamc@822 1159 | earga (earga)
adamc@822 1160
adamc@822 1161 eargp : pterm (fn (e, t) =>
adamc@241 1162 let
adamc@822 1163 val loc = s (ptermleft, ptermright)
adamc@822 1164 val pt = patType loc pterm
adamc@822 1165
adamc@822 1166 val e' = case #1 pterm of
adamc@822 1167 PVar x => (EAbs (x, NONE, e), loc)
adamc@823 1168 | PAnnot ((PVar x, _), t) => (EAbs (x, SOME t, e), loc)
adamc@822 1169 | _ => (EAbs ("$x", SOME pt,
adamc@822 1170 (ECase ((EVar ([], "$x", DontInfer),
adamc@822 1171 loc),
adamc@822 1172 [(pterm, e)]), loc)), loc)
adamc@241 1173 in
adamc@822 1174 (e', (TFun (pt, t), loc))
adamc@241 1175 end)
adamc@822 1176 | earga (earga)
adamc@241 1177
adamc@822 1178 earga : LBRACK SYMBOL RBRACK (fn (e, t) =>
adamc@241 1179 let
adamc@822 1180 val loc = s (LBRACKleft, RBRACKright)
adamc@822 1181 val kind = (KWild, loc)
adamc@822 1182 in
adamc@822 1183 ((ECAbs (Implicit, SYMBOL, kind, e), loc),
adamc@822 1184 (TCFun (Implicit, SYMBOL, kind, t), loc))
adamc@822 1185 end)
adam@1302 1186 | LBRACK SYMBOL DCOLONWILD RBRACK (fn (e, t) =>
adam@1302 1187 let
adam@1302 1188 val loc = s (LBRACKleft, RBRACKright)
adam@1302 1189 val kind = (KWild, loc)
adam@1302 1190 in
adam@1302 1191 ((ECAbs (Explicit, SYMBOL, kind, e), loc),
adam@1302 1192 (TCFun (Explicit, SYMBOL, kind, t), loc))
adam@1302 1193 end)
adamc@822 1194 | LBRACK SYMBOL kcolon kind RBRACK(fn (e, t) =>
adamc@822 1195 let
adamc@822 1196 val loc = s (LBRACKleft, RBRACKright)
adamc@241 1197 in
adamc@241 1198 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
adamc@241 1199 (TCFun (kcolon, SYMBOL, kind, t), loc))
adamc@241 1200 end)
adam@1306 1201 | LBRACK SYMBOL TCOLONWILD RBRACK (fn (e, t) =>
adam@1306 1202 let
adam@1306 1203 val loc = s (LBRACKleft, RBRACKright)
adam@1306 1204 val kind = (KWild, loc)
adam@1306 1205 in
adam@1306 1206 ((ECAbs (Implicit, SYMBOL, kind, e), loc),
adam@1306 1207 (TCFun (Implicit, SYMBOL, kind, t), loc))
adam@1306 1208 end)
adamc@478 1209 | LBRACK cexp TWIDDLE cexp RBRACK(fn (e, t) =>
adamc@356 1210 let
adamc@356 1211 val loc = s (LBRACKleft, RBRACKright)
adamc@356 1212 in
adamc@478 1213 ((EDisjoint (cexp1, cexp2, e), loc),
adamc@628 1214 (TDisjoint (cexp1, cexp2, t), loc))
adamc@356 1215 end)
adamc@822 1216 | LBRACK CSYMBOL RBRACK (fn (e, t) =>
adamc@623 1217 let
adamc@623 1218 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@623 1219 in
adamc@623 1220 ((EKAbs (CSYMBOL, e), loc),
adamc@623 1221 (TKFun (CSYMBOL, t), loc))
adamc@623 1222 end)
adamc@241 1223
adamc@8 1224 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
adamc@195 1225 | LPAREN etuple RPAREN (let
adamc@195 1226 val loc = s (LPARENleft, RPARENright)
adamc@195 1227 in
adamc@195 1228 (ERecord (ListUtil.mapi (fn (i, e) =>
adamc@195 1229 ((CName (Int.toString (i + 1)), loc),
adamc@195 1230 e)) etuple), loc)
adamc@195 1231 end)
adamc@8 1232
adamc@403 1233 | path (EVar (#1 path, #2 path, Infer), s (pathleft, pathright))
adamc@403 1234 | cpath (EVar (#1 cpath, #2 cpath, Infer), s (cpathleft, cpathright))
adamc@403 1235 | AT path (EVar (#1 path, #2 path, TypesOnly), s (ATleft, pathright))
adamc@403 1236 | AT AT path (EVar (#1 path, #2 path, DontInfer), s (AT1left, pathright))
adamc@403 1237 | AT cpath (EVar (#1 cpath, #2 cpath, TypesOnly), s (ATleft, cpathright))
adamc@403 1238 | AT AT cpath (EVar (#1 cpath, #2 cpath, DontInfer), s (AT1left, cpathright))
adamc@12 1239 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
adamc@110 1240 | UNIT (ERecord [], s (UNITleft, UNITright))
adamc@12 1241
adamc@14 1242 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@14 1243 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@14 1244 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@821 1245 | CHAR (EPrim (Prim.Char CHAR), s (CHARleft, CHARright))
adamc@14 1246
adamc@200 1247 | path DOT idents (let
adamc@200 1248 val loc = s (pathleft, identsright)
adamc@200 1249 in
adamc@200 1250 foldl (fn (ident, e) =>
adamc@200 1251 (EField (e, ident), loc))
adamc@403 1252 (EVar (#1 path, #2 path, Infer), s (pathleft, pathright)) idents
adamc@403 1253 end)
adamc@910 1254 | LPAREN eexp RPAREN DOT idents (let
adamc@910 1255 val loc = s (LPARENleft, identsright)
adamc@910 1256 in
adamc@910 1257 foldl (fn (ident, e) =>
adamc@910 1258 (EField (e, ident), loc))
adamc@910 1259 eexp idents
adamc@910 1260 end)
adamc@403 1261 | AT path DOT idents (let
adamc@403 1262 val loc = s (ATleft, identsright)
adamc@403 1263 in
adamc@403 1264 foldl (fn (ident, e) =>
adamc@403 1265 (EField (e, ident), loc))
adamc@403 1266 (EVar (#1 path, #2 path, TypesOnly), s (pathleft, pathright)) idents
adamc@403 1267 end)
adamc@403 1268 | AT AT path DOT idents (let
adamc@403 1269 val loc = s (AT1left, identsright)
adamc@403 1270 in
adamc@403 1271 foldl (fn (ident, e) =>
adamc@403 1272 (EField (e, ident), loc))
adamc@403 1273 (EVar (#1 path, #2 path, DontInfer), s (pathleft, pathright)) idents
adamc@200 1274 end)
adamc@71 1275
adamc@360 1276 | XML_BEGIN xml XML_END (let
adamc@360 1277 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 1278 in
adamc@360 1279 if XML_BEGIN = "xml" then
adamc@360 1280 ()
adamc@360 1281 else
adamc@360 1282 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@360 1283 xml
adamc@360 1284 end)
adamc@360 1285 | XML_BEGIN XML_END (let
adamc@360 1286 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 1287 in
adamc@360 1288 if XML_BEGIN = "xml" then
adamc@360 1289 ()
adamc@360 1290 else
adamc@360 1291 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@403 1292 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
adamc@360 1293 (EPrim (Prim.String ""), loc)),
adamc@360 1294 loc)
adamc@360 1295 end)
adamc@360 1296 | XML_BEGIN_END (let
adamc@360 1297 val loc = s (XML_BEGIN_ENDleft, XML_BEGIN_ENDright)
adamc@360 1298 in
adamc@360 1299 if XML_BEGIN_END = "xml" then
adamc@360 1300 ()
adamc@360 1301 else
adamc@360 1302 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@403 1303 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
adamc@360 1304 (EPrim (Prim.String ""), loc)),
adamc@360 1305 loc)
adamc@360 1306 end)
adamc@302 1307
adamc@204 1308 | LPAREN query RPAREN (query)
adamc@300 1309 | LPAREN CWHERE sqlexp RPAREN (sqlexp)
adamc@339 1310 | LPAREN SQL sqlexp RPAREN (sqlexp)
adamc@1070 1311 | LPAREN FROM tables RPAREN (#2 tables)
adamc@1071 1312 | LPAREN SELECT1 query1 RPAREN (query1)
adamc@302 1313
adamc@302 1314 | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN
adamc@302 1315 (let
adamc@302 1316 val loc = s (LPAREN1left, RPAREN3right)
adamc@302 1317
adamc@403 1318 val e = (EVar (["Basis"], "insert", Infer), loc)
adamc@302 1319 val e = (EApp (e, texp), loc)
adamc@302 1320 in
adamc@302 1321 if length fields <> length sqlexps then
adam@1360 1322 ErrorMsg.errorAt loc ("Length mismatch in INSERT field specification ("
adam@1360 1323 ^ Int.toString (length fields)
adam@1360 1324 ^ " vs. " ^ Int.toString (length sqlexps) ^ ")")
adamc@302 1325 else
adamc@302 1326 ();
adamc@302 1327 (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
adamc@302 1328 end)
adamc@310 1329 | LPAREN enterDml UPDATE texp SET fsets CWHERE sqlexp leaveDml RPAREN
adamc@303 1330 (let
adamc@303 1331 val loc = s (LPARENleft, RPARENright)
adamc@303 1332
adamc@403 1333 val e = (EVar (["Basis"], "update", Infer), loc)
adamc@342 1334 val e = (ECApp (e, (CWild (KRecord (KType, loc), loc), loc)), loc)
adamc@306 1335 val e = (EApp (e, (ERecord fsets, loc)), loc)
adamc@305 1336 val e = (EApp (e, texp), loc)
adamc@303 1337 in
adamc@303 1338 (EApp (e, sqlexp), loc)
adamc@303 1339 end)
adamc@310 1340 | LPAREN enterDml DELETE FROM texp CWHERE sqlexp leaveDml RPAREN
adamc@304 1341 (let
adamc@304 1342 val loc = s (LPARENleft, RPARENright)
adamc@304 1343
adamc@403 1344 val e = (EVar (["Basis"], "delete", Infer), loc)
adamc@304 1345 val e = (EApp (e, texp), loc)
adamc@304 1346 in
adamc@304 1347 (EApp (e, sqlexp), loc)
adamc@304 1348 end)
adamc@302 1349
adamc@211 1350 | UNDER (EWild, s (UNDERleft, UNDERright))
adamc@91 1351
adamc@446 1352 | LET edecls IN eexp END (ELet (edecls, eexp), s (LETleft, ENDright))
adamc@446 1353
adamc@762 1354 | LBRACK RBRACK (EVar (["Basis"], "Nil", Infer), s (LBRACKleft, RBRACKright))
adamc@762 1355
adamc@446 1356 edecls : ([])
adamc@446 1357 | edecl edecls (edecl :: edecls)
adamc@446 1358
adamc@825 1359 edecl : VAL pat EQ eexp ((EDVal (pat, eexp), s (VALleft, eexpright)))
adamc@446 1360 | VAL REC valis ((EDValRec valis, s (VALleft, valisright)))
adamc@446 1361 | FUN valis ((EDValRec valis, s (FUNleft, valisright)))
adamc@446 1362
adamc@310 1363 enterDml : (inDml := true)
adamc@310 1364 leaveDml : (inDml := false)
adamc@310 1365
adamc@403 1366 texp : SYMBOL (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
adamc@302 1367 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
adamc@302 1368
adamc@302 1369 fields : fident ([fident])
adamc@302 1370 | fident COMMA fields (fident :: fields)
adamc@302 1371
adamc@302 1372 sqlexps: sqlexp ([sqlexp])
adamc@302 1373 | sqlexp COMMA sqlexps (sqlexp :: sqlexps)
adamc@302 1374
adamc@303 1375 fsets : fident EQ sqlexp ([(fident, sqlexp)])
adamc@303 1376 | fident EQ sqlexp COMMA fsets ((fident, sqlexp) :: fsets)
adamc@303 1377
adamc@200 1378 idents : ident ([ident])
adamc@200 1379 | ident DOT idents (ident :: idents)
adamc@200 1380
adamc@195 1381 etuple : eexp COMMA eexp ([eexp1, eexp2])
adamc@195 1382 | eexp COMMA etuple (eexp :: etuple)
adamc@195 1383
adamc@170 1384 branch : pat DARROW eexp (pat, eexp)
adamc@170 1385
adamc@170 1386 branchs: ([])
adamc@170 1387 | BAR branch branchs (branch :: branchs)
adamc@170 1388
adamc@822 1389 patS : pterm (pterm)
adamc@822 1390 | pterm DCOLON patS (let
adamc@822 1391 val loc = s (ptermleft, patSright)
adamc@762 1392 in
adamc@762 1393 (PCon (["Basis"], "Cons", SOME (PRecord ([("1", pterm),
adamc@822 1394 ("2", patS)], false), loc)),
adamc@762 1395 loc)
adamc@762 1396 end)
adamc@822 1397 | patS COLON cexp (PAnnot (patS, cexp), s (patSleft, cexpright))
adamc@822 1398
adamc@822 1399 pat : patS (patS)
adamc@822 1400 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
adamc@170 1401
adamc@170 1402 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
adamc@170 1403 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
adamc@170 1404 | UNDER (PWild, s (UNDERleft, UNDERright))
adamc@173 1405 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
adam@1420 1406 | MINUS INT (PPrim (Prim.Int (~INT)), s (MINUSleft, INTright))
adamc@173 1407 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@821 1408 | CHAR (PPrim (Prim.Char CHAR), s (CHARleft, CHARright))
adamc@170 1409 | LPAREN pat RPAREN (pat)
adamc@174 1410 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
adamc@174 1411 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
adamc@174 1412 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
adamc@195 1413 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
adamc@195 1414 false),
adamc@195 1415 s (LPARENleft, RPARENright))
adamc@762 1416 | LBRACK RBRACK (PCon (["Basis"], "Nil", NONE), s (LBRACKleft, RBRACKright))
adamc@174 1417
adamc@175 1418 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
adamc@243 1419 | INT EQ pat ([(Int64.toString INT, pat)], false)
adamc@174 1420 | DOTDOTDOT ([], true)
adamc@175 1421 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
adamc@243 1422 | INT EQ pat COMMA rpat ((Int64.toString INT, pat) :: #1 rpat, #2 rpat)
adamc@170 1423
adamc@195 1424 ptuple : pat COMMA pat ([pat1, pat2])
adamc@195 1425 | pat COMMA ptuple (pat :: ptuple)
adamc@195 1426
adamc@12 1427 rexp : ([])
adamc@12 1428 | ident EQ eexp ([(ident, eexp)])
adamc@12 1429 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
adamc@91 1430
adamc@141 1431 xml : xmlOne xml (let
adamc@141 1432 val pos = s (xmlOneleft, xmlright)
adamc@141 1433 in
adamc@720 1434 (EApp ((EApp (
adamc@720 1435 (EVar (["Basis"], "join", Infer), pos),
adamc@720 1436 xmlOne), pos),
adamc@720 1437 xml), pos)
adamc@141 1438 end)
adamc@141 1439 | xmlOne (xmlOne)
adamc@91 1440
adamc@1045 1441 xmlOpt : xml (xml)
adamc@1045 1442 | (EApp ((EVar (["Basis"], "cdata", Infer), dummy),
adamc@1045 1443 (EPrim (Prim.String ""), dummy)),
adamc@1045 1444 dummy)
adamc@1045 1445
adamc@403 1446 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata", Infer), s (NOTAGSleft, NOTAGSright)),
adamc@141 1447 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
adamc@141 1448 s (NOTAGSleft, NOTAGSright))
adamc@141 1449 | tag DIVIDE GT (let
adamc@141 1450 val pos = s (tagleft, GTright)
adamc@710 1451
adamc@710 1452 val cdata =
adamc@756 1453 if #1 (#1 tag) = "submit" orelse #1 (#1 tag) = "dyn" then
adamc@710 1454 let
adamc@710 1455 val e = (EVar (["Basis"], "cdata", DontInfer), pos)
adamc@710 1456 val e = (ECApp (e, (CWild (KWild, pos), pos)), pos)
adamc@710 1457 in
adamc@710 1458 (ECApp (e, (CRecord [], pos)), pos)
adamc@710 1459 end
adamc@710 1460 else
adamc@710 1461 (EVar (["Basis"], "cdata", Infer), pos)
adamc@710 1462
adamc@710 1463 val cdata = (EApp (cdata,
adamc@710 1464 (EPrim (Prim.String ""), pos)),
adamc@710 1465 pos)
adamc@141 1466 in
adam@1643 1467 (EApp (#4 tag, cdata), pos)
adamc@141 1468 end)
adamc@141 1469
adamc@1045 1470 | tag GT xmlOpt END_TAG (let
adam@1563 1471 fun tagOut s =
adam@1563 1472 case s of
adam@1563 1473 "tabl" => "table"
adam@1563 1474 | _ => s
adam@1563 1475
adamc@141 1476 val pos = s (tagleft, GTright)
adamc@325 1477 val et = tagIn END_TAG
adamc@141 1478 in
adamc@756 1479 if #1 (#1 tag) = et then
adamc@361 1480 if et = "form" then
adam@1412 1481 let
adam@1412 1482 val e = (EVar (["Basis"], "form", Infer), pos)
adam@1412 1483 val e = (EApp (e, case #2 tag of
adam@1412 1484 NONE => (EVar (["Basis"], "None", Infer), pos)
adam@1412 1485 | SOME c => (EApp ((EVar (["Basis"], "Some", Infer), pos), c), pos)), pos)
adam@1412 1486 in
adam@1651 1487 case #3 tag of
adam@1651 1488 NONE => ()
adam@1651 1489 | SOME _ => ErrorMsg.errorAt pos "<form> does not support 'dynClass' attribute";
adam@1412 1490 (EApp (e, xmlOpt), pos)
adam@1412 1491 end
adamc@1093 1492 else if et = "subform" orelse et = "subforms" then
adamc@1093 1493 (EApp (#2 (#1 tag),
adamc@1045 1494 xmlOpt), pos)
adamc@758 1495 else if et = "entry" then
adamc@758 1496 (EApp ((EVar (["Basis"], "entry", Infer), pos),
adamc@1045 1497 xmlOpt), pos)
adamc@141 1498 else
adam@1643 1499 (EApp (#4 tag, xmlOpt), pos)
adamc@141 1500 else
adamc@325 1501 (if ErrorMsg.anyErrors () then
adamc@325 1502 ()
adamc@325 1503 else
adamc@1189 1504 ErrorMsg.errorAt pos ("Begin tag <"
adam@1563 1505 ^ tagOut (#1 (#1 tag))
adamc@1189 1506 ^ "> and end tag </"
adam@1563 1507 ^ tagOut et
adamc@1189 1508 ^ "> don't match.");
adamc@623 1509 (EWild, pos))
adamc@141 1510 end)
adamc@141 1511 | LBRACE eexp RBRACE (eexp)
adamc@391 1512 | LBRACE LBRACK eexp RBRACK RBRACE (let
adamc@391 1513 val loc = s (LBRACEleft, RBRACEright)
adamc@403 1514 val e = (EVar (["Top"], "txt", Infer), loc)
adamc@391 1515 in
adamc@391 1516 (EApp (e, eexp), loc)
adamc@391 1517 end)
adamc@92 1518
adamc@141 1519 tag : tagHead attrs (let
adamc@141 1520 val pos = s (tagHeadleft, attrsright)
adamc@721 1521
adamc@721 1522 val e = (EVar (["Basis"], "tag", Infer), pos)
adamc@721 1523 val eo = case #1 attrs of
adamc@721 1524 NONE => (EVar (["Basis"], "None", Infer), pos)
adamc@721 1525 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos),
adamc@721 1526 e), pos)
adamc@721 1527 val e = (EApp (e, eo), pos)
adam@1643 1528 val eo = case #2 attrs of
adam@1643 1529 NONE => (EVar (["Basis"], "None", Infer), pos)
adam@1643 1530 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos),
adam@1643 1531 e), pos)
adam@1643 1532 val e = (EApp (e, eo), pos)
adam@1643 1533 val e = (EApp (e, (ERecord (#3 attrs), pos)), pos)
adamc@721 1534 val e = (EApp (e, (EApp (#2 tagHead,
adamc@721 1535 (ERecord [], pos)), pos)), pos)
adamc@141 1536 in
adam@1643 1537 (tagHead, #1 attrs, #2 attrs, e)
adamc@141 1538 end)
adamc@141 1539
adamc@141 1540 tagHead: BEGIN_TAG (let
adamc@325 1541 val bt = tagIn BEGIN_TAG
adamc@141 1542 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
adamc@141 1543 in
adamc@325 1544 (bt,
adamc@473 1545 (EVar (["Basis"], bt, Infer), pos))
adamc@141 1546 end)
adamc@141 1547 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
adamc@92 1548
adam@1643 1549 attrs : (NONE, NONE, [])
adamc@721 1550 | attr attrs (let
adamc@721 1551 val loc = s (attrleft, attrsright)
adamc@721 1552 in
adamc@721 1553 case attr of
adamc@721 1554 Class e =>
adamc@721 1555 (case #1 attrs of
adamc@721 1556 NONE => ()
adamc@721 1557 | SOME _ => ErrorMsg.errorAt loc "Multiple classes specified for tag";
adam@1643 1558 (SOME e, #2 attrs, #3 attrs))
adam@1643 1559 | DynClass e =>
adam@1643 1560 (case #2 attrs of
adam@1643 1561 NONE => ()
adam@1643 1562 | SOME _ => ErrorMsg.errorAt loc "Multiple dynamic classes specified for tag";
adam@1643 1563 (#1 attrs, SOME e, #3 attrs))
adamc@721 1564 | Normal xe =>
adam@1643 1565 (#1 attrs, #2 attrs, xe :: #3 attrs)
adamc@721 1566 end)
adamc@104 1567
adam@1643 1568 attr : SYMBOL EQ attrv (case SYMBOL of
adam@1643 1569 "class" => Class attrv
adam@1643 1570 | "dynClass" => DynClass attrv
adam@1643 1571 | _ =>
adamc@724 1572 let
adamc@724 1573 val sym =
adamc@724 1574 case SYMBOL of
adamc@724 1575 "type" => "Typ"
adamc@724 1576 | x => capitalize x
adamc@724 1577 in
adamc@724 1578 Normal ((CName sym, s (SYMBOLleft, SYMBOLright)),
adamc@724 1579 if (sym = "Href" orelse sym = "Src")
adamc@724 1580 andalso (case #1 attrv of
adamc@724 1581 EPrim _ => true
adamc@724 1582 | _ => false) then
adamc@724 1583 let
adamc@724 1584 val loc = s (attrvleft, attrvright)
adamc@724 1585 in
adamc@724 1586 (EApp ((EVar (["Basis"], "bless", Infer), loc),
adamc@724 1587 attrv), loc)
adamc@724 1588 end
adamc@724 1589 else
adamc@724 1590 attrv)
adamc@724 1591 end)
adamc@204 1592
adamc@104 1593 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@104 1594 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@104 1595 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@110 1596 | LBRACE eexp RBRACE (eexp)
adamc@226 1597
adamc@232 1598 query : query1 obopt lopt ofopt (let
adamc@229 1599 val loc = s (query1left, query1right)
adamc@230 1600
adamc@230 1601 val re = (ERecord [((CName "Rows", loc),
adamc@230 1602 query1),
adamc@230 1603 ((CName "OrderBy", loc),
adamc@231 1604 obopt),
adamc@231 1605 ((CName "Limit", loc),
adamc@232 1606 lopt),
adamc@232 1607 ((CName "Offset", loc),
adamc@232 1608 ofopt)], loc)
adamc@229 1609 in
adamc@403 1610 (EApp ((EVar (["Basis"], "sql_query", Infer), loc), re), loc)
adamc@229 1611 end)
adamc@993 1612
adamc@993 1613 dopt : (EVar (["Basis"], "False", Infer), dummy)
adamc@993 1614 | DISTINCT (EVar (["Basis"], "True", Infer),
adamc@993 1615 s (DISTINCTleft, DISTINCTright))
adamc@993 1616
adamc@993 1617 query1 : SELECT dopt select FROM tables wopt gopt hopt
adamc@209 1618 (let
adamc@204 1619 val loc = s (SELECTleft, tablesright)
adamc@207 1620
adamc@1070 1621 val (empties, sel, exps) =
adamc@207 1622 case select of
adamc@1070 1623 Star => ([],
adamc@1070 1624 map (fn nm =>
adamc@233 1625 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
adamc@233 1626 loc),
adamc@233 1627 (CRecord [], loc)],
adamc@748 1628 loc))) (#1 tables),
adamc@233 1629 [])
adamc@207 1630 | Items sis =>
adamc@207 1631 let
adam@1627 1632 val tabs = map (fn nm => (nm, Unknown)) (#1 tables)
adamc@1194 1633 val (_, tabs, exps) = foldl (amend_select loc)
adamc@1194 1634 (1, tabs, []) sis
adam@1627 1635 val empties = List.mapPartial (fn (nm, c) =>
adam@1627 1636 case c of
adam@1627 1637 Unknown => SOME nm
adam@1627 1638 | Selective (CRecord [], _) => SOME nm
adam@1627 1639 | _ => NONE) tabs
adamc@207 1640 in
adamc@1070 1641 (empties,
adamc@1070 1642 map (fn (nm, c) => (nm,
adam@1627 1643 case c of
adam@1627 1644 Everything =>
adam@1627 1645 (CTuple [(CWild (KRecord (KType, loc), loc), loc),
adam@1627 1646 (CRecord [], loc)], loc)
adam@1627 1647 | _ =>
adam@1627 1648 let
adam@1627 1649 val c = case c of
adam@1627 1650 Selective c => c
adam@1627 1651 | _ => (CRecord [], loc)
adam@1627 1652 in
adam@1627 1653 (CTuple [c,
adam@1627 1654 (CWild (KRecord (KType, loc), loc),
adam@1627 1655 loc)], loc)
adam@1627 1656 end)) tabs,
adamc@233 1657 exps)
adamc@207 1658 end
adamc@207 1659
adamc@207 1660 val sel = (CRecord sel, loc)
adamc@207 1661
adamc@226 1662 val grp = case gopt of
adamc@403 1663 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all",
adamc@403 1664 Infer), loc),
adamc@226 1665 (CWild (KRecord (KRecord (KType, loc), loc),
adamc@226 1666 loc), loc)), loc)
adamc@226 1667 | SOME gis =>
adamc@226 1668 let
adamc@748 1669 val tabs = map (fn nm =>
adamc@748 1670 (nm, (CRecord [], loc))) (#1 tables)
adamc@226 1671 val tabs = foldl (amend_group loc) tabs gis
adamc@226 1672
adamc@226 1673 val tabs = map (fn (nm, c) =>
adamc@226 1674 (nm,
adamc@226 1675 (CTuple [c,
adamc@226 1676 (CWild (KRecord (KType, loc),
adamc@226 1677 loc),
adamc@226 1678 loc)], loc))) tabs
adamc@226 1679 in
adamc@403 1680 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@226 1681 (CRecord tabs, loc)), loc)
adamc@226 1682 end
adamc@226 1683
adamc@403 1684 val e = (EVar (["Basis"], "sql_query1", Infer), loc)
adamc@1070 1685 val e = (ECApp (e, (CRecord (map (fn nm => (nm, (CUnit, loc))) empties),
adamc@1070 1686 loc)), loc)
adamc@993 1687 val re = (ERecord [((CName "Distinct", loc),
adamc@993 1688 dopt),
adamc@993 1689 ((CName "From", loc),
adamc@748 1690 #2 tables),
adamc@209 1691 ((CName "Where", loc),
adamc@223 1692 wopt),
adamc@224 1693 ((CName "GroupBy", loc),
adamc@226 1694 grp),
adamc@224 1695 ((CName "Having", loc),
adamc@224 1696 hopt),
adamc@223 1697 ((CName "SelectFields", loc),
adamc@403 1698 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@233 1699 sel), loc)),
adamc@233 1700 ((CName "SelectExps", loc),
adamc@233 1701 (ERecord exps, loc))], loc)
adamc@223 1702
adamc@209 1703 val e = (EApp (e, re), loc)
adamc@204 1704 in
adamc@207 1705 e
adamc@204 1706 end)
adam@1427 1707 | query1 UNION query1 (sql_relop ("union", false, query11, query12, s (query11left, query12right)))
adam@1427 1708 | query1 INTERSECT query1 (sql_relop ("intersect", false, query11, query12, s (query11left, query12right)))
adam@1427 1709 | query1 EXCEPT query1 (sql_relop ("except", false, query11, query12, s (query11left, query12right)))
adam@1427 1710 | query1 UNION ALL query1 (sql_relop ("union", true, query11, query12, s (query11left, query12right)))
adam@1427 1711 | query1 INTERSECT ALL query1 (sql_relop ("intersect", true, query11, query12, s (query11left, query12right)))
adam@1427 1712 | query1 EXCEPT ALL query1 (sql_relop ("except", true, query11, query12, s (query11left, query12right)))
adamc@1070 1713 | LBRACE LBRACE LBRACE eexp RBRACE RBRACE RBRACE (eexp)
adamc@204 1714
adamc@749 1715 tables : fitem (fitem)
adamc@749 1716 | fitem COMMA tables (let
adamc@749 1717 val loc = s (fitemleft, tablesright)
adamc@748 1718
adamc@748 1719 val e = (EVar (["Basis"], "sql_from_comma", Infer), loc)
adamc@749 1720 val e = (EApp (e, #2 fitem), loc)
adamc@748 1721 in
adamc@749 1722 (#1 fitem @ #1 tables,
adamc@748 1723 (EApp (e, #2 tables), loc))
adamc@748 1724 end)
adamc@204 1725
adamc@749 1726 fitem : table' ([#1 table'], #2 table')
adamc@1265 1727 | LBRACE LBRACE eexp RBRACE RBRACE (tnamesOf eexp, eexp)
adamc@749 1728 | fitem JOIN fitem ON sqlexp (let
adamc@749 1729 val loc = s (fitem1left, sqlexpright)
adamc@749 1730
adamc@749 1731 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1732 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1733 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1734 in
adamc@749 1735 (#1 fitem1 @ #1 fitem2,
adamc@749 1736 (EApp (e, sqlexp), loc))
adamc@749 1737 end)
adamc@749 1738 | fitem INNER JOIN fitem ON sqlexp (let
adamc@749 1739 val loc = s (fitem1left, sqlexpright)
adamc@749 1740
adamc@749 1741 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1742 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1743 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1744 in
adamc@749 1745 (#1 fitem1 @ #1 fitem2,
adamc@749 1746 (EApp (e, sqlexp), loc))
adamc@749 1747 end)
adamc@749 1748 | fitem CROSS JOIN fitem (let
adamc@749 1749 val loc = s (fitem1left, fitem2right)
adamc@749 1750
adamc@749 1751 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1752 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1753 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1754 val tru = sql_inject (EVar (["Basis"], "True", Infer), loc)
adamc@749 1755 in
adamc@749 1756 (#1 fitem1 @ #1 fitem2,
adamc@749 1757 (EApp (e, tru), loc))
adamc@749 1758 end)
adamc@750 1759 | fitem LEFT JOIN fitem ON sqlexp (let
adamc@750 1760 val loc = s (fitem1left, sqlexpright)
adamc@750 1761
adamc@750 1762 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
adamc@750 1763 val e = (EApp (e, #2 fitem1), loc)
adamc@750 1764 val e = (EApp (e, #2 fitem2), loc)
adamc@750 1765 in
adamc@750 1766 (#1 fitem1 @ #1 fitem2,
adamc@750 1767 (EApp (e, sqlexp), loc))
adamc@750 1768 end)
adamc@751 1769 | fitem LEFT OUTER JOIN fitem ON sqlexp (let
adamc@751 1770 val loc = s (fitem1left, sqlexpright)
adamc@751 1771
adamc@751 1772 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
adamc@751 1773 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1774 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1775 in
adamc@751 1776 (#1 fitem1 @ #1 fitem2,
adamc@751 1777 (EApp (e, sqlexp), loc))
adamc@751 1778 end)
adamc@751 1779 | fitem RIGHT JOIN fitem ON sqlexp (let
adamc@751 1780 val loc = s (fitem1left, sqlexpright)
adamc@751 1781
adamc@751 1782 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
adamc@751 1783 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1784 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1785 in
adamc@751 1786 (#1 fitem1 @ #1 fitem2,
adamc@751 1787 (EApp (e, sqlexp), loc))
adamc@751 1788 end)
adamc@751 1789 | fitem RIGHT OUTER JOIN fitem ON sqlexp (let
adamc@751 1790 val loc = s (fitem1left, sqlexpright)
adamc@751 1791
adamc@751 1792 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
adamc@751 1793 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1794 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1795 in
adamc@751 1796 (#1 fitem1 @ #1 fitem2,
adamc@751 1797 (EApp (e, sqlexp), loc))
adamc@751 1798 end)
adamc@751 1799 | fitem FULL JOIN fitem ON sqlexp (let
adamc@751 1800 val loc = s (fitem1left, sqlexpright)
adamc@751 1801
adamc@751 1802 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
adamc@751 1803 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1804 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1805 in
adamc@751 1806 (#1 fitem1 @ #1 fitem2,
adamc@751 1807 (EApp (e, sqlexp), loc))
adamc@751 1808 end)
adamc@751 1809 | fitem FULL OUTER JOIN fitem ON sqlexp (let
adamc@751 1810 val loc = s (fitem1left, sqlexpright)
adamc@751 1811
adamc@751 1812 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
adamc@751 1813 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1814 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1815 in
adamc@751 1816 (#1 fitem1 @ #1 fitem2,
adamc@751 1817 (EApp (e, sqlexp), loc))
adamc@751 1818 end)
adamc@1192 1819 | LPAREN query RPAREN AS tname (let
adamc@1192 1820 val loc = s (LPARENleft, RPARENright)
adamc@1192 1821
adamc@1192 1822 val e = (EVar (["Basis"], "sql_from_query", Infer), loc)
adamc@1192 1823 val e = (ECApp (e, tname), loc)
adamc@1192 1824 in
adamc@1192 1825 ([tname], (EApp (e, query), loc))
adamc@1192 1826 end)
adamc@749 1827
adamc@204 1828 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@204 1829 | LBRACE cexp RBRACE (cexp)
adamc@204 1830
adamc@243 1831 table : SYMBOL ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)),
adamc@403 1832 (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@403 1833 | SYMBOL AS tname (tname, (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@221 1834 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
adamc@207 1835
adamc@748 1836 table' : table (let
adamc@748 1837 val loc = s (tableleft, tableright)
adamc@748 1838 val e = (EVar (["Basis"], "sql_from_table", Infer), loc)
adamc@748 1839 val e = (ECApp (e, #1 table), loc)
adamc@748 1840 in
adamc@748 1841 (#1 table, (EApp (e, #2 table), loc))
adamc@748 1842 end)
adamc@748 1843
adamc@243 1844 tident : SYMBOL (CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@207 1845 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@221 1846 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
adamc@207 1847
adamc@207 1848 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@207 1849 | LBRACE cexp RBRACE (cexp)
adamc@207 1850
adamc@207 1851 seli : tident DOT fident (Field (tident, fident))
adamc@1194 1852 | sqlexp (Exp (NONE, sqlexp))
adamc@1194 1853 | sqlexp AS fident (Exp (SOME fident, sqlexp))
adamc@341 1854 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (Fields (tident, cexp))
adam@1627 1855 | tident DOT STAR (StarFields tident)
adamc@207 1856
adamc@207 1857 selis : seli ([seli])
adamc@207 1858 | seli COMMA selis (seli :: selis)
adamc@207 1859
adamc@207 1860 select : STAR (Star)
adamc@207 1861 | selis (Items selis)
adamc@209 1862
adamc@403 1863 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", Infer),
adamc@209 1864 s (TRUEleft, TRUEright)))
adamc@403 1865 | FALSE (sql_inject (EVar (["Basis"], "False", Infer),
adamc@209 1866 s (FALSEleft, FALSEright)))
adamc@209 1867
adamc@222 1868 | INT (sql_inject (EPrim (Prim.Int INT),
adamc@222 1869 s (INTleft, INTright)))
adamc@222 1870 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
adamc@222 1871 s (FLOATleft, FLOATright)))
adamc@229 1872 | STRING (sql_inject (EPrim (Prim.String STRING),
adamc@229 1873 s (STRINGleft, STRINGright)))
adamc@441 1874 | CURRENT_TIMESTAMP (sql_nfunc ("current_timestamp",
adamc@441 1875 s (CURRENT_TIMESTAMPleft, CURRENT_TIMESTAMPright)))
adamc@222 1876
adamc@221 1877 | tident DOT fident (let
adamc@221 1878 val loc = s (tidentleft, fidentright)
adamc@403 1879 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@221 1880 val e = (ECApp (e, tident), loc)
adamc@221 1881 in
adamc@221 1882 (ECApp (e, fident), loc)
adamc@221 1883 end)
adamc@234 1884 | CSYMBOL (let
adamc@234 1885 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@310 1886 in
adamc@310 1887 if !inDml then
adamc@310 1888 let
adamc@403 1889 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@310 1890 val e = (ECApp (e, (CName "T", loc)), loc)
adamc@310 1891 in
adamc@310 1892 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1893 end
adamc@310 1894 else
adamc@310 1895 let
adamc@403 1896 val e = (EVar (["Basis"], "sql_exp", Infer), loc)
adamc@310 1897 in
adamc@310 1898 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1899 end
adamc@310 1900 end)
adamc@221 1901
adamc@471 1902 | LBRACE eexp RBRACE (eexp)
adamc@470 1903
adamc@559 1904 | sqlexp EQ sqlexp (sql_binary ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1905 | sqlexp NE sqlexp (sql_binary ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1906 | sqlexp LT sqlexp (sql_binary ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1907 | sqlexp LE sqlexp (sql_binary ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1908 | sqlexp GT sqlexp (sql_binary ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1909 | sqlexp GE sqlexp (sql_binary ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1910
adamc@559 1911 | sqlexp PLUS sqlexp (sql_binary ("plus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1912 | sqlexp MINUS sqlexp (sql_binary ("minus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1913 | sqlexp STAR sqlexp (sql_binary ("times", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1914 | sqlexp DIVIDE sqlexp (sql_binary ("div", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1915 | sqlexp MOD sqlexp (sql_binary ("mod", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1916
adamc@220 1917 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@220 1918 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1919
kkallio@1607 1920 | sqlexp LIKE sqlexp (sql_binary ("like", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
kkallio@1607 1921
adamc@220 1922 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
adamc@559 1923 | MINUS sqlexp (sql_unary ("neg", sqlexp, s (MINUSleft, sqlexpright)))
adamc@220 1924
adamc@470 1925 | sqlexp IS NULL (let
adamc@470 1926 val loc = s (sqlexpleft, NULLright)
adamc@470 1927 in
adamc@470 1928 (EApp ((EVar (["Basis"], "sql_is_null", Infer), loc),
adamc@470 1929 sqlexp), loc)
adamc@470 1930 end)
adamc@470 1931
kkallio@1572 1932 | CIF sqlexp CTHEN sqlexp CELSE sqlexp (let
kkallio@1572 1933 val loc = s (CIFleft, sqlexp3right)
kkallio@1572 1934 val e = (EVar (["Basis"], "sql_if_then_else", Infer), loc)
kkallio@1572 1935 in
kkallio@1572 1936 (EApp ((EApp ((EApp (e, sqlexp1), loc), sqlexp2), loc), sqlexp3), loc)
kkallio@1572 1937 end)
kkallio@1572 1938
adamc@471 1939 | LBRACE LBRACK eexp RBRACK RBRACE (sql_inject (#1 eexp,
adamc@471 1940 s (LBRACEleft, RBRACEright)))
adamc@220 1941 | LPAREN sqlexp RPAREN (sqlexp)
adamc@210 1942
adamc@467 1943 | NULL (sql_inject ((EVar (["Basis"], "None", Infer),
adamc@467 1944 s (NULLleft, NULLright))))
adamc@467 1945
adamc@235 1946 | COUNT LPAREN STAR RPAREN (let
adamc@235 1947 val loc = s (COUNTleft, RPARENright)
adamc@235 1948 in
adamc@544 1949 (EVar (["Basis"], "sql_count", Infer), loc)
adamc@235 1950 end)
adamc@1187 1951 | COUNT LPAREN sqlexp RPAREN (let
adamc@1187 1952 val loc = s (COUNTleft, RPARENright)
adamc@1187 1953
adamc@1187 1954 val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
adamc@1187 1955 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
adamc@1187 1956 e), loc)
adamc@1187 1957 in
adamc@1187 1958 (EApp (e, sqlexp), loc)
adamc@1187 1959 end)
adamc@236 1960 | sqlagg LPAREN sqlexp RPAREN (let
adamc@236 1961 val loc = s (sqlaggleft, RPARENright)
adamc@236 1962
adamc@403 1963 val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
adamc@403 1964 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
adamc@236 1965 e), loc)
adamc@236 1966 in
adamc@236 1967 (EApp (e, sqlexp), loc)
adamc@236 1968 end)
adam@1602 1969 | COALESCE LPAREN sqlexp COMMA sqlexp RPAREN
adam@1602 1970 (let
adam@1602 1971 val loc = s (COALESCEright, sqlexp2right)
adam@1602 1972 val e = (EVar (["Basis"], "sql_coalesce", Infer), loc)
adam@1602 1973 val e = (EApp (e, sqlexp1), loc)
adam@1602 1974 in
adam@1602 1975 (EApp (e, sqlexp2), loc)
adam@1602 1976 end)
adamc@746 1977 | fname LPAREN sqlexp RPAREN (let
adamc@746 1978 val loc = s (fnameleft, RPARENright)
adamc@746 1979
adamc@746 1980 val e = (EVar (["Basis"], "sql_ufunc", Infer), loc)
adamc@746 1981 val e = (EApp (e, fname), loc)
adamc@746 1982 in
adamc@746 1983 (EApp (e, sqlexp), loc)
adamc@746 1984 end)
adamc@1191 1985 | LPAREN query RPAREN (let
adamc@1191 1986 val loc = s (LPARENleft, RPARENright)
adamc@1191 1987
adamc@1191 1988 val e = (EVar (["Basis"], "sql_subquery", Infer), loc)
adamc@1191 1989 in
adamc@1191 1990 (EApp (e, query), loc)
adamc@1191 1991 end)
adamc@746 1992
adamc@746 1993 fname : SYMBOL (EVar (["Basis"], "sql_" ^ SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
adamc@746 1994 | LBRACE eexp RBRACE (eexp)
adamc@235 1995
adamc@403 1996 wopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 1997 dummy))
adamc@209 1998 | CWHERE sqlexp (sqlexp)
adamc@226 1999
adamc@226 2000 groupi : tident DOT fident (GField (tident, fident))
adam@1425 2001 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (GFields (tident, cexp))
adamc@226 2002
adamc@226 2003 groupis: groupi ([groupi])
adamc@226 2004 | groupi COMMA groupis (groupi :: groupis)
adamc@226 2005
adamc@226 2006 gopt : (NONE)
adamc@226 2007 | GROUP BY groupis (SOME groupis)
adamc@227 2008
adamc@403 2009 hopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 2010 dummy))
adamc@227 2011 | HAVING sqlexp (sqlexp)
adamc@230 2012
adamc@403 2013 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
adamc@234 2014 (CWild (KRecord (KType, dummy), dummy), dummy)),
adamc@230 2015 dummy)
adamc@230 2016 | ORDER BY obexps (obexps)
adamc@230 2017
adamc@268 2018 obitem : sqlexp diropt (sqlexp, diropt)
adamc@268 2019
adamc@268 2020 obexps : obitem (let
adamc@268 2021 val loc = s (obitemleft, obitemright)
adamc@230 2022
adamc@403 2023 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), loc),
adamc@234 2024 (CWild (KRecord (KType, loc), loc), loc)),
adamc@230 2025 loc)
adamc@403 2026 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 2027 #1 obitem), loc)
adamc@268 2028 val e = (EApp (e, #2 obitem), loc)
adamc@230 2029 in
adamc@230 2030 (EApp (e, e'), loc)
adamc@230 2031 end)
adamc@268 2032 | obitem COMMA obexps (let
adamc@268 2033 val loc = s (obitemleft, obexpsright)
adamc@230 2034
adamc@403 2035 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 2036 #1 obitem), loc)
adamc@268 2037 val e = (EApp (e, #2 obitem), loc)
adamc@230 2038 in
adamc@230 2039 (EApp (e, obexps), loc)
adamc@230 2040 end)
adam@1682 2041 | RANDOM popt (EVar (["Basis"], "sql_order_by_random", Infer), s (RANDOMleft, poptright))
adam@1682 2042
adam@1682 2043 popt : ()
adam@1682 2044 | LPAREN RPAREN ()
adam@1684 2045 | UNIT ()
adamc@231 2046
adamc@403 2047 diropt : (EVar (["Basis"], "sql_asc", Infer), dummy)
adamc@403 2048 | ASC (EVar (["Basis"], "sql_asc", Infer), s (ASCleft, ASCright))
adamc@403 2049 | DESC (EVar (["Basis"], "sql_desc", Infer), s (DESCleft, DESCright))
adam@1543 2050 | LBRACE eexp RBRACE (eexp)
adamc@268 2051
adamc@403 2052 lopt : (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@403 2053 | LIMIT ALL (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@231 2054 | LIMIT sqlint (let
adamc@231 2055 val loc = s (LIMITleft, sqlintright)
adamc@231 2056 in
adamc@403 2057 (EApp ((EVar (["Basis"], "sql_limit", Infer), loc), sqlint), loc)
adamc@231 2058 end)
adamc@231 2059
adamc@403 2060 ofopt : (EVar (["Basis"], "sql_no_offset", Infer), dummy)
adamc@232 2061 | OFFSET sqlint (let
adamc@232 2062 val loc = s (OFFSETleft, sqlintright)
adamc@232 2063 in
adamc@403 2064 (EApp ((EVar (["Basis"], "sql_offset", Infer), loc), sqlint), loc)
adamc@232 2065 end)
adamc@232 2066
adamc@231 2067 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@231 2068 | LBRACE eexp RBRACE (eexp)
adamc@236 2069
adamc@236 2070 sqlagg : AVG ("avg")
adamc@236 2071 | SUM ("sum")
adamc@236 2072 | MIN ("min")
adamc@236 2073 | MAX ("max")