annotate src/urweb.grm @ 1416:a8606c1cfe87

Fix monoization of sql_relop (grandfathered into release!)
author Adam Chlipala <adam@chlipala.net>
date Sun, 23 Jan 2011 15:49:35 -0500
parents 5f4fee8a4dcd
children 146b69c53304
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))
adamc@173 1326 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@821 1327 | CHAR (PPrim (Prim.Char CHAR), s (CHARleft, CHARright))
adamc@170 1328 | LPAREN pat RPAREN (pat)
adamc@174 1329 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
adamc@174 1330 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
adamc@174 1331 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
adamc@195 1332 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
adamc@195 1333 false),
adamc@195 1334 s (LPARENleft, RPARENright))
adamc@762 1335 | LBRACK RBRACK (PCon (["Basis"], "Nil", NONE), s (LBRACKleft, RBRACKright))
adamc@174 1336
adamc@175 1337 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
adamc@243 1338 | INT EQ pat ([(Int64.toString INT, pat)], false)
adamc@174 1339 | DOTDOTDOT ([], true)
adamc@175 1340 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
adamc@243 1341 | INT EQ pat COMMA rpat ((Int64.toString INT, pat) :: #1 rpat, #2 rpat)
adamc@170 1342
adamc@195 1343 ptuple : pat COMMA pat ([pat1, pat2])
adamc@195 1344 | pat COMMA ptuple (pat :: ptuple)
adamc@195 1345
adamc@12 1346 rexp : ([])
adamc@12 1347 | ident EQ eexp ([(ident, eexp)])
adamc@12 1348 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
adamc@91 1349
adamc@141 1350 xml : xmlOne xml (let
adamc@141 1351 val pos = s (xmlOneleft, xmlright)
adamc@141 1352 in
adamc@720 1353 (EApp ((EApp (
adamc@720 1354 (EVar (["Basis"], "join", Infer), pos),
adamc@720 1355 xmlOne), pos),
adamc@720 1356 xml), pos)
adamc@141 1357 end)
adamc@141 1358 | xmlOne (xmlOne)
adamc@91 1359
adamc@1045 1360 xmlOpt : xml (xml)
adamc@1045 1361 | (EApp ((EVar (["Basis"], "cdata", Infer), dummy),
adamc@1045 1362 (EPrim (Prim.String ""), dummy)),
adamc@1045 1363 dummy)
adamc@1045 1364
adamc@403 1365 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata", Infer), s (NOTAGSleft, NOTAGSright)),
adamc@141 1366 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
adamc@141 1367 s (NOTAGSleft, NOTAGSright))
adamc@141 1368 | tag DIVIDE GT (let
adamc@141 1369 val pos = s (tagleft, GTright)
adamc@710 1370
adamc@710 1371 val cdata =
adamc@756 1372 if #1 (#1 tag) = "submit" orelse #1 (#1 tag) = "dyn" then
adamc@710 1373 let
adamc@710 1374 val e = (EVar (["Basis"], "cdata", DontInfer), pos)
adamc@710 1375 val e = (ECApp (e, (CWild (KWild, pos), pos)), pos)
adamc@710 1376 in
adamc@710 1377 (ECApp (e, (CRecord [], pos)), pos)
adamc@710 1378 end
adamc@710 1379 else
adamc@710 1380 (EVar (["Basis"], "cdata", Infer), pos)
adamc@710 1381
adamc@710 1382 val cdata = (EApp (cdata,
adamc@710 1383 (EPrim (Prim.String ""), pos)),
adamc@710 1384 pos)
adamc@141 1385 in
adam@1412 1386 (EApp (#3 tag, cdata), pos)
adamc@141 1387 end)
adamc@141 1388
adamc@1045 1389 | tag GT xmlOpt END_TAG (let
adamc@141 1390 val pos = s (tagleft, GTright)
adamc@325 1391 val et = tagIn END_TAG
adamc@141 1392 in
adamc@756 1393 if #1 (#1 tag) = et then
adamc@361 1394 if et = "form" then
adam@1412 1395 let
adam@1412 1396 val e = (EVar (["Basis"], "form", Infer), pos)
adam@1412 1397 val e = (EApp (e, case #2 tag of
adam@1412 1398 NONE => (EVar (["Basis"], "None", Infer), pos)
adam@1412 1399 | SOME c => (EApp ((EVar (["Basis"], "Some", Infer), pos), c), pos)), pos)
adam@1412 1400 in
adam@1412 1401 (EApp (e, xmlOpt), pos)
adam@1412 1402 end
adamc@1093 1403 else if et = "subform" orelse et = "subforms" then
adamc@1093 1404 (EApp (#2 (#1 tag),
adamc@1045 1405 xmlOpt), pos)
adamc@758 1406 else if et = "entry" then
adamc@758 1407 (EApp ((EVar (["Basis"], "entry", Infer), pos),
adamc@1045 1408 xmlOpt), pos)
adamc@141 1409 else
adam@1412 1410 (EApp (#3 tag, xmlOpt), pos)
adamc@141 1411 else
adamc@325 1412 (if ErrorMsg.anyErrors () then
adamc@325 1413 ()
adamc@325 1414 else
adamc@1189 1415 ErrorMsg.errorAt pos ("Begin tag <"
adamc@1189 1416 ^ #1 (#1 tag)
adamc@1189 1417 ^ "> and end tag </"
adamc@1189 1418 ^ et
adamc@1189 1419 ^ "> don't match.");
adamc@623 1420 (EWild, pos))
adamc@141 1421 end)
adamc@141 1422 | LBRACE eexp RBRACE (eexp)
adamc@391 1423 | LBRACE LBRACK eexp RBRACK RBRACE (let
adamc@391 1424 val loc = s (LBRACEleft, RBRACEright)
adamc@403 1425 val e = (EVar (["Top"], "txt", Infer), loc)
adamc@391 1426 in
adamc@391 1427 (EApp (e, eexp), loc)
adamc@391 1428 end)
adamc@92 1429
adamc@141 1430 tag : tagHead attrs (let
adamc@141 1431 val pos = s (tagHeadleft, attrsright)
adamc@721 1432
adamc@721 1433 val e = (EVar (["Basis"], "tag", Infer), pos)
adamc@721 1434 val eo = case #1 attrs of
adamc@721 1435 NONE => (EVar (["Basis"], "None", Infer), pos)
adamc@721 1436 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos),
adamc@721 1437 e), pos)
adamc@721 1438 val e = (EApp (e, eo), pos)
adamc@721 1439 val e = (EApp (e, (ERecord (#2 attrs), pos)), pos)
adamc@721 1440 val e = (EApp (e, (EApp (#2 tagHead,
adamc@721 1441 (ERecord [], pos)), pos)), pos)
adamc@141 1442 in
adam@1412 1443 (tagHead, #1 attrs, e)
adamc@141 1444 end)
adamc@141 1445
adamc@141 1446 tagHead: BEGIN_TAG (let
adamc@325 1447 val bt = tagIn BEGIN_TAG
adamc@141 1448 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
adamc@141 1449 in
adamc@325 1450 (bt,
adamc@473 1451 (EVar (["Basis"], bt, Infer), pos))
adamc@141 1452 end)
adamc@141 1453 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
adamc@92 1454
adamc@721 1455 attrs : (NONE, [])
adamc@721 1456 | attr attrs (let
adamc@721 1457 val loc = s (attrleft, attrsright)
adamc@721 1458 in
adamc@721 1459 case attr of
adamc@721 1460 Class e =>
adamc@721 1461 (case #1 attrs of
adamc@721 1462 NONE => ()
adamc@721 1463 | SOME _ => ErrorMsg.errorAt loc "Multiple classes specified for tag";
adamc@721 1464 (SOME e, #2 attrs))
adamc@721 1465 | Normal xe =>
adamc@721 1466 (#1 attrs, xe :: #2 attrs)
adamc@721 1467 end)
adamc@104 1468
adamc@721 1469 attr : SYMBOL EQ attrv (if SYMBOL = "class" then
adamc@721 1470 Class attrv
adamc@717 1471 else
adamc@724 1472 let
adamc@724 1473 val sym =
adamc@724 1474 case SYMBOL of
adamc@724 1475 "type" => "Typ"
adamc@724 1476 | x => capitalize x
adamc@724 1477 in
adamc@724 1478 Normal ((CName sym, s (SYMBOLleft, SYMBOLright)),
adamc@724 1479 if (sym = "Href" orelse sym = "Src")
adamc@724 1480 andalso (case #1 attrv of
adamc@724 1481 EPrim _ => true
adamc@724 1482 | _ => false) then
adamc@724 1483 let
adamc@724 1484 val loc = s (attrvleft, attrvright)
adamc@724 1485 in
adamc@724 1486 (EApp ((EVar (["Basis"], "bless", Infer), loc),
adamc@724 1487 attrv), loc)
adamc@724 1488 end
adamc@724 1489 else
adamc@724 1490 attrv)
adamc@724 1491 end)
adamc@204 1492
adamc@104 1493 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@104 1494 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@104 1495 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@110 1496 | LBRACE eexp RBRACE (eexp)
adamc@226 1497
adamc@232 1498 query : query1 obopt lopt ofopt (let
adamc@229 1499 val loc = s (query1left, query1right)
adamc@230 1500
adamc@230 1501 val re = (ERecord [((CName "Rows", loc),
adamc@230 1502 query1),
adamc@230 1503 ((CName "OrderBy", loc),
adamc@231 1504 obopt),
adamc@231 1505 ((CName "Limit", loc),
adamc@232 1506 lopt),
adamc@232 1507 ((CName "Offset", loc),
adamc@232 1508 ofopt)], loc)
adamc@229 1509 in
adamc@403 1510 (EApp ((EVar (["Basis"], "sql_query", Infer), loc), re), loc)
adamc@229 1511 end)
adamc@993 1512
adamc@993 1513 dopt : (EVar (["Basis"], "False", Infer), dummy)
adamc@993 1514 | DISTINCT (EVar (["Basis"], "True", Infer),
adamc@993 1515 s (DISTINCTleft, DISTINCTright))
adamc@993 1516
adamc@993 1517 query1 : SELECT dopt select FROM tables wopt gopt hopt
adamc@209 1518 (let
adamc@204 1519 val loc = s (SELECTleft, tablesright)
adamc@207 1520
adamc@1070 1521 val (empties, sel, exps) =
adamc@207 1522 case select of
adamc@1070 1523 Star => ([],
adamc@1070 1524 map (fn nm =>
adamc@233 1525 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
adamc@233 1526 loc),
adamc@233 1527 (CRecord [], loc)],
adamc@748 1528 loc))) (#1 tables),
adamc@233 1529 [])
adamc@207 1530 | Items sis =>
adamc@207 1531 let
adamc@748 1532 val tabs = map (fn nm => (nm, (CRecord [], loc))) (#1 tables)
adamc@1194 1533 val (_, tabs, exps) = foldl (amend_select loc)
adamc@1194 1534 (1, tabs, []) sis
adamc@1070 1535 val empties = List.mapPartial (fn (nm, (CRecord [], _)) =>
adamc@1070 1536 SOME nm
adamc@1070 1537 | _ => NONE) tabs
adamc@207 1538 in
adamc@1070 1539 (empties,
adamc@1070 1540 map (fn (nm, c) => (nm,
adamc@233 1541 (CTuple [c,
adamc@233 1542 (CWild (KRecord (KType, loc), loc),
adamc@233 1543 loc)], loc))) tabs,
adamc@233 1544 exps)
adamc@207 1545 end
adamc@207 1546
adamc@207 1547 val sel = (CRecord sel, loc)
adamc@207 1548
adamc@226 1549 val grp = case gopt of
adamc@403 1550 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all",
adamc@403 1551 Infer), loc),
adamc@226 1552 (CWild (KRecord (KRecord (KType, loc), loc),
adamc@226 1553 loc), loc)), loc)
adamc@226 1554 | SOME gis =>
adamc@226 1555 let
adamc@748 1556 val tabs = map (fn nm =>
adamc@748 1557 (nm, (CRecord [], loc))) (#1 tables)
adamc@226 1558 val tabs = foldl (amend_group loc) tabs gis
adamc@226 1559
adamc@226 1560 val tabs = map (fn (nm, c) =>
adamc@226 1561 (nm,
adamc@226 1562 (CTuple [c,
adamc@226 1563 (CWild (KRecord (KType, loc),
adamc@226 1564 loc),
adamc@226 1565 loc)], loc))) tabs
adamc@226 1566 in
adamc@403 1567 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@226 1568 (CRecord tabs, loc)), loc)
adamc@226 1569 end
adamc@226 1570
adamc@403 1571 val e = (EVar (["Basis"], "sql_query1", Infer), loc)
adamc@1070 1572 val e = (ECApp (e, (CRecord (map (fn nm => (nm, (CUnit, loc))) empties),
adamc@1070 1573 loc)), loc)
adamc@993 1574 val re = (ERecord [((CName "Distinct", loc),
adamc@993 1575 dopt),
adamc@993 1576 ((CName "From", loc),
adamc@748 1577 #2 tables),
adamc@209 1578 ((CName "Where", loc),
adamc@223 1579 wopt),
adamc@224 1580 ((CName "GroupBy", loc),
adamc@226 1581 grp),
adamc@224 1582 ((CName "Having", loc),
adamc@224 1583 hopt),
adamc@223 1584 ((CName "SelectFields", loc),
adamc@403 1585 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@233 1586 sel), loc)),
adamc@233 1587 ((CName "SelectExps", loc),
adamc@233 1588 (ERecord exps, loc))], loc)
adamc@223 1589
adamc@209 1590 val e = (EApp (e, re), loc)
adamc@204 1591 in
adamc@207 1592 e
adamc@204 1593 end)
adamc@229 1594 | query1 UNION query1 (sql_relop ("union", query11, query12, s (query11left, query12right)))
adamc@229 1595 | query1 INTERSECT query1 (sql_relop ("intersect", query11, query12, s (query11left, query12right)))
adamc@229 1596 | query1 EXCEPT query1 (sql_relop ("except", query11, query12, s (query11left, query12right)))
adamc@1070 1597 | LBRACE LBRACE LBRACE eexp RBRACE RBRACE RBRACE (eexp)
adamc@204 1598
adamc@749 1599 tables : fitem (fitem)
adamc@749 1600 | fitem COMMA tables (let
adamc@749 1601 val loc = s (fitemleft, tablesright)
adamc@748 1602
adamc@748 1603 val e = (EVar (["Basis"], "sql_from_comma", Infer), loc)
adamc@749 1604 val e = (EApp (e, #2 fitem), loc)
adamc@748 1605 in
adamc@749 1606 (#1 fitem @ #1 tables,
adamc@748 1607 (EApp (e, #2 tables), loc))
adamc@748 1608 end)
adamc@204 1609
adamc@749 1610 fitem : table' ([#1 table'], #2 table')
adamc@1265 1611 | LBRACE LBRACE eexp RBRACE RBRACE (tnamesOf eexp, eexp)
adamc@749 1612 | fitem JOIN fitem ON sqlexp (let
adamc@749 1613 val loc = s (fitem1left, sqlexpright)
adamc@749 1614
adamc@749 1615 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1616 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1617 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1618 in
adamc@749 1619 (#1 fitem1 @ #1 fitem2,
adamc@749 1620 (EApp (e, sqlexp), loc))
adamc@749 1621 end)
adamc@749 1622 | fitem INNER JOIN fitem ON sqlexp (let
adamc@749 1623 val loc = s (fitem1left, sqlexpright)
adamc@749 1624
adamc@749 1625 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1626 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1627 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1628 in
adamc@749 1629 (#1 fitem1 @ #1 fitem2,
adamc@749 1630 (EApp (e, sqlexp), loc))
adamc@749 1631 end)
adamc@749 1632 | fitem CROSS JOIN fitem (let
adamc@749 1633 val loc = s (fitem1left, fitem2right)
adamc@749 1634
adamc@749 1635 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1636 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1637 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1638 val tru = sql_inject (EVar (["Basis"], "True", Infer), loc)
adamc@749 1639 in
adamc@749 1640 (#1 fitem1 @ #1 fitem2,
adamc@749 1641 (EApp (e, tru), loc))
adamc@749 1642 end)
adamc@750 1643 | fitem LEFT JOIN fitem ON sqlexp (let
adamc@750 1644 val loc = s (fitem1left, sqlexpright)
adamc@750 1645
adamc@750 1646 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
adamc@750 1647 val e = (EApp (e, #2 fitem1), loc)
adamc@750 1648 val e = (EApp (e, #2 fitem2), loc)
adamc@750 1649 in
adamc@750 1650 (#1 fitem1 @ #1 fitem2,
adamc@750 1651 (EApp (e, sqlexp), loc))
adamc@750 1652 end)
adamc@751 1653 | fitem LEFT OUTER JOIN fitem ON sqlexp (let
adamc@751 1654 val loc = s (fitem1left, sqlexpright)
adamc@751 1655
adamc@751 1656 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
adamc@751 1657 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1658 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1659 in
adamc@751 1660 (#1 fitem1 @ #1 fitem2,
adamc@751 1661 (EApp (e, sqlexp), loc))
adamc@751 1662 end)
adamc@751 1663 | fitem RIGHT JOIN fitem ON sqlexp (let
adamc@751 1664 val loc = s (fitem1left, sqlexpright)
adamc@751 1665
adamc@751 1666 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
adamc@751 1667 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1668 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1669 in
adamc@751 1670 (#1 fitem1 @ #1 fitem2,
adamc@751 1671 (EApp (e, sqlexp), loc))
adamc@751 1672 end)
adamc@751 1673 | fitem RIGHT OUTER JOIN fitem ON sqlexp (let
adamc@751 1674 val loc = s (fitem1left, sqlexpright)
adamc@751 1675
adamc@751 1676 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
adamc@751 1677 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1678 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1679 in
adamc@751 1680 (#1 fitem1 @ #1 fitem2,
adamc@751 1681 (EApp (e, sqlexp), loc))
adamc@751 1682 end)
adamc@751 1683 | fitem FULL JOIN fitem ON sqlexp (let
adamc@751 1684 val loc = s (fitem1left, sqlexpright)
adamc@751 1685
adamc@751 1686 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
adamc@751 1687 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1688 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1689 in
adamc@751 1690 (#1 fitem1 @ #1 fitem2,
adamc@751 1691 (EApp (e, sqlexp), loc))
adamc@751 1692 end)
adamc@751 1693 | fitem FULL OUTER JOIN fitem ON sqlexp (let
adamc@751 1694 val loc = s (fitem1left, sqlexpright)
adamc@751 1695
adamc@751 1696 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
adamc@751 1697 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1698 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1699 in
adamc@751 1700 (#1 fitem1 @ #1 fitem2,
adamc@751 1701 (EApp (e, sqlexp), loc))
adamc@751 1702 end)
adamc@1192 1703 | LPAREN query RPAREN AS tname (let
adamc@1192 1704 val loc = s (LPARENleft, RPARENright)
adamc@1192 1705
adamc@1192 1706 val e = (EVar (["Basis"], "sql_from_query", Infer), loc)
adamc@1192 1707 val e = (ECApp (e, tname), loc)
adamc@1192 1708 in
adamc@1192 1709 ([tname], (EApp (e, query), loc))
adamc@1192 1710 end)
adamc@749 1711
adamc@204 1712 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@204 1713 | LBRACE cexp RBRACE (cexp)
adamc@204 1714
adamc@243 1715 table : SYMBOL ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)),
adamc@403 1716 (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@403 1717 | SYMBOL AS tname (tname, (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@221 1718 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
adamc@207 1719
adamc@748 1720 table' : table (let
adamc@748 1721 val loc = s (tableleft, tableright)
adamc@748 1722 val e = (EVar (["Basis"], "sql_from_table", Infer), loc)
adamc@748 1723 val e = (ECApp (e, #1 table), loc)
adamc@748 1724 in
adamc@748 1725 (#1 table, (EApp (e, #2 table), loc))
adamc@748 1726 end)
adamc@748 1727
adamc@243 1728 tident : SYMBOL (CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@207 1729 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@221 1730 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
adamc@207 1731
adamc@207 1732 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@207 1733 | LBRACE cexp RBRACE (cexp)
adamc@207 1734
adamc@207 1735 seli : tident DOT fident (Field (tident, fident))
adamc@1194 1736 | sqlexp (Exp (NONE, sqlexp))
adamc@1194 1737 | sqlexp AS fident (Exp (SOME fident, sqlexp))
adamc@341 1738 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (Fields (tident, cexp))
adamc@207 1739
adamc@207 1740 selis : seli ([seli])
adamc@207 1741 | seli COMMA selis (seli :: selis)
adamc@207 1742
adamc@207 1743 select : STAR (Star)
adamc@207 1744 | selis (Items selis)
adamc@209 1745
adamc@403 1746 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", Infer),
adamc@209 1747 s (TRUEleft, TRUEright)))
adamc@403 1748 | FALSE (sql_inject (EVar (["Basis"], "False", Infer),
adamc@209 1749 s (FALSEleft, FALSEright)))
adamc@209 1750
adamc@222 1751 | INT (sql_inject (EPrim (Prim.Int INT),
adamc@222 1752 s (INTleft, INTright)))
adamc@222 1753 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
adamc@222 1754 s (FLOATleft, FLOATright)))
adamc@229 1755 | STRING (sql_inject (EPrim (Prim.String STRING),
adamc@229 1756 s (STRINGleft, STRINGright)))
adamc@441 1757 | CURRENT_TIMESTAMP (sql_nfunc ("current_timestamp",
adamc@441 1758 s (CURRENT_TIMESTAMPleft, CURRENT_TIMESTAMPright)))
adamc@222 1759
adamc@221 1760 | tident DOT fident (let
adamc@221 1761 val loc = s (tidentleft, fidentright)
adamc@403 1762 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@221 1763 val e = (ECApp (e, tident), loc)
adamc@221 1764 in
adamc@221 1765 (ECApp (e, fident), loc)
adamc@221 1766 end)
adamc@234 1767 | CSYMBOL (let
adamc@234 1768 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@310 1769 in
adamc@310 1770 if !inDml then
adamc@310 1771 let
adamc@403 1772 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@310 1773 val e = (ECApp (e, (CName "T", loc)), loc)
adamc@310 1774 in
adamc@310 1775 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1776 end
adamc@310 1777 else
adamc@310 1778 let
adamc@403 1779 val e = (EVar (["Basis"], "sql_exp", Infer), loc)
adamc@310 1780 in
adamc@310 1781 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1782 end
adamc@310 1783 end)
adamc@221 1784
adamc@471 1785 | LBRACE eexp RBRACE (eexp)
adamc@470 1786
adamc@559 1787 | sqlexp EQ sqlexp (sql_binary ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1788 | sqlexp NE sqlexp (sql_binary ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1789 | sqlexp LT sqlexp (sql_binary ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1790 | sqlexp LE sqlexp (sql_binary ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1791 | sqlexp GT sqlexp (sql_binary ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1792 | sqlexp GE sqlexp (sql_binary ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1793
adamc@559 1794 | sqlexp PLUS sqlexp (sql_binary ("plus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1795 | sqlexp MINUS sqlexp (sql_binary ("minus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1796 | sqlexp STAR sqlexp (sql_binary ("times", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1797 | sqlexp DIVIDE sqlexp (sql_binary ("div", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1798 | sqlexp MOD sqlexp (sql_binary ("mod", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1799
adamc@220 1800 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@220 1801 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1802
adamc@220 1803 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
adamc@559 1804 | MINUS sqlexp (sql_unary ("neg", sqlexp, s (MINUSleft, sqlexpright)))
adamc@220 1805
adamc@470 1806 | sqlexp IS NULL (let
adamc@470 1807 val loc = s (sqlexpleft, NULLright)
adamc@470 1808 in
adamc@470 1809 (EApp ((EVar (["Basis"], "sql_is_null", Infer), loc),
adamc@470 1810 sqlexp), loc)
adamc@470 1811 end)
adamc@470 1812
adamc@471 1813 | LBRACE LBRACK eexp RBRACK RBRACE (sql_inject (#1 eexp,
adamc@471 1814 s (LBRACEleft, RBRACEright)))
adamc@220 1815 | LPAREN sqlexp RPAREN (sqlexp)
adamc@210 1816
adamc@467 1817 | NULL (sql_inject ((EVar (["Basis"], "None", Infer),
adamc@467 1818 s (NULLleft, NULLright))))
adamc@467 1819
adamc@235 1820 | COUNT LPAREN STAR RPAREN (let
adamc@235 1821 val loc = s (COUNTleft, RPARENright)
adamc@235 1822 in
adamc@544 1823 (EVar (["Basis"], "sql_count", Infer), loc)
adamc@235 1824 end)
adamc@1187 1825 | COUNT LPAREN sqlexp RPAREN (let
adamc@1187 1826 val loc = s (COUNTleft, RPARENright)
adamc@1187 1827
adamc@1187 1828 val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
adamc@1187 1829 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
adamc@1187 1830 e), loc)
adamc@1187 1831 in
adamc@1187 1832 (EApp (e, sqlexp), loc)
adamc@1187 1833 end)
adamc@236 1834 | sqlagg LPAREN sqlexp RPAREN (let
adamc@236 1835 val loc = s (sqlaggleft, RPARENright)
adamc@236 1836
adamc@403 1837 val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
adamc@403 1838 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
adamc@236 1839 e), loc)
adamc@236 1840 in
adamc@236 1841 (EApp (e, sqlexp), loc)
adamc@236 1842 end)
adamc@746 1843 | fname LPAREN sqlexp RPAREN (let
adamc@746 1844 val loc = s (fnameleft, RPARENright)
adamc@746 1845
adamc@746 1846 val e = (EVar (["Basis"], "sql_ufunc", Infer), loc)
adamc@746 1847 val e = (EApp (e, fname), loc)
adamc@746 1848 in
adamc@746 1849 (EApp (e, sqlexp), loc)
adamc@746 1850 end)
adamc@1191 1851 | LPAREN query RPAREN (let
adamc@1191 1852 val loc = s (LPARENleft, RPARENright)
adamc@1191 1853
adamc@1191 1854 val e = (EVar (["Basis"], "sql_subquery", Infer), loc)
adamc@1191 1855 in
adamc@1191 1856 (EApp (e, query), loc)
adamc@1191 1857 end)
adamc@746 1858
adamc@746 1859 fname : SYMBOL (EVar (["Basis"], "sql_" ^ SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
adamc@746 1860 | LBRACE eexp RBRACE (eexp)
adamc@235 1861
adamc@403 1862 wopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 1863 dummy))
adamc@209 1864 | CWHERE sqlexp (sqlexp)
adamc@226 1865
adamc@226 1866 groupi : tident DOT fident (GField (tident, fident))
adamc@226 1867
adamc@226 1868 groupis: groupi ([groupi])
adamc@226 1869 | groupi COMMA groupis (groupi :: groupis)
adamc@226 1870
adamc@226 1871 gopt : (NONE)
adamc@226 1872 | GROUP BY groupis (SOME groupis)
adamc@227 1873
adamc@403 1874 hopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 1875 dummy))
adamc@227 1876 | HAVING sqlexp (sqlexp)
adamc@230 1877
adamc@403 1878 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
adamc@234 1879 (CWild (KRecord (KType, dummy), dummy), dummy)),
adamc@230 1880 dummy)
adamc@230 1881 | ORDER BY obexps (obexps)
adamc@230 1882
adamc@268 1883 obitem : sqlexp diropt (sqlexp, diropt)
adamc@268 1884
adamc@268 1885 obexps : obitem (let
adamc@268 1886 val loc = s (obitemleft, obitemright)
adamc@230 1887
adamc@403 1888 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), loc),
adamc@234 1889 (CWild (KRecord (KType, loc), loc), loc)),
adamc@230 1890 loc)
adamc@403 1891 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 1892 #1 obitem), loc)
adamc@268 1893 val e = (EApp (e, #2 obitem), loc)
adamc@230 1894 in
adamc@230 1895 (EApp (e, e'), loc)
adamc@230 1896 end)
adamc@268 1897 | obitem COMMA obexps (let
adamc@268 1898 val loc = s (obitemleft, obexpsright)
adamc@230 1899
adamc@403 1900 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 1901 #1 obitem), loc)
adamc@268 1902 val e = (EApp (e, #2 obitem), loc)
adamc@230 1903 in
adamc@230 1904 (EApp (e, obexps), loc)
adamc@230 1905 end)
adamc@231 1906
adamc@403 1907 diropt : (EVar (["Basis"], "sql_asc", Infer), dummy)
adamc@403 1908 | ASC (EVar (["Basis"], "sql_asc", Infer), s (ASCleft, ASCright))
adamc@403 1909 | DESC (EVar (["Basis"], "sql_desc", Infer), s (DESCleft, DESCright))
adamc@268 1910
adamc@403 1911 lopt : (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@403 1912 | LIMIT ALL (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@231 1913 | LIMIT sqlint (let
adamc@231 1914 val loc = s (LIMITleft, sqlintright)
adamc@231 1915 in
adamc@403 1916 (EApp ((EVar (["Basis"], "sql_limit", Infer), loc), sqlint), loc)
adamc@231 1917 end)
adamc@231 1918
adamc@403 1919 ofopt : (EVar (["Basis"], "sql_no_offset", Infer), dummy)
adamc@232 1920 | OFFSET sqlint (let
adamc@232 1921 val loc = s (OFFSETleft, sqlintright)
adamc@232 1922 in
adamc@403 1923 (EApp ((EVar (["Basis"], "sql_offset", Infer), loc), sqlint), loc)
adamc@232 1924 end)
adamc@232 1925
adamc@231 1926 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@231 1927 | LBRACE eexp RBRACE (eexp)
adamc@236 1928
adamc@236 1929 sqlagg : AVG ("avg")
adamc@236 1930 | SUM ("sum")
adamc@236 1931 | MIN ("min")
adamc@236 1932 | MAX ("max")