annotate src/urweb.grm @ 1446:36f7d1debb37

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