annotate src/urweb.grm @ 1749:f9e5a8e09cdf

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