annotate src/urweb.grm @ 1774:27fdd78bd2f5

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