annotate src/urweb.grm @ 1574:644558d9c756

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