annotate src/urweb.grm @ 1421:3dab4696d116

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