annotate src/urweb.grm @ 1265:e8d68fd8ed4b

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