annotate src/urweb.grm @ 1303:c7b9a33c26c8

Hopeful fix for the Great Unification Bug
author Adam Chlipala <adam@chlipala.net>
date Sun, 10 Oct 2010 14:41:03 -0400
parents d008c4c43a0a
children 3a845f2ce9e9
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@1302 215 | EQ | COMMA | COLON | DCOLON | DCOLONWILD | TCOLON | 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
adamc@756 314 | tag of (string * exp) * 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
adamc@6 397 %nonassoc DCOLON TCOLON
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')
adamc@709 592
adamc@709 593 fun findMode mode =
adamc@709 594 let
adamc@709 595 fun findMode' pmodes =
adamc@709 596 case pmodes of
adamc@709 597 [] => (EVar (["Basis"], "no_action", Infer), loc)
adamc@709 598 | (mode', rule) :: pmodes' =>
adamc@709 599 if mode' = mode then
adamc@709 600 (if List.exists (fn (mode', _) => mode' = mode)
adamc@709 601 pmodes' then
adamc@709 602 ErrorMsg.errorAt loc "Duplicate propagation rule"
adamc@709 603 else
adamc@709 604 ();
adamc@709 605 rule)
adamc@709 606 else
adamc@709 607 findMode' pmodes'
adamc@709 608 in
adamc@709 609 findMode' pmodes
adamc@709 610 end
adamc@709 611
adamc@709 612 val e = (EVar (["Basis"], "foreign_key", Infer), loc)
adamc@709 613 val e = (EApp (e, mat), loc)
adamc@709 614 val e = (EApp (e, texp), loc)
adamc@709 615 in
adamc@709 616 (EApp (e, (ERecord [((CName "OnDelete", loc),
adamc@709 617 findMode Delete),
adamc@709 618 ((CName "OnUpdate", loc),
adamc@709 619 findMode Update)], loc)), loc)
adamc@709 620 end)
adamc@709 621
adamc@704 622 | LBRACE eexp RBRACE (eexp)
adamc@704 623
adamc@704 624 tnameW : tname (let
adamc@704 625 val loc = s (tnameleft, tnameright)
adamc@704 626 in
adamc@704 627 (tname, (CWild (KType, loc), loc))
adamc@704 628 end)
adamc@704 629
adamc@705 630 tnames : tnameW (tnameW, [])
adamc@705 631 | LPAREN tnames' RPAREN (tnames')
adamc@704 632
adamc@705 633 tnames': tnameW (tnameW, [])
adamc@705 634 | tnameW COMMA tnames' (#1 tnames', tnameW :: #2 tnames')
adamc@704 635
adamc@709 636 pmode : ON pkind prule (pkind, prule)
adamc@709 637
adamc@709 638 pkind : DELETE (Delete)
adamc@709 639 | UPDATE (Update)
adamc@709 640
adamc@709 641 prule : NO ACTION (EVar (["Basis"], "no_action", Infer), s (NOleft, ACTIONright))
adamc@709 642 | RESTRICT (EVar (["Basis"], "restrict", Infer), s (RESTRICTleft, RESTRICTright))
adamc@709 643 | CASCADE (EVar (["Basis"], "cascade", Infer), s (CASCADEleft, CASCADEright))
adamc@709 644 | SET NULL (EVar (["Basis"], "set_null", Infer), s (SETleft, NULLright))
adamc@709 645
adamc@709 646 pmodes : ([])
adamc@709 647 | pmode pmodes (pmode :: pmodes)
adamc@709 648
adamc@707 649 commaOpt: ()
adamc@707 650 | COMMA ()
adamc@707 651
adamc@993 652 pkopt : (EVar (["Basis"], "no_primary_key", Infer), dummy)
adamc@707 653 | PRIMARY KEY tnames (let
adamc@707 654 val loc = s (PRIMARYleft, tnamesright)
adamc@707 655
adamc@1093 656 val e = (EVar (["Basis"], "primary_key", TypesOnly), loc)
adamc@707 657 val e = (ECApp (e, #1 (#1 tnames)), loc)
adamc@707 658 val e = (ECApp (e, (CRecord (#2 tnames), loc)), loc)
adamc@707 659 val e = (EDisjointApp e, loc)
adamc@707 660 val e = (EDisjointApp e, loc)
adamc@707 661
adamc@707 662 val witness = map (fn (c, _) =>
adamc@707 663 (c, (EWild, loc)))
adamc@707 664 (#1 tnames :: #2 tnames)
adamc@707 665 val witness = (ERecord witness, loc)
adamc@707 666 in
adamc@707 667 (EApp (e, witness), loc)
adamc@707 668 end)
adamc@707 669
adamc@123 670 valis : vali ([vali])
adamc@123 671 | vali AND valis (vali :: valis)
adamc@123 672
adamc@42 673 sgn : sgntm (sgntm)
adamc@40 674 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@40 675 (SgnFun (CSYMBOL, sgn1, sgn2), s (FUNCTORleft, sgn2right))
adamc@30 676
adamc@42 677 sgntm : SIG sgis END (SgnConst sgis, s (SIGleft, ENDright))
adamc@59 678 | mpath (case mpath of
adamc@61 679 [] => raise Fail "Impossible mpath parse [2]"
adamc@59 680 | [x] => SgnVar x
adamc@59 681 | m :: ms => SgnProj (m,
adamc@59 682 List.take (ms, length ms - 1),
adamc@59 683 List.nth (ms, length ms - 1)),
adamc@59 684 s (mpathleft, mpathright))
adamc@42 685 | sgntm WHERE CON SYMBOL EQ cexp (SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
adamc@42 686 | sgntm WHERE LTYPE SYMBOL EQ cexp(SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
adamc@42 687 | LPAREN sgn RPAREN (sgn)
adamc@42 688
adamc@706 689 sgi : CON SYMBOL DCOLON kind ((SgiConAbs (SYMBOL, kind), s (CONleft, kindright)))
adamc@706 690 | LTYPE SYMBOL ((SgiConAbs (SYMBOL, (KType, s (LTYPEleft, SYMBOLright))),
adamc@706 691 s (LTYPEleft, SYMBOLright)))
adamc@706 692 | CON SYMBOL EQ cexp ((SgiCon (SYMBOL, NONE, cexp), s (CONleft, cexpright)))
adamc@706 693 | CON SYMBOL DCOLON kind EQ cexp ((SgiCon (SYMBOL, SOME kind, cexp), s (CONleft, cexpright)))
adamc@706 694 | LTYPE SYMBOL EQ cexp ((SgiCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
adamc@706 695 s (LTYPEleft, cexpright)))
adamc@805 696 | DATATYPE dtypes ((SgiDatatype dtypes, s (DATATYPEleft, dtypesright)))
adamc@191 697 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
adamc@191 698 (case dargs of
adamc@191 699 [] => (SgiDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
adamc@191 700 | _ => raise Fail "Arguments specified for imported datatype")
adamc@706 701 | VAL SYMBOL COLON cexp ((SgiVal (SYMBOL, cexp), s (VALleft, cexpright)))
adamc@30 702
adamc@706 703 | STRUCTURE CSYMBOL COLON sgn ((SgiStr (CSYMBOL, sgn), s (STRUCTUREleft, sgnright)))
adamc@706 704 | SIGNATURE CSYMBOL EQ sgn ((SgiSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright)))
adamc@42 705 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@706 706 ((SgiStr (CSYMBOL1,
adamc@706 707 (SgnFun (CSYMBOL2, sgn1, sgn2), s (FUNCTORleft, sgn2right))),
adamc@706 708 s (FUNCTORleft, sgn2right)))
adamc@706 709 | INCLUDE sgn ((SgiInclude sgn, s (INCLUDEleft, sgnright)))
adamc@706 710 | CONSTRAINT cterm TWIDDLE cterm ((SgiConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright)))
adamc@707 711 | TABLE SYMBOL COLON cterm pkopt commaOpt cstopt (let
adamc@707 712 val loc = s (TABLEleft, ctermright)
adamc@707 713 in
adamc@707 714 (SgiTable (SYMBOL, entable cterm, pkopt, cstopt), loc)
adamc@707 715 end)
adamc@460 716 | SEQUENCE SYMBOL (let
adamc@460 717 val loc = s (SEQUENCEleft, SYMBOLright)
adamc@460 718 val t = (CVar (["Basis"], "sql_sequence"), loc)
adamc@460 719 in
adamc@460 720 (SgiVal (SYMBOL, t), loc)
adamc@460 721 end)
adamc@754 722 | VIEW SYMBOL COLON cexp (let
adamc@754 723 val loc = s (VIEWleft, cexpright)
adamc@754 724 val t = (CVar (["Basis"], "sql_view"), loc)
adamc@1076 725 val t = (CApp (t, entable cexp), loc)
adamc@754 726 in
adamc@754 727 (SgiVal (SYMBOL, t), loc)
adamc@754 728 end)
adamc@563 729 | CLASS SYMBOL (let
adamc@563 730 val loc = s (CLASSleft, SYMBOLright)
adamc@711 731 val k = (KArrow ((KType, loc), (KType, loc)), loc)
adamc@563 732 in
adamc@711 733 (SgiClassAbs (SYMBOL, k), loc)
adamc@563 734 end)
adamc@563 735 | CLASS SYMBOL DCOLON kind (let
adamc@563 736 val loc = s (CLASSleft, kindright)
adamc@563 737 in
adamc@563 738 (SgiClassAbs (SYMBOL, kind), loc)
adamc@563 739 end)
adamc@563 740 | CLASS SYMBOL EQ cexp (let
adamc@563 741 val loc = s (CLASSleft, cexpright)
adamc@563 742 in
adamc@563 743 (SgiClass (SYMBOL, (KWild, loc), cexp), loc)
adamc@563 744 end)
adamc@563 745 | CLASS SYMBOL DCOLON kind EQ cexp (let
adamc@563 746 val loc = s (CLASSleft, cexpright)
adamc@563 747 in
adamc@563 748 (SgiClass (SYMBOL, kind, cexp), loc)
adamc@563 749 end)
adamc@211 750 | CLASS SYMBOL SYMBOL EQ cexp (let
adamc@211 751 val loc = s (CLASSleft, cexpright)
adamc@563 752 val k = (KWild, loc)
adamc@211 753 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
adamc@211 754 in
adamc@563 755 (SgiClass (SYMBOL1, k, c), s (CLASSleft, cexpright))
adamc@563 756 end)
adamc@563 757 | CLASS SYMBOL LPAREN SYMBOL DCOLON kind RPAREN EQ cexp (let
adamc@563 758 val loc = s (CLASSleft, cexpright)
adamc@563 759 val c = (CAbs (SYMBOL2, SOME kind, cexp), loc)
adamc@563 760 in
adamc@563 761 (SgiClass (SYMBOL1, kind, c), s (CLASSleft, cexpright))
adamc@211 762 end)
adamc@460 763 | COOKIE SYMBOL COLON cexp (let
adamc@460 764 val loc = s (COOKIEleft, cexpright)
adamc@460 765 val t = (CApp ((CVar (["Basis"], "http_cookie"), loc),
adamc@460 766 entable cexp), loc)
adamc@460 767 in
adamc@460 768 (SgiVal (SYMBOL, t), loc)
adamc@460 769 end)
adamc@720 770 | STYLE SYMBOL (let
adamc@720 771 val loc = s (STYLEleft, SYMBOLright)
adamc@720 772 val t = (CVar (["Basis"], "css_class"), loc)
adamc@718 773 in
adamc@718 774 (SgiVal (SYMBOL, t), loc)
adamc@718 775 end)
adamc@30 776
adamc@30 777 sgis : ([])
adamc@30 778 | sgi sgis (sgi :: sgis)
adamc@30 779
adamc@30 780 str : STRUCT decls END (StrConst decls, s (STRUCTleft, ENDright))
adamc@34 781 | spath (spath)
adamc@40 782 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN DARROW str
adamc@40 783 (StrFun (CSYMBOL, sgn, NONE, str), s (FUNCTORleft, strright))
adamc@40 784 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn DARROW str
adamc@40 785 (StrFun (CSYMBOL, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))
adamc@44 786 | spath LPAREN str RPAREN (StrApp (spath, str), s (spathleft, RPARENright))
adamc@34 787
adamc@34 788 spath : CSYMBOL (StrVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@34 789 | spath DOT CSYMBOL (StrProj (spath, CSYMBOL), s (spathleft, CSYMBOLright))
adamc@30 790
adamc@1 791 kind : TYPE (KType, s (TYPEleft, TYPEright))
adamc@1 792 | NAME (KName, s (NAMEleft, NAMEright))
adamc@1 793 | LBRACE kind RBRACE (KRecord kind, s (LBRACEleft, RBRACEright))
adamc@1 794 | kind ARROW kind (KArrow (kind1, kind2), s (kind1left, kind2right))
adamc@1 795 | LPAREN kind RPAREN (#1 kind, s (LPARENleft, RPARENright))
adamc@82 796 | KUNIT (KUnit, s (KUNITleft, KUNITright))
adamc@18 797 | UNDERUNDER (KWild, s (UNDERUNDERleft, UNDERUNDERright))
adamc@207 798 | LPAREN ktuple RPAREN (KTuple ktuple, s (LPARENleft, RPARENright))
adamc@623 799 | CSYMBOL (KVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@623 800 | CSYMBOL KARROW kind (KFun (CSYMBOL, kind), s (CSYMBOLleft, kindright))
adamc@207 801
adamc@207 802 ktuple : kind STAR kind ([kind1, kind2])
adamc@207 803 | kind STAR ktuple (kind :: ktuple)
adamc@1 804
adamc@1 805 capps : cterm (cterm)
adamc@1 806 | capps cterm (CApp (capps, cterm), s (cappsleft, ctermright))
adamc@1 807
adamc@1 808 cexp : capps (capps)
adamc@1 809 | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right))
adamc@15 810 | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright))
adamc@623 811 | CSYMBOL KARROW cexp (TKFun (CSYMBOL, cexp), s (CSYMBOLleft, cexpright))
adamc@1 812
adamc@1 813 | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right))
adamc@1 814
adamc@239 815 | FN cargs DARROW cexp (#1 (cargs (cexp, (KWild, s (FNleft, cexpright)))))
adamc@628 816 | LBRACK cexp TWIDDLE cexp RBRACK DARROW cexp (TDisjoint (cexp1, cexp2, cexp3), s (LBRACKleft, cexp3right))
adamc@623 817 | CSYMBOL DKARROW cexp (CKAbs (CSYMBOL, cexp), s (CSYMBOLleft, cexpright))
adamc@1 818
adamc@8 819 | LPAREN cexp RPAREN DCOLON kind (CAnnot (cexp, kind), s (LPARENleft, kindright))
adamc@6 820
adamc@18 821 | UNDER DCOLON kind (CWild kind, s (UNDERleft, UNDERright))
adamc@195 822 | ctuple (let
adamc@195 823 val loc = s (ctupleleft, ctupleright)
adamc@195 824 in
adamc@195 825 (TRecord (CRecord (ListUtil.mapi (fn (i, c) =>
adamc@195 826 ((CName (Int.toString (i + 1)), loc),
adamc@195 827 c)) ctuple),
adamc@195 828 loc), loc)
adamc@195 829 end)
adamc@18 830
adamc@1 831 kcolon : DCOLON (Explicit)
adamc@1 832 | TCOLON (Implicit)
adamc@1 833
adamc@239 834 cargs : carg (carg)
adamc@239 835 | cargl (cargl)
adamc@239 836
adamc@239 837 cargl : cargp cargp (cargp1 o cargp2)
adamc@239 838 | cargp cargl (cargp o cargl)
adamc@239 839
adamc@240 840 cargl2 : (fn x => x)
adamc@240 841 | cargp cargl2 (cargp o cargl2)
adamc@240 842
adamc@241 843 carg : SYMBOL DCOLON kind (fn (c, k) =>
adamc@239 844 let
adamc@239 845 val loc = s (SYMBOLleft, kindright)
adamc@239 846 in
adamc@239 847 ((CAbs (SYMBOL, SOME kind, c), loc),
adamc@239 848 (KArrow (kind, k), loc))
adamc@239 849 end)
adamc@329 850 | UNDER DCOLON kind (fn (c, k) =>
adamc@329 851 let
adamc@329 852 val loc = s (UNDERleft, kindright)
adamc@329 853 in
adamc@329 854 ((CAbs ("_", SOME kind, c), loc),
adamc@329 855 (KArrow (kind, k), loc))
adamc@329 856 end)
adam@1302 857 | SYMBOL DCOLONWILD (fn (c, k) =>
adam@1302 858 let
adam@1302 859 val loc = s (SYMBOLleft, DCOLONWILDright)
adam@1302 860 val kind = (KWild, loc)
adam@1302 861 in
adam@1302 862 ((CAbs (SYMBOL, NONE, c), loc),
adam@1302 863 (KArrow (kind, k), loc))
adam@1302 864 end)
adam@1302 865 | UNDER DCOLONWILD (fn (c, k) =>
adam@1302 866 let
adam@1302 867 val loc = s (UNDERleft, DCOLONWILDright)
adam@1302 868 val kind = (KWild, loc)
adam@1302 869 in
adam@1302 870 ((CAbs ("_", NONE, c), loc),
adam@1302 871 (KArrow (kind, k), loc))
adam@1302 872 end)
adamc@241 873 | cargp (cargp)
adamc@239 874
adamc@239 875 cargp : SYMBOL (fn (c, k) =>
adamc@239 876 let
adamc@239 877 val loc = s (SYMBOLleft, SYMBOLright)
adamc@239 878 in
adamc@239 879 ((CAbs (SYMBOL, NONE, c), loc),
adamc@239 880 (KArrow ((KWild, loc), k), loc))
adamc@239 881 end)
adamc@329 882 | UNDER (fn (c, k) =>
adamc@329 883 let
adamc@329 884 val loc = s (UNDERleft, UNDERright)
adamc@329 885 in
adamc@329 886 ((CAbs ("_", NONE, c), loc),
adamc@329 887 (KArrow ((KWild, loc), k), loc))
adamc@329 888 end)
adamc@1001 889 | LPAREN SYMBOL kopt ckl RPAREN (fn (c, k) =>
adamc@239 890 let
adamc@239 891 val loc = s (LPARENleft, RPARENright)
adamc@1001 892 val ckl = (SYMBOL, kopt) :: ckl
adamc@1001 893 val ckl = map (fn (x, ko) => (x, case ko of
adamc@1001 894 NONE => (KWild, loc)
adamc@1001 895 | SOME k => k)) ckl
adamc@239 896 in
adamc@1001 897 case ckl of
adamc@1001 898 [(x, k')] => ((CAbs (SYMBOL, SOME k', c), loc),
adamc@1001 899 (KArrow (k', k), loc))
adamc@1001 900 | _ =>
adamc@1001 901 let
adamc@1001 902 val k' = (KTuple (map #2 ckl), loc)
adamc@1001 903
adamc@1001 904 val c = foldr (fn ((x, k), c) =>
adamc@1001 905 (CAbs (x, SOME k, c), loc)) c ckl
adamc@1001 906 val v = (CVar ([], "$x"), loc)
adamc@1001 907 val c = ListUtil.foldli (fn (i, _, c) =>
adamc@1001 908 (CApp (c, (CProj (v, i + 1), loc)),
adamc@1001 909 loc)) c ckl
adamc@1001 910 in
adamc@1001 911 ((CAbs ("$x", SOME k', c), loc),
adamc@1001 912 (KArrow (k', k), loc))
adamc@1001 913 end
adamc@239 914 end)
adamc@628 915
adamc@1001 916 ckl : ([])
adamc@1001 917 | COMMA SYMBOL kopt ckl ((SYMBOL, kopt) :: ckl)
adamc@239 918
adamc@34 919 path : SYMBOL ([], SYMBOL)
adamc@34 920 | CSYMBOL DOT path (let val (ms, x) = path in (CSYMBOL :: ms, x) end)
adamc@34 921
adamc@156 922 cpath : CSYMBOL ([], CSYMBOL)
adamc@156 923 | CSYMBOL DOT cpath (let val (ms, x) = cpath in (CSYMBOL :: ms, x) end)
adamc@156 924
adamc@59 925 mpath : CSYMBOL ([CSYMBOL])
adamc@59 926 | CSYMBOL DOT mpath (CSYMBOL :: mpath)
adamc@59 927
adamc@1 928 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright))
adamc@1 929 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright))
adamc@83 930 | LBRACK rconn RBRACK (CRecord rconn, s (LBRACKleft, RBRACKright))
adamc@1 931 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)),
adamc@1 932 s (LBRACEleft, RBRACEright))
adamc@1 933 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright))
adamc@1 934 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright))
adamc@195 935 | HASH INT (CName (Int64.toString INT), s (HASHleft, INTright))
adamc@1 936
adamc@34 937 | path (CVar path, s (pathleft, pathright))
adamc@207 938 | path DOT INT (CProj ((CVar path, s (pathleft, pathright)), Int64.toInt INT),
adamc@207 939 s (pathleft, INTright))
adamc@18 940 | UNDER (CWild (KWild, s (UNDERleft, UNDERright)), s (UNDERleft, UNDERright))
adamc@621 941 | MAP (CMap, s (MAPleft, MAPright))
adamc@82 942 | UNIT (CUnit, s (UNITleft, UNITright))
adamc@207 943 | LPAREN ctuplev RPAREN (CTuple ctuplev, s (LPARENleft, RPARENright))
adamc@207 944
adamc@207 945 ctuplev: cexp COMMA cexp ([cexp1, cexp2])
adamc@207 946 | cexp COMMA ctuplev (cexp :: ctuplev)
adamc@1 947
adamc@196 948 ctuple : capps STAR capps ([capps1, capps2])
adamc@196 949 | capps STAR ctuple (capps :: ctuple)
adamc@195 950
adamc@1 951 rcon : ([])
adamc@1 952 | ident EQ cexp ([(ident, cexp)])
adamc@1 953 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon)
adamc@1 954
adamc@83 955 rconn : ident ([(ident, (CUnit, s (identleft, identright)))])
adamc@83 956 | ident COMMA rconn ((ident, (CUnit, s (identleft, identright))) :: rconn)
adamc@83 957
adamc@1 958 rcone : ([])
adamc@1 959 | ident COLON cexp ([(ident, cexp)])
adamc@1 960 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone)
adamc@1 961
adamc@1 962 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@195 963 | INT (CName (Int64.toString INT), s (INTleft, INTright))
adamc@200 964 | SYMBOL (CVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@8 965
adamc@8 966 eapps : eterm (eterm)
adamc@8 967 | eapps eterm (EApp (eapps, eterm), s (eappsleft, etermright))
adamc@8 968 | eapps LBRACK cexp RBRACK (ECApp (eapps, cexp), s (eappsleft, RBRACKright))
adamc@629 969 | eapps BANG (EDisjointApp eapps, s (eappsleft, BANGright))
adamc@8 970
adamc@8 971 eexp : eapps (eapps)
adamc@241 972 | FN eargs DARROW eexp (let
adamc@93 973 val loc = s (FNleft, eexpright)
adamc@93 974 in
adamc@241 975 #1 (eargs (eexp, (CWild (KType, loc), loc)))
adamc@93 976 end)
adamc@623 977 | CSYMBOL DKARROW eexp (EKAbs (CSYMBOL, eexp), s (CSYMBOLleft, eexpright))
adamc@196 978 | eexp COLON cexp (EAnnot (eexp, cexp), s (eexpleft, cexpright))
adamc@149 979 | eexp MINUSMINUS cexp (ECut (eexp, cexp), s (eexpleft, cexpright))
adamc@493 980 | eexp MINUSMINUSMINUS cexp (ECutMulti (eexp, cexp), s (eexpleft, cexpright))
adamc@170 981 | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
adamc@190 982 | IF eexp THEN eexp ELSE eexp (let
adamc@190 983 val loc = s (IFleft, eexp3right)
adamc@190 984 in
adamc@190 985 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc), eexp2),
adamc@190 986 ((PCon (["Basis"], "False", NONE), loc), eexp3)]), loc)
adamc@190 987 end)
adamc@434 988 | bind SEMI eexp (let
adamc@434 989 val loc = s (bindleft, eexpright)
adamc@434 990 val (v, to, e1) = bind
adamc@403 991 val e = (EVar (["Basis"], "bind", Infer), loc)
adamc@434 992 val e = (EApp (e, e1), loc)
adamc@243 993 in
adamc@434 994 (EApp (e, (EAbs (v, to, eexp), loc)), loc)
adamc@299 995 end)
adamc@256 996 | eexp EQ eexp (native_op ("eq", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@257 997 | eexp NE eexp (native_op ("ne", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 998 | MINUS eterm (native_unop ("neg", eterm, s (MINUSleft, etermright)))
adamc@389 999 | eexp PLUS eexp (native_op ("plus", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 1000 | eexp MINUS eexp (native_op ("minus", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@1116 1001 | eapps STAR eexp (native_op ("times", eapps, eexp, s (eappsleft, eexpright)))
adamc@964 1002 | eexp DIVIDE eexp (native_op ("divide", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 1003 | eexp MOD eexp (native_op ("mod", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1004
adamc@391 1005 | eexp LT eexp (native_op ("lt", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1006 | eexp LE eexp (native_op ("le", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1007 | eexp GT eexp (native_op ("gt", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1008 | eexp GE eexp (native_op ("ge", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1009
adamc@842 1010 | eexp ANDALSO eexp (let
adamc@842 1011 val loc = s (eexp1left, eexp2right)
adamc@842 1012 in
adamc@842 1013 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc),
adamc@842 1014 eexp2),
adamc@842 1015 ((PCon (["Basis"], "False", NONE), loc),
adamc@842 1016 (EVar (["Basis"], "False", Infer), loc))]), loc)
adamc@842 1017 end)
adamc@842 1018 | eexp ORELSE eexp (let
adamc@842 1019 val loc = s (eexp1left, eexp2right)
adamc@842 1020 in
adamc@842 1021 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc),
adamc@842 1022 (EVar (["Basis"], "True", Infer), loc)),
adamc@842 1023 ((PCon (["Basis"], "False", NONE), loc),
adamc@842 1024 eexp2)]), loc)
adamc@842 1025 end)
adamc@842 1026
adamc@445 1027 | eexp PLUSPLUS eexp (EConcat (eexp1, eexp2), s (eexp1left, eexp2right))
adamc@8 1028
adamc@674 1029 | eexp CARET eexp (native_op ("strcat", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@674 1030
adamc@794 1031 | eapps DCOLON eexp (let
adamc@794 1032 val loc = s (eappsleft, eexpright)
adamc@762 1033 in
adamc@762 1034 (EApp ((EVar (["Basis"], "Cons", Infer), loc),
adamc@762 1035 (ERecord [((CName "1", loc),
adamc@794 1036 eapps),
adamc@762 1037 ((CName "2", loc),
adamc@762 1038 eexp)], loc)), loc)
adamc@762 1039 end)
adamc@762 1040
adamc@434 1041 bind : SYMBOL LARROW eapps (SYMBOL, NONE, eapps)
adamc@434 1042 | eapps (let
adamc@434 1043 val loc = s (eappsleft, eappsright)
adamc@434 1044 in
adamc@434 1045 ("_", SOME (TRecord (CRecord [], loc), loc), eapps)
adamc@434 1046 end)
adamc@434 1047
adamc@241 1048 eargs : earg (earg)
adamc@241 1049 | eargl (eargl)
adamc@241 1050
adamc@241 1051 eargl : eargp eargp (eargp1 o eargp2)
adamc@241 1052 | eargp eargl (eargp o eargl)
adamc@241 1053
adamc@242 1054 eargl2 : (fn x => x)
adamc@242 1055 | eargp eargl2 (eargp o eargl2)
adamc@242 1056
adamc@822 1057 earg : patS (fn (e, t) =>
adamc@241 1058 let
adamc@822 1059 val loc = s (patSleft, patSright)
adamc@822 1060 val pt = patType loc patS
adamc@822 1061
adamc@822 1062 val e' = case #1 patS of
adamc@822 1063 PVar x => (EAbs (x, NONE, e), loc)
adamc@823 1064 | PAnnot ((PVar x, _), t) => (EAbs (x, SOME t, e), loc)
adamc@822 1065 | _ => (EAbs ("$x", SOME pt,
adamc@822 1066 (ECase ((EVar ([], "$x", DontInfer),
adamc@822 1067 loc),
adamc@822 1068 [(patS, e)]), loc)), loc)
adamc@241 1069 in
adamc@822 1070 (e', (TFun (pt, t), loc))
adamc@241 1071 end)
adamc@822 1072 | earga (earga)
adamc@822 1073
adamc@822 1074 eargp : pterm (fn (e, t) =>
adamc@241 1075 let
adamc@822 1076 val loc = s (ptermleft, ptermright)
adamc@822 1077 val pt = patType loc pterm
adamc@822 1078
adamc@822 1079 val e' = case #1 pterm of
adamc@822 1080 PVar x => (EAbs (x, NONE, e), loc)
adamc@823 1081 | PAnnot ((PVar x, _), t) => (EAbs (x, SOME t, e), loc)
adamc@822 1082 | _ => (EAbs ("$x", SOME pt,
adamc@822 1083 (ECase ((EVar ([], "$x", DontInfer),
adamc@822 1084 loc),
adamc@822 1085 [(pterm, e)]), loc)), loc)
adamc@241 1086 in
adamc@822 1087 (e', (TFun (pt, t), loc))
adamc@241 1088 end)
adamc@822 1089 | earga (earga)
adamc@241 1090
adamc@822 1091 earga : LBRACK SYMBOL RBRACK (fn (e, t) =>
adamc@241 1092 let
adamc@822 1093 val loc = s (LBRACKleft, RBRACKright)
adamc@822 1094 val kind = (KWild, loc)
adamc@822 1095 in
adamc@822 1096 ((ECAbs (Implicit, SYMBOL, kind, e), loc),
adamc@822 1097 (TCFun (Implicit, SYMBOL, kind, t), loc))
adamc@822 1098 end)
adam@1302 1099 | LBRACK SYMBOL DCOLONWILD RBRACK (fn (e, t) =>
adam@1302 1100 let
adam@1302 1101 val loc = s (LBRACKleft, RBRACKright)
adam@1302 1102 val kind = (KWild, loc)
adam@1302 1103 in
adam@1302 1104 ((ECAbs (Explicit, SYMBOL, kind, e), loc),
adam@1302 1105 (TCFun (Explicit, SYMBOL, kind, t), loc))
adam@1302 1106 end)
adamc@822 1107 | LBRACK SYMBOL kcolon kind RBRACK(fn (e, t) =>
adamc@822 1108 let
adamc@822 1109 val loc = s (LBRACKleft, RBRACKright)
adamc@241 1110 in
adamc@241 1111 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
adamc@241 1112 (TCFun (kcolon, SYMBOL, kind, t), loc))
adamc@241 1113 end)
adamc@478 1114 | LBRACK cexp TWIDDLE cexp RBRACK(fn (e, t) =>
adamc@356 1115 let
adamc@356 1116 val loc = s (LBRACKleft, RBRACKright)
adamc@356 1117 in
adamc@478 1118 ((EDisjoint (cexp1, cexp2, e), loc),
adamc@628 1119 (TDisjoint (cexp1, cexp2, t), loc))
adamc@356 1120 end)
adamc@822 1121 | LBRACK CSYMBOL RBRACK (fn (e, t) =>
adamc@623 1122 let
adamc@623 1123 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@623 1124 in
adamc@623 1125 ((EKAbs (CSYMBOL, e), loc),
adamc@623 1126 (TKFun (CSYMBOL, t), loc))
adamc@623 1127 end)
adamc@241 1128
adamc@8 1129 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
adamc@195 1130 | LPAREN etuple RPAREN (let
adamc@195 1131 val loc = s (LPARENleft, RPARENright)
adamc@195 1132 in
adamc@195 1133 (ERecord (ListUtil.mapi (fn (i, e) =>
adamc@195 1134 ((CName (Int.toString (i + 1)), loc),
adamc@195 1135 e)) etuple), loc)
adamc@195 1136 end)
adamc@8 1137
adamc@403 1138 | path (EVar (#1 path, #2 path, Infer), s (pathleft, pathright))
adamc@403 1139 | cpath (EVar (#1 cpath, #2 cpath, Infer), s (cpathleft, cpathright))
adamc@403 1140 | AT path (EVar (#1 path, #2 path, TypesOnly), s (ATleft, pathright))
adamc@403 1141 | AT AT path (EVar (#1 path, #2 path, DontInfer), s (AT1left, pathright))
adamc@403 1142 | AT cpath (EVar (#1 cpath, #2 cpath, TypesOnly), s (ATleft, cpathright))
adamc@403 1143 | AT AT cpath (EVar (#1 cpath, #2 cpath, DontInfer), s (AT1left, cpathright))
adamc@12 1144 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
adamc@110 1145 | UNIT (ERecord [], s (UNITleft, UNITright))
adamc@12 1146
adamc@14 1147 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@14 1148 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@14 1149 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@821 1150 | CHAR (EPrim (Prim.Char CHAR), s (CHARleft, CHARright))
adamc@14 1151
adamc@200 1152 | path DOT idents (let
adamc@200 1153 val loc = s (pathleft, identsright)
adamc@200 1154 in
adamc@200 1155 foldl (fn (ident, e) =>
adamc@200 1156 (EField (e, ident), loc))
adamc@403 1157 (EVar (#1 path, #2 path, Infer), s (pathleft, pathright)) idents
adamc@403 1158 end)
adamc@910 1159 | LPAREN eexp RPAREN DOT idents (let
adamc@910 1160 val loc = s (LPARENleft, identsright)
adamc@910 1161 in
adamc@910 1162 foldl (fn (ident, e) =>
adamc@910 1163 (EField (e, ident), loc))
adamc@910 1164 eexp idents
adamc@910 1165 end)
adamc@403 1166 | AT path DOT idents (let
adamc@403 1167 val loc = s (ATleft, identsright)
adamc@403 1168 in
adamc@403 1169 foldl (fn (ident, e) =>
adamc@403 1170 (EField (e, ident), loc))
adamc@403 1171 (EVar (#1 path, #2 path, TypesOnly), s (pathleft, pathright)) idents
adamc@403 1172 end)
adamc@403 1173 | AT AT path DOT idents (let
adamc@403 1174 val loc = s (AT1left, identsright)
adamc@403 1175 in
adamc@403 1176 foldl (fn (ident, e) =>
adamc@403 1177 (EField (e, ident), loc))
adamc@403 1178 (EVar (#1 path, #2 path, DontInfer), s (pathleft, pathright)) idents
adamc@200 1179 end)
adamc@71 1180
adamc@360 1181 | XML_BEGIN xml XML_END (let
adamc@360 1182 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 1183 in
adamc@360 1184 if XML_BEGIN = "xml" then
adamc@360 1185 ()
adamc@360 1186 else
adamc@360 1187 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@360 1188 xml
adamc@360 1189 end)
adamc@360 1190 | XML_BEGIN XML_END (let
adamc@360 1191 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 1192 in
adamc@360 1193 if XML_BEGIN = "xml" then
adamc@360 1194 ()
adamc@360 1195 else
adamc@360 1196 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@403 1197 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
adamc@360 1198 (EPrim (Prim.String ""), loc)),
adamc@360 1199 loc)
adamc@360 1200 end)
adamc@360 1201 | XML_BEGIN_END (let
adamc@360 1202 val loc = s (XML_BEGIN_ENDleft, XML_BEGIN_ENDright)
adamc@360 1203 in
adamc@360 1204 if XML_BEGIN_END = "xml" then
adamc@360 1205 ()
adamc@360 1206 else
adamc@360 1207 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@403 1208 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
adamc@360 1209 (EPrim (Prim.String ""), loc)),
adamc@360 1210 loc)
adamc@360 1211 end)
adamc@302 1212
adamc@204 1213 | LPAREN query RPAREN (query)
adamc@300 1214 | LPAREN CWHERE sqlexp RPAREN (sqlexp)
adamc@339 1215 | LPAREN SQL sqlexp RPAREN (sqlexp)
adamc@1070 1216 | LPAREN FROM tables RPAREN (#2 tables)
adamc@1071 1217 | LPAREN SELECT1 query1 RPAREN (query1)
adamc@302 1218
adamc@302 1219 | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN
adamc@302 1220 (let
adamc@302 1221 val loc = s (LPAREN1left, RPAREN3right)
adamc@302 1222
adamc@403 1223 val e = (EVar (["Basis"], "insert", Infer), loc)
adamc@302 1224 val e = (EApp (e, texp), loc)
adamc@302 1225 in
adamc@302 1226 if length fields <> length sqlexps then
adamc@302 1227 ErrorMsg.errorAt loc "Length mismatch in INSERT field specification"
adamc@302 1228 else
adamc@302 1229 ();
adamc@302 1230 (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
adamc@302 1231 end)
adamc@310 1232 | LPAREN enterDml UPDATE texp SET fsets CWHERE sqlexp leaveDml RPAREN
adamc@303 1233 (let
adamc@303 1234 val loc = s (LPARENleft, RPARENright)
adamc@303 1235
adamc@403 1236 val e = (EVar (["Basis"], "update", Infer), loc)
adamc@342 1237 val e = (ECApp (e, (CWild (KRecord (KType, loc), loc), loc)), loc)
adamc@306 1238 val e = (EApp (e, (ERecord fsets, loc)), loc)
adamc@305 1239 val e = (EApp (e, texp), loc)
adamc@303 1240 in
adamc@303 1241 (EApp (e, sqlexp), loc)
adamc@303 1242 end)
adamc@310 1243 | LPAREN enterDml DELETE FROM texp CWHERE sqlexp leaveDml RPAREN
adamc@304 1244 (let
adamc@304 1245 val loc = s (LPARENleft, RPARENright)
adamc@304 1246
adamc@403 1247 val e = (EVar (["Basis"], "delete", Infer), loc)
adamc@304 1248 val e = (EApp (e, texp), loc)
adamc@304 1249 in
adamc@304 1250 (EApp (e, sqlexp), loc)
adamc@304 1251 end)
adamc@302 1252
adamc@211 1253 | UNDER (EWild, s (UNDERleft, UNDERright))
adamc@91 1254
adamc@446 1255 | LET edecls IN eexp END (ELet (edecls, eexp), s (LETleft, ENDright))
adamc@446 1256
adamc@762 1257 | LBRACK RBRACK (EVar (["Basis"], "Nil", Infer), s (LBRACKleft, RBRACKright))
adamc@762 1258
adamc@446 1259 edecls : ([])
adamc@446 1260 | edecl edecls (edecl :: edecls)
adamc@446 1261
adamc@825 1262 edecl : VAL pat EQ eexp ((EDVal (pat, eexp), s (VALleft, eexpright)))
adamc@446 1263 | VAL REC valis ((EDValRec valis, s (VALleft, valisright)))
adamc@446 1264 | FUN valis ((EDValRec valis, s (FUNleft, valisright)))
adamc@446 1265
adamc@310 1266 enterDml : (inDml := true)
adamc@310 1267 leaveDml : (inDml := false)
adamc@310 1268
adamc@403 1269 texp : SYMBOL (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
adamc@302 1270 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
adamc@302 1271
adamc@302 1272 fields : fident ([fident])
adamc@302 1273 | fident COMMA fields (fident :: fields)
adamc@302 1274
adamc@302 1275 sqlexps: sqlexp ([sqlexp])
adamc@302 1276 | sqlexp COMMA sqlexps (sqlexp :: sqlexps)
adamc@302 1277
adamc@303 1278 fsets : fident EQ sqlexp ([(fident, sqlexp)])
adamc@303 1279 | fident EQ sqlexp COMMA fsets ((fident, sqlexp) :: fsets)
adamc@303 1280
adamc@200 1281 idents : ident ([ident])
adamc@200 1282 | ident DOT idents (ident :: idents)
adamc@200 1283
adamc@195 1284 etuple : eexp COMMA eexp ([eexp1, eexp2])
adamc@195 1285 | eexp COMMA etuple (eexp :: etuple)
adamc@195 1286
adamc@170 1287 branch : pat DARROW eexp (pat, eexp)
adamc@170 1288
adamc@170 1289 branchs: ([])
adamc@170 1290 | BAR branch branchs (branch :: branchs)
adamc@170 1291
adamc@822 1292 patS : pterm (pterm)
adamc@822 1293 | pterm DCOLON patS (let
adamc@822 1294 val loc = s (ptermleft, patSright)
adamc@762 1295 in
adamc@762 1296 (PCon (["Basis"], "Cons", SOME (PRecord ([("1", pterm),
adamc@822 1297 ("2", patS)], false), loc)),
adamc@762 1298 loc)
adamc@762 1299 end)
adamc@822 1300 | patS COLON cexp (PAnnot (patS, cexp), s (patSleft, cexpright))
adamc@822 1301
adamc@822 1302 pat : patS (patS)
adamc@822 1303 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
adamc@170 1304
adamc@170 1305 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
adamc@170 1306 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
adamc@170 1307 | UNDER (PWild, s (UNDERleft, UNDERright))
adamc@173 1308 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
adamc@173 1309 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@821 1310 | CHAR (PPrim (Prim.Char CHAR), s (CHARleft, CHARright))
adamc@170 1311 | LPAREN pat RPAREN (pat)
adamc@174 1312 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
adamc@174 1313 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
adamc@174 1314 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
adamc@195 1315 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
adamc@195 1316 false),
adamc@195 1317 s (LPARENleft, RPARENright))
adamc@762 1318 | LBRACK RBRACK (PCon (["Basis"], "Nil", NONE), s (LBRACKleft, RBRACKright))
adamc@174 1319
adamc@175 1320 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
adamc@243 1321 | INT EQ pat ([(Int64.toString INT, pat)], false)
adamc@174 1322 | DOTDOTDOT ([], true)
adamc@175 1323 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
adamc@243 1324 | INT EQ pat COMMA rpat ((Int64.toString INT, pat) :: #1 rpat, #2 rpat)
adamc@170 1325
adamc@195 1326 ptuple : pat COMMA pat ([pat1, pat2])
adamc@195 1327 | pat COMMA ptuple (pat :: ptuple)
adamc@195 1328
adamc@12 1329 rexp : ([])
adamc@12 1330 | ident EQ eexp ([(ident, eexp)])
adamc@12 1331 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
adamc@91 1332
adamc@141 1333 xml : xmlOne xml (let
adamc@141 1334 val pos = s (xmlOneleft, xmlright)
adamc@141 1335 in
adamc@720 1336 (EApp ((EApp (
adamc@720 1337 (EVar (["Basis"], "join", Infer), pos),
adamc@720 1338 xmlOne), pos),
adamc@720 1339 xml), pos)
adamc@141 1340 end)
adamc@141 1341 | xmlOne (xmlOne)
adamc@91 1342
adamc@1045 1343 xmlOpt : xml (xml)
adamc@1045 1344 | (EApp ((EVar (["Basis"], "cdata", Infer), dummy),
adamc@1045 1345 (EPrim (Prim.String ""), dummy)),
adamc@1045 1346 dummy)
adamc@1045 1347
adamc@403 1348 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata", Infer), s (NOTAGSleft, NOTAGSright)),
adamc@141 1349 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
adamc@141 1350 s (NOTAGSleft, NOTAGSright))
adamc@141 1351 | tag DIVIDE GT (let
adamc@141 1352 val pos = s (tagleft, GTright)
adamc@710 1353
adamc@710 1354 val cdata =
adamc@756 1355 if #1 (#1 tag) = "submit" orelse #1 (#1 tag) = "dyn" then
adamc@710 1356 let
adamc@710 1357 val e = (EVar (["Basis"], "cdata", DontInfer), pos)
adamc@710 1358 val e = (ECApp (e, (CWild (KWild, pos), pos)), pos)
adamc@710 1359 in
adamc@710 1360 (ECApp (e, (CRecord [], pos)), pos)
adamc@710 1361 end
adamc@710 1362 else
adamc@710 1363 (EVar (["Basis"], "cdata", Infer), pos)
adamc@710 1364
adamc@710 1365 val cdata = (EApp (cdata,
adamc@710 1366 (EPrim (Prim.String ""), pos)),
adamc@710 1367 pos)
adamc@141 1368 in
adamc@710 1369 (EApp (#2 tag, cdata), pos)
adamc@141 1370 end)
adamc@141 1371
adamc@1045 1372 | tag GT xmlOpt END_TAG (let
adamc@141 1373 val pos = s (tagleft, GTright)
adamc@325 1374 val et = tagIn END_TAG
adamc@141 1375 in
adamc@756 1376 if #1 (#1 tag) = et then
adamc@361 1377 if et = "form" then
adamc@403 1378 (EApp ((EVar (["Basis"], "form", Infer), pos),
adamc@1045 1379 xmlOpt), pos)
adamc@1093 1380 else if et = "subform" orelse et = "subforms" then
adamc@1093 1381 (EApp (#2 (#1 tag),
adamc@1045 1382 xmlOpt), pos)
adamc@758 1383 else if et = "entry" then
adamc@758 1384 (EApp ((EVar (["Basis"], "entry", Infer), pos),
adamc@1045 1385 xmlOpt), pos)
adamc@141 1386 else
adamc@1045 1387 (EApp (#2 tag, xmlOpt), pos)
adamc@141 1388 else
adamc@325 1389 (if ErrorMsg.anyErrors () then
adamc@325 1390 ()
adamc@325 1391 else
adamc@1189 1392 ErrorMsg.errorAt pos ("Begin tag <"
adamc@1189 1393 ^ #1 (#1 tag)
adamc@1189 1394 ^ "> and end tag </"
adamc@1189 1395 ^ et
adamc@1189 1396 ^ "> don't match.");
adamc@623 1397 (EWild, pos))
adamc@141 1398 end)
adamc@141 1399 | LBRACE eexp RBRACE (eexp)
adamc@391 1400 | LBRACE LBRACK eexp RBRACK RBRACE (let
adamc@391 1401 val loc = s (LBRACEleft, RBRACEright)
adamc@403 1402 val e = (EVar (["Top"], "txt", Infer), loc)
adamc@391 1403 in
adamc@391 1404 (EApp (e, eexp), loc)
adamc@391 1405 end)
adamc@92 1406
adamc@141 1407 tag : tagHead attrs (let
adamc@141 1408 val pos = s (tagHeadleft, attrsright)
adamc@721 1409
adamc@721 1410 val e = (EVar (["Basis"], "tag", Infer), pos)
adamc@721 1411 val eo = case #1 attrs of
adamc@721 1412 NONE => (EVar (["Basis"], "None", Infer), pos)
adamc@721 1413 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos),
adamc@721 1414 e), pos)
adamc@721 1415 val e = (EApp (e, eo), pos)
adamc@721 1416 val e = (EApp (e, (ERecord (#2 attrs), pos)), pos)
adamc@721 1417 val e = (EApp (e, (EApp (#2 tagHead,
adamc@721 1418 (ERecord [], pos)), pos)), pos)
adamc@141 1419 in
adamc@756 1420 (tagHead, e)
adamc@141 1421 end)
adamc@141 1422
adamc@141 1423 tagHead: BEGIN_TAG (let
adamc@325 1424 val bt = tagIn BEGIN_TAG
adamc@141 1425 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
adamc@141 1426 in
adamc@325 1427 (bt,
adamc@473 1428 (EVar (["Basis"], bt, Infer), pos))
adamc@141 1429 end)
adamc@141 1430 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
adamc@92 1431
adamc@721 1432 attrs : (NONE, [])
adamc@721 1433 | attr attrs (let
adamc@721 1434 val loc = s (attrleft, attrsright)
adamc@721 1435 in
adamc@721 1436 case attr of
adamc@721 1437 Class e =>
adamc@721 1438 (case #1 attrs of
adamc@721 1439 NONE => ()
adamc@721 1440 | SOME _ => ErrorMsg.errorAt loc "Multiple classes specified for tag";
adamc@721 1441 (SOME e, #2 attrs))
adamc@721 1442 | Normal xe =>
adamc@721 1443 (#1 attrs, xe :: #2 attrs)
adamc@721 1444 end)
adamc@104 1445
adamc@721 1446 attr : SYMBOL EQ attrv (if SYMBOL = "class" then
adamc@721 1447 Class attrv
adamc@717 1448 else
adamc@724 1449 let
adamc@724 1450 val sym =
adamc@724 1451 case SYMBOL of
adamc@724 1452 "type" => "Typ"
adamc@724 1453 | x => capitalize x
adamc@724 1454 in
adamc@724 1455 Normal ((CName sym, s (SYMBOLleft, SYMBOLright)),
adamc@724 1456 if (sym = "Href" orelse sym = "Src")
adamc@724 1457 andalso (case #1 attrv of
adamc@724 1458 EPrim _ => true
adamc@724 1459 | _ => false) then
adamc@724 1460 let
adamc@724 1461 val loc = s (attrvleft, attrvright)
adamc@724 1462 in
adamc@724 1463 (EApp ((EVar (["Basis"], "bless", Infer), loc),
adamc@724 1464 attrv), loc)
adamc@724 1465 end
adamc@724 1466 else
adamc@724 1467 attrv)
adamc@724 1468 end)
adamc@204 1469
adamc@104 1470 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@104 1471 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@104 1472 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@110 1473 | LBRACE eexp RBRACE (eexp)
adamc@226 1474
adamc@232 1475 query : query1 obopt lopt ofopt (let
adamc@229 1476 val loc = s (query1left, query1right)
adamc@230 1477
adamc@230 1478 val re = (ERecord [((CName "Rows", loc),
adamc@230 1479 query1),
adamc@230 1480 ((CName "OrderBy", loc),
adamc@231 1481 obopt),
adamc@231 1482 ((CName "Limit", loc),
adamc@232 1483 lopt),
adamc@232 1484 ((CName "Offset", loc),
adamc@232 1485 ofopt)], loc)
adamc@229 1486 in
adamc@403 1487 (EApp ((EVar (["Basis"], "sql_query", Infer), loc), re), loc)
adamc@229 1488 end)
adamc@993 1489
adamc@993 1490 dopt : (EVar (["Basis"], "False", Infer), dummy)
adamc@993 1491 | DISTINCT (EVar (["Basis"], "True", Infer),
adamc@993 1492 s (DISTINCTleft, DISTINCTright))
adamc@993 1493
adamc@993 1494 query1 : SELECT dopt select FROM tables wopt gopt hopt
adamc@209 1495 (let
adamc@204 1496 val loc = s (SELECTleft, tablesright)
adamc@207 1497
adamc@1070 1498 val (empties, sel, exps) =
adamc@207 1499 case select of
adamc@1070 1500 Star => ([],
adamc@1070 1501 map (fn nm =>
adamc@233 1502 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
adamc@233 1503 loc),
adamc@233 1504 (CRecord [], loc)],
adamc@748 1505 loc))) (#1 tables),
adamc@233 1506 [])
adamc@207 1507 | Items sis =>
adamc@207 1508 let
adamc@748 1509 val tabs = map (fn nm => (nm, (CRecord [], loc))) (#1 tables)
adamc@1194 1510 val (_, tabs, exps) = foldl (amend_select loc)
adamc@1194 1511 (1, tabs, []) sis
adamc@1070 1512 val empties = List.mapPartial (fn (nm, (CRecord [], _)) =>
adamc@1070 1513 SOME nm
adamc@1070 1514 | _ => NONE) tabs
adamc@207 1515 in
adamc@1070 1516 (empties,
adamc@1070 1517 map (fn (nm, c) => (nm,
adamc@233 1518 (CTuple [c,
adamc@233 1519 (CWild (KRecord (KType, loc), loc),
adamc@233 1520 loc)], loc))) tabs,
adamc@233 1521 exps)
adamc@207 1522 end
adamc@207 1523
adamc@207 1524 val sel = (CRecord sel, loc)
adamc@207 1525
adamc@226 1526 val grp = case gopt of
adamc@403 1527 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all",
adamc@403 1528 Infer), loc),
adamc@226 1529 (CWild (KRecord (KRecord (KType, loc), loc),
adamc@226 1530 loc), loc)), loc)
adamc@226 1531 | SOME gis =>
adamc@226 1532 let
adamc@748 1533 val tabs = map (fn nm =>
adamc@748 1534 (nm, (CRecord [], loc))) (#1 tables)
adamc@226 1535 val tabs = foldl (amend_group loc) tabs gis
adamc@226 1536
adamc@226 1537 val tabs = map (fn (nm, c) =>
adamc@226 1538 (nm,
adamc@226 1539 (CTuple [c,
adamc@226 1540 (CWild (KRecord (KType, loc),
adamc@226 1541 loc),
adamc@226 1542 loc)], loc))) tabs
adamc@226 1543 in
adamc@403 1544 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@226 1545 (CRecord tabs, loc)), loc)
adamc@226 1546 end
adamc@226 1547
adamc@403 1548 val e = (EVar (["Basis"], "sql_query1", Infer), loc)
adamc@1070 1549 val e = (ECApp (e, (CRecord (map (fn nm => (nm, (CUnit, loc))) empties),
adamc@1070 1550 loc)), loc)
adamc@993 1551 val re = (ERecord [((CName "Distinct", loc),
adamc@993 1552 dopt),
adamc@993 1553 ((CName "From", loc),
adamc@748 1554 #2 tables),
adamc@209 1555 ((CName "Where", loc),
adamc@223 1556 wopt),
adamc@224 1557 ((CName "GroupBy", loc),
adamc@226 1558 grp),
adamc@224 1559 ((CName "Having", loc),
adamc@224 1560 hopt),
adamc@223 1561 ((CName "SelectFields", loc),
adamc@403 1562 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@233 1563 sel), loc)),
adamc@233 1564 ((CName "SelectExps", loc),
adamc@233 1565 (ERecord exps, loc))], loc)
adamc@223 1566
adamc@209 1567 val e = (EApp (e, re), loc)
adamc@204 1568 in
adamc@207 1569 e
adamc@204 1570 end)
adamc@229 1571 | query1 UNION query1 (sql_relop ("union", query11, query12, s (query11left, query12right)))
adamc@229 1572 | query1 INTERSECT query1 (sql_relop ("intersect", query11, query12, s (query11left, query12right)))
adamc@229 1573 | query1 EXCEPT query1 (sql_relop ("except", query11, query12, s (query11left, query12right)))
adamc@1070 1574 | LBRACE LBRACE LBRACE eexp RBRACE RBRACE RBRACE (eexp)
adamc@204 1575
adamc@749 1576 tables : fitem (fitem)
adamc@749 1577 | fitem COMMA tables (let
adamc@749 1578 val loc = s (fitemleft, tablesright)
adamc@748 1579
adamc@748 1580 val e = (EVar (["Basis"], "sql_from_comma", Infer), loc)
adamc@749 1581 val e = (EApp (e, #2 fitem), loc)
adamc@748 1582 in
adamc@749 1583 (#1 fitem @ #1 tables,
adamc@748 1584 (EApp (e, #2 tables), loc))
adamc@748 1585 end)
adamc@204 1586
adamc@749 1587 fitem : table' ([#1 table'], #2 table')
adamc@1265 1588 | LBRACE LBRACE eexp RBRACE RBRACE (tnamesOf eexp, eexp)
adamc@749 1589 | fitem JOIN fitem ON sqlexp (let
adamc@749 1590 val loc = s (fitem1left, sqlexpright)
adamc@749 1591
adamc@749 1592 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1593 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1594 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1595 in
adamc@749 1596 (#1 fitem1 @ #1 fitem2,
adamc@749 1597 (EApp (e, sqlexp), loc))
adamc@749 1598 end)
adamc@749 1599 | fitem INNER JOIN fitem ON sqlexp (let
adamc@749 1600 val loc = s (fitem1left, sqlexpright)
adamc@749 1601
adamc@749 1602 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1603 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1604 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1605 in
adamc@749 1606 (#1 fitem1 @ #1 fitem2,
adamc@749 1607 (EApp (e, sqlexp), loc))
adamc@749 1608 end)
adamc@749 1609 | fitem CROSS JOIN fitem (let
adamc@749 1610 val loc = s (fitem1left, fitem2right)
adamc@749 1611
adamc@749 1612 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1613 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1614 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1615 val tru = sql_inject (EVar (["Basis"], "True", Infer), loc)
adamc@749 1616 in
adamc@749 1617 (#1 fitem1 @ #1 fitem2,
adamc@749 1618 (EApp (e, tru), loc))
adamc@749 1619 end)
adamc@750 1620 | fitem LEFT JOIN fitem ON sqlexp (let
adamc@750 1621 val loc = s (fitem1left, sqlexpright)
adamc@750 1622
adamc@750 1623 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
adamc@750 1624 val e = (EApp (e, #2 fitem1), loc)
adamc@750 1625 val e = (EApp (e, #2 fitem2), loc)
adamc@750 1626 in
adamc@750 1627 (#1 fitem1 @ #1 fitem2,
adamc@750 1628 (EApp (e, sqlexp), loc))
adamc@750 1629 end)
adamc@751 1630 | fitem LEFT OUTER JOIN fitem ON sqlexp (let
adamc@751 1631 val loc = s (fitem1left, sqlexpright)
adamc@751 1632
adamc@751 1633 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
adamc@751 1634 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1635 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1636 in
adamc@751 1637 (#1 fitem1 @ #1 fitem2,
adamc@751 1638 (EApp (e, sqlexp), loc))
adamc@751 1639 end)
adamc@751 1640 | fitem RIGHT JOIN fitem ON sqlexp (let
adamc@751 1641 val loc = s (fitem1left, sqlexpright)
adamc@751 1642
adamc@751 1643 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
adamc@751 1644 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1645 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1646 in
adamc@751 1647 (#1 fitem1 @ #1 fitem2,
adamc@751 1648 (EApp (e, sqlexp), loc))
adamc@751 1649 end)
adamc@751 1650 | fitem RIGHT OUTER JOIN fitem ON sqlexp (let
adamc@751 1651 val loc = s (fitem1left, sqlexpright)
adamc@751 1652
adamc@751 1653 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
adamc@751 1654 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1655 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1656 in
adamc@751 1657 (#1 fitem1 @ #1 fitem2,
adamc@751 1658 (EApp (e, sqlexp), loc))
adamc@751 1659 end)
adamc@751 1660 | fitem FULL JOIN fitem ON sqlexp (let
adamc@751 1661 val loc = s (fitem1left, sqlexpright)
adamc@751 1662
adamc@751 1663 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
adamc@751 1664 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1665 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1666 in
adamc@751 1667 (#1 fitem1 @ #1 fitem2,
adamc@751 1668 (EApp (e, sqlexp), loc))
adamc@751 1669 end)
adamc@751 1670 | fitem FULL OUTER JOIN fitem ON sqlexp (let
adamc@751 1671 val loc = s (fitem1left, sqlexpright)
adamc@751 1672
adamc@751 1673 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
adamc@751 1674 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1675 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1676 in
adamc@751 1677 (#1 fitem1 @ #1 fitem2,
adamc@751 1678 (EApp (e, sqlexp), loc))
adamc@751 1679 end)
adamc@1192 1680 | LPAREN query RPAREN AS tname (let
adamc@1192 1681 val loc = s (LPARENleft, RPARENright)
adamc@1192 1682
adamc@1192 1683 val e = (EVar (["Basis"], "sql_from_query", Infer), loc)
adamc@1192 1684 val e = (ECApp (e, tname), loc)
adamc@1192 1685 in
adamc@1192 1686 ([tname], (EApp (e, query), loc))
adamc@1192 1687 end)
adamc@749 1688
adamc@204 1689 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@204 1690 | LBRACE cexp RBRACE (cexp)
adamc@204 1691
adamc@243 1692 table : SYMBOL ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)),
adamc@403 1693 (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@403 1694 | SYMBOL AS tname (tname, (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@221 1695 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
adamc@207 1696
adamc@748 1697 table' : table (let
adamc@748 1698 val loc = s (tableleft, tableright)
adamc@748 1699 val e = (EVar (["Basis"], "sql_from_table", Infer), loc)
adamc@748 1700 val e = (ECApp (e, #1 table), loc)
adamc@748 1701 in
adamc@748 1702 (#1 table, (EApp (e, #2 table), loc))
adamc@748 1703 end)
adamc@748 1704
adamc@243 1705 tident : SYMBOL (CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@207 1706 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@221 1707 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
adamc@207 1708
adamc@207 1709 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@207 1710 | LBRACE cexp RBRACE (cexp)
adamc@207 1711
adamc@207 1712 seli : tident DOT fident (Field (tident, fident))
adamc@1194 1713 | sqlexp (Exp (NONE, sqlexp))
adamc@1194 1714 | sqlexp AS fident (Exp (SOME fident, sqlexp))
adamc@341 1715 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (Fields (tident, cexp))
adamc@207 1716
adamc@207 1717 selis : seli ([seli])
adamc@207 1718 | seli COMMA selis (seli :: selis)
adamc@207 1719
adamc@207 1720 select : STAR (Star)
adamc@207 1721 | selis (Items selis)
adamc@209 1722
adamc@403 1723 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", Infer),
adamc@209 1724 s (TRUEleft, TRUEright)))
adamc@403 1725 | FALSE (sql_inject (EVar (["Basis"], "False", Infer),
adamc@209 1726 s (FALSEleft, FALSEright)))
adamc@209 1727
adamc@222 1728 | INT (sql_inject (EPrim (Prim.Int INT),
adamc@222 1729 s (INTleft, INTright)))
adamc@222 1730 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
adamc@222 1731 s (FLOATleft, FLOATright)))
adamc@229 1732 | STRING (sql_inject (EPrim (Prim.String STRING),
adamc@229 1733 s (STRINGleft, STRINGright)))
adamc@441 1734 | CURRENT_TIMESTAMP (sql_nfunc ("current_timestamp",
adamc@441 1735 s (CURRENT_TIMESTAMPleft, CURRENT_TIMESTAMPright)))
adamc@222 1736
adamc@221 1737 | tident DOT fident (let
adamc@221 1738 val loc = s (tidentleft, fidentright)
adamc@403 1739 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@221 1740 val e = (ECApp (e, tident), loc)
adamc@221 1741 in
adamc@221 1742 (ECApp (e, fident), loc)
adamc@221 1743 end)
adamc@234 1744 | CSYMBOL (let
adamc@234 1745 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@310 1746 in
adamc@310 1747 if !inDml then
adamc@310 1748 let
adamc@403 1749 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@310 1750 val e = (ECApp (e, (CName "T", loc)), loc)
adamc@310 1751 in
adamc@310 1752 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1753 end
adamc@310 1754 else
adamc@310 1755 let
adamc@403 1756 val e = (EVar (["Basis"], "sql_exp", Infer), loc)
adamc@310 1757 in
adamc@310 1758 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1759 end
adamc@310 1760 end)
adamc@221 1761
adamc@471 1762 | LBRACE eexp RBRACE (eexp)
adamc@470 1763
adamc@559 1764 | sqlexp EQ sqlexp (sql_binary ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1765 | sqlexp NE sqlexp (sql_binary ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1766 | sqlexp LT sqlexp (sql_binary ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1767 | sqlexp LE sqlexp (sql_binary ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1768 | sqlexp GT sqlexp (sql_binary ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1769 | sqlexp GE sqlexp (sql_binary ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1770
adamc@559 1771 | sqlexp PLUS sqlexp (sql_binary ("plus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1772 | sqlexp MINUS sqlexp (sql_binary ("minus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1773 | sqlexp STAR sqlexp (sql_binary ("times", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1774 | sqlexp DIVIDE sqlexp (sql_binary ("div", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1775 | sqlexp MOD sqlexp (sql_binary ("mod", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1776
adamc@220 1777 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@220 1778 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1779
adamc@220 1780 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
adamc@559 1781 | MINUS sqlexp (sql_unary ("neg", sqlexp, s (MINUSleft, sqlexpright)))
adamc@220 1782
adamc@470 1783 | sqlexp IS NULL (let
adamc@470 1784 val loc = s (sqlexpleft, NULLright)
adamc@470 1785 in
adamc@470 1786 (EApp ((EVar (["Basis"], "sql_is_null", Infer), loc),
adamc@470 1787 sqlexp), loc)
adamc@470 1788 end)
adamc@470 1789
adamc@471 1790 | LBRACE LBRACK eexp RBRACK RBRACE (sql_inject (#1 eexp,
adamc@471 1791 s (LBRACEleft, RBRACEright)))
adamc@220 1792 | LPAREN sqlexp RPAREN (sqlexp)
adamc@210 1793
adamc@467 1794 | NULL (sql_inject ((EVar (["Basis"], "None", Infer),
adamc@467 1795 s (NULLleft, NULLright))))
adamc@467 1796
adamc@235 1797 | COUNT LPAREN STAR RPAREN (let
adamc@235 1798 val loc = s (COUNTleft, RPARENright)
adamc@235 1799 in
adamc@544 1800 (EVar (["Basis"], "sql_count", Infer), loc)
adamc@235 1801 end)
adamc@1187 1802 | COUNT LPAREN sqlexp RPAREN (let
adamc@1187 1803 val loc = s (COUNTleft, RPARENright)
adamc@1187 1804
adamc@1187 1805 val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
adamc@1187 1806 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
adamc@1187 1807 e), loc)
adamc@1187 1808 in
adamc@1187 1809 (EApp (e, sqlexp), loc)
adamc@1187 1810 end)
adamc@236 1811 | sqlagg LPAREN sqlexp RPAREN (let
adamc@236 1812 val loc = s (sqlaggleft, RPARENright)
adamc@236 1813
adamc@403 1814 val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
adamc@403 1815 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
adamc@236 1816 e), loc)
adamc@236 1817 in
adamc@236 1818 (EApp (e, sqlexp), loc)
adamc@236 1819 end)
adamc@746 1820 | fname LPAREN sqlexp RPAREN (let
adamc@746 1821 val loc = s (fnameleft, RPARENright)
adamc@746 1822
adamc@746 1823 val e = (EVar (["Basis"], "sql_ufunc", Infer), loc)
adamc@746 1824 val e = (EApp (e, fname), loc)
adamc@746 1825 in
adamc@746 1826 (EApp (e, sqlexp), loc)
adamc@746 1827 end)
adamc@1191 1828 | LPAREN query RPAREN (let
adamc@1191 1829 val loc = s (LPARENleft, RPARENright)
adamc@1191 1830
adamc@1191 1831 val e = (EVar (["Basis"], "sql_subquery", Infer), loc)
adamc@1191 1832 in
adamc@1191 1833 (EApp (e, query), loc)
adamc@1191 1834 end)
adamc@746 1835
adamc@746 1836 fname : SYMBOL (EVar (["Basis"], "sql_" ^ SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
adamc@746 1837 | LBRACE eexp RBRACE (eexp)
adamc@235 1838
adamc@403 1839 wopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 1840 dummy))
adamc@209 1841 | CWHERE sqlexp (sqlexp)
adamc@226 1842
adamc@226 1843 groupi : tident DOT fident (GField (tident, fident))
adamc@226 1844
adamc@226 1845 groupis: groupi ([groupi])
adamc@226 1846 | groupi COMMA groupis (groupi :: groupis)
adamc@226 1847
adamc@226 1848 gopt : (NONE)
adamc@226 1849 | GROUP BY groupis (SOME groupis)
adamc@227 1850
adamc@403 1851 hopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 1852 dummy))
adamc@227 1853 | HAVING sqlexp (sqlexp)
adamc@230 1854
adamc@403 1855 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
adamc@234 1856 (CWild (KRecord (KType, dummy), dummy), dummy)),
adamc@230 1857 dummy)
adamc@230 1858 | ORDER BY obexps (obexps)
adamc@230 1859
adamc@268 1860 obitem : sqlexp diropt (sqlexp, diropt)
adamc@268 1861
adamc@268 1862 obexps : obitem (let
adamc@268 1863 val loc = s (obitemleft, obitemright)
adamc@230 1864
adamc@403 1865 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), loc),
adamc@234 1866 (CWild (KRecord (KType, loc), loc), loc)),
adamc@230 1867 loc)
adamc@403 1868 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 1869 #1 obitem), loc)
adamc@268 1870 val e = (EApp (e, #2 obitem), loc)
adamc@230 1871 in
adamc@230 1872 (EApp (e, e'), loc)
adamc@230 1873 end)
adamc@268 1874 | obitem COMMA obexps (let
adamc@268 1875 val loc = s (obitemleft, obexpsright)
adamc@230 1876
adamc@403 1877 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 1878 #1 obitem), loc)
adamc@268 1879 val e = (EApp (e, #2 obitem), loc)
adamc@230 1880 in
adamc@230 1881 (EApp (e, obexps), loc)
adamc@230 1882 end)
adamc@231 1883
adamc@403 1884 diropt : (EVar (["Basis"], "sql_asc", Infer), dummy)
adamc@403 1885 | ASC (EVar (["Basis"], "sql_asc", Infer), s (ASCleft, ASCright))
adamc@403 1886 | DESC (EVar (["Basis"], "sql_desc", Infer), s (DESCleft, DESCright))
adamc@268 1887
adamc@403 1888 lopt : (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@403 1889 | LIMIT ALL (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@231 1890 | LIMIT sqlint (let
adamc@231 1891 val loc = s (LIMITleft, sqlintright)
adamc@231 1892 in
adamc@403 1893 (EApp ((EVar (["Basis"], "sql_limit", Infer), loc), sqlint), loc)
adamc@231 1894 end)
adamc@231 1895
adamc@403 1896 ofopt : (EVar (["Basis"], "sql_no_offset", Infer), dummy)
adamc@232 1897 | OFFSET sqlint (let
adamc@232 1898 val loc = s (OFFSETleft, sqlintright)
adamc@232 1899 in
adamc@403 1900 (EApp ((EVar (["Basis"], "sql_offset", Infer), loc), sqlint), loc)
adamc@232 1901 end)
adamc@232 1902
adamc@231 1903 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@231 1904 | LBRACE eexp RBRACE (eexp)
adamc@236 1905
adamc@236 1906 sqlagg : AVG ("avg")
adamc@236 1907 | SUM ("sum")
adamc@236 1908 | MIN ("min")
adamc@236 1909 | MAX ("max")