annotate src/urweb.grm @ 768:3b7e46790fa7

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