annotate src/urweb.grm @ 760:21f6d2e65685

Megaform test
author Adam Chlipala <adamc@hcoop.net>
date Thu, 30 Apr 2009 14:43:55 -0400
parents 8323c1beef2e
children 9021d44ba6b2
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@434 936 bind : SYMBOL LARROW eapps (SYMBOL, NONE, eapps)
adamc@434 937 | UNIT LARROW eapps (let
adamc@434 938 val loc = s (UNITleft, eappsright)
adamc@434 939 in
adamc@434 940 ("_", SOME (TRecord (CRecord [], loc), loc), eapps)
adamc@434 941 end)
adamc@434 942 | eapps (let
adamc@434 943 val loc = s (eappsleft, eappsright)
adamc@434 944 in
adamc@434 945 ("_", SOME (TRecord (CRecord [], loc), loc), eapps)
adamc@434 946 end)
adamc@434 947
adamc@241 948 eargs : earg (earg)
adamc@241 949 | eargl (eargl)
adamc@241 950
adamc@241 951 eargl : eargp eargp (eargp1 o eargp2)
adamc@241 952 | eargp eargl (eargp o eargl)
adamc@241 953
adamc@242 954 eargl2 : (fn x => x)
adamc@242 955 | eargp eargl2 (eargp o eargl2)
adamc@242 956
adamc@241 957 earg : SYMBOL kcolon kind (fn (e, t) =>
adamc@241 958 let
adamc@241 959 val loc = s (SYMBOLleft, kindright)
adamc@241 960 in
adamc@241 961 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
adamc@241 962 (TCFun (kcolon, SYMBOL, kind, t), loc))
adamc@241 963 end)
adamc@241 964 | SYMBOL COLON cexp (fn (e, t) =>
adamc@241 965 let
adamc@241 966 val loc = s (SYMBOLleft, cexpright)
adamc@241 967 in
adamc@241 968 ((EAbs (SYMBOL, SOME cexp, e), loc),
adamc@241 969 (TFun (cexp, t), loc))
adamc@241 970 end)
adamc@241 971 | UNDER COLON cexp (fn (e, t) =>
adamc@241 972 let
adamc@241 973 val loc = s (UNDERleft, cexpright)
adamc@241 974 in
adamc@241 975 ((EAbs ("_", SOME cexp, e), loc),
adamc@241 976 (TFun (cexp, t), loc))
adamc@241 977 end)
adamc@241 978 | eargp (eargp)
adamc@241 979
adamc@241 980 eargp : SYMBOL (fn (e, t) =>
adamc@241 981 let
adamc@241 982 val loc = s (SYMBOLleft, SYMBOLright)
adamc@241 983 in
adamc@241 984 ((EAbs (SYMBOL, NONE, e), loc),
adamc@241 985 (TFun ((CWild (KType, loc), loc), t), loc))
adamc@241 986 end)
adamc@241 987 | UNIT (fn (e, t) =>
adamc@241 988 let
adamc@241 989 val loc = s (UNITleft, UNITright)
adamc@241 990 val t' = (TRecord (CRecord [], loc), loc)
adamc@241 991 in
adamc@241 992 ((EAbs ("_", SOME t', e), loc),
adamc@241 993 (TFun (t', t), loc))
adamc@241 994 end)
adamc@241 995 | UNDER (fn (e, t) =>
adamc@241 996 let
adamc@241 997 val loc = s (UNDERleft, UNDERright)
adamc@241 998 in
adamc@241 999 ((EAbs ("_", NONE, e), loc),
adamc@241 1000 (TFun ((CWild (KType, loc), loc), t), loc))
adamc@241 1001 end)
adamc@241 1002 | LPAREN SYMBOL kcolon kind RPAREN(fn (e, t) =>
adamc@241 1003 let
adamc@241 1004 val loc = s (LPARENleft, RPARENright)
adamc@241 1005 in
adamc@241 1006 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
adamc@241 1007 (TCFun (kcolon, SYMBOL, kind, t), loc))
adamc@241 1008 end)
adamc@241 1009 | LPAREN SYMBOL COLON cexp RPAREN (fn (e, t) =>
adamc@241 1010 let
adamc@241 1011 val loc = s (LPARENleft, RPARENright)
adamc@241 1012 in
adamc@241 1013 ((EAbs (SYMBOL, SOME cexp, e), loc),
adamc@241 1014 (TFun (cexp, t), loc))
adamc@241 1015 end)
adamc@241 1016 | LPAREN UNDER COLON cexp RPAREN (fn (e, t) =>
adamc@241 1017 let
adamc@241 1018 val loc = s (LPARENleft, RPARENright)
adamc@241 1019 in
adamc@241 1020 ((EAbs ("_", SOME cexp, e), loc),
adamc@241 1021 (TFun (cexp, t), loc))
adamc@241 1022 end)
adamc@478 1023 | LPAREN cexp TWIDDLE cexp RPAREN (fn (e, t) =>
adamc@354 1024 let
adamc@354 1025 val loc = s (LPARENleft, RPARENright)
adamc@354 1026 in
adamc@478 1027 ((EDisjoint (cexp1, cexp2, e), loc),
adamc@628 1028 (TDisjoint (cexp1, cexp2, t), loc))
adamc@354 1029 end)
adamc@478 1030 | LBRACK cexp TWIDDLE cexp RBRACK(fn (e, t) =>
adamc@356 1031 let
adamc@356 1032 val loc = s (LBRACKleft, RBRACKright)
adamc@356 1033 in
adamc@478 1034 ((EDisjoint (cexp1, cexp2, e), loc),
adamc@628 1035 (TDisjoint (cexp1, cexp2, t), loc))
adamc@356 1036 end)
adamc@623 1037 | CSYMBOL (fn (e, t) =>
adamc@623 1038 let
adamc@623 1039 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@623 1040 in
adamc@623 1041 ((EKAbs (CSYMBOL, e), loc),
adamc@623 1042 (TKFun (CSYMBOL, t), loc))
adamc@623 1043 end)
adamc@241 1044
adamc@8 1045 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
adamc@195 1046 | LPAREN etuple RPAREN (let
adamc@195 1047 val loc = s (LPARENleft, RPARENright)
adamc@195 1048 in
adamc@195 1049 (ERecord (ListUtil.mapi (fn (i, e) =>
adamc@195 1050 ((CName (Int.toString (i + 1)), loc),
adamc@195 1051 e)) etuple), loc)
adamc@195 1052 end)
adamc@8 1053
adamc@403 1054 | path (EVar (#1 path, #2 path, Infer), s (pathleft, pathright))
adamc@403 1055 | cpath (EVar (#1 cpath, #2 cpath, Infer), s (cpathleft, cpathright))
adamc@403 1056 | AT path (EVar (#1 path, #2 path, TypesOnly), s (ATleft, pathright))
adamc@403 1057 | AT AT path (EVar (#1 path, #2 path, DontInfer), s (AT1left, pathright))
adamc@403 1058 | AT cpath (EVar (#1 cpath, #2 cpath, TypesOnly), s (ATleft, cpathright))
adamc@403 1059 | AT AT cpath (EVar (#1 cpath, #2 cpath, DontInfer), s (AT1left, cpathright))
adamc@12 1060 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
adamc@110 1061 | UNIT (ERecord [], s (UNITleft, UNITright))
adamc@12 1062
adamc@14 1063 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@14 1064 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@14 1065 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@14 1066
adamc@200 1067 | path DOT idents (let
adamc@200 1068 val loc = s (pathleft, identsright)
adamc@200 1069 in
adamc@200 1070 foldl (fn (ident, e) =>
adamc@200 1071 (EField (e, ident), loc))
adamc@403 1072 (EVar (#1 path, #2 path, Infer), s (pathleft, pathright)) idents
adamc@403 1073 end)
adamc@403 1074 | AT path DOT idents (let
adamc@403 1075 val loc = s (ATleft, identsright)
adamc@403 1076 in
adamc@403 1077 foldl (fn (ident, e) =>
adamc@403 1078 (EField (e, ident), loc))
adamc@403 1079 (EVar (#1 path, #2 path, TypesOnly), s (pathleft, pathright)) idents
adamc@403 1080 end)
adamc@403 1081 | AT AT path DOT idents (let
adamc@403 1082 val loc = s (AT1left, identsright)
adamc@403 1083 in
adamc@403 1084 foldl (fn (ident, e) =>
adamc@403 1085 (EField (e, ident), loc))
adamc@403 1086 (EVar (#1 path, #2 path, DontInfer), s (pathleft, pathright)) idents
adamc@200 1087 end)
adamc@71 1088
adamc@360 1089 | XML_BEGIN xml XML_END (let
adamc@360 1090 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 1091 in
adamc@360 1092 if XML_BEGIN = "xml" then
adamc@360 1093 ()
adamc@360 1094 else
adamc@360 1095 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@360 1096 xml
adamc@360 1097 end)
adamc@360 1098 | XML_BEGIN XML_END (let
adamc@360 1099 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 1100 in
adamc@360 1101 if XML_BEGIN = "xml" then
adamc@360 1102 ()
adamc@360 1103 else
adamc@360 1104 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@403 1105 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
adamc@360 1106 (EPrim (Prim.String ""), loc)),
adamc@360 1107 loc)
adamc@360 1108 end)
adamc@360 1109 | XML_BEGIN_END (let
adamc@360 1110 val loc = s (XML_BEGIN_ENDleft, XML_BEGIN_ENDright)
adamc@360 1111 in
adamc@360 1112 if XML_BEGIN_END = "xml" then
adamc@360 1113 ()
adamc@360 1114 else
adamc@360 1115 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@403 1116 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
adamc@360 1117 (EPrim (Prim.String ""), loc)),
adamc@360 1118 loc)
adamc@360 1119 end)
adamc@302 1120
adamc@204 1121 | LPAREN query RPAREN (query)
adamc@300 1122 | LPAREN CWHERE sqlexp RPAREN (sqlexp)
adamc@339 1123 | LPAREN SQL sqlexp RPAREN (sqlexp)
adamc@302 1124
adamc@302 1125 | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN
adamc@302 1126 (let
adamc@302 1127 val loc = s (LPAREN1left, RPAREN3right)
adamc@302 1128
adamc@403 1129 val e = (EVar (["Basis"], "insert", Infer), loc)
adamc@302 1130 val e = (EApp (e, texp), loc)
adamc@302 1131 in
adamc@302 1132 if length fields <> length sqlexps then
adamc@302 1133 ErrorMsg.errorAt loc "Length mismatch in INSERT field specification"
adamc@302 1134 else
adamc@302 1135 ();
adamc@302 1136 (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
adamc@302 1137 end)
adamc@310 1138 | LPAREN enterDml UPDATE texp SET fsets CWHERE sqlexp leaveDml RPAREN
adamc@303 1139 (let
adamc@303 1140 val loc = s (LPARENleft, RPARENright)
adamc@303 1141
adamc@403 1142 val e = (EVar (["Basis"], "update", Infer), loc)
adamc@342 1143 val e = (ECApp (e, (CWild (KRecord (KType, loc), loc), loc)), loc)
adamc@632 1144 val e = (EDisjointApp e, loc)
adamc@306 1145 val e = (EApp (e, (ERecord fsets, loc)), loc)
adamc@305 1146 val e = (EApp (e, texp), loc)
adamc@303 1147 in
adamc@303 1148 (EApp (e, sqlexp), loc)
adamc@303 1149 end)
adamc@310 1150 | LPAREN enterDml DELETE FROM texp CWHERE sqlexp leaveDml RPAREN
adamc@304 1151 (let
adamc@304 1152 val loc = s (LPARENleft, RPARENright)
adamc@304 1153
adamc@403 1154 val e = (EVar (["Basis"], "delete", Infer), loc)
adamc@304 1155 val e = (EApp (e, texp), loc)
adamc@304 1156 in
adamc@304 1157 (EApp (e, sqlexp), loc)
adamc@304 1158 end)
adamc@302 1159
adamc@211 1160 | UNDER (EWild, s (UNDERleft, UNDERright))
adamc@91 1161
adamc@446 1162 | LET edecls IN eexp END (ELet (edecls, eexp), s (LETleft, ENDright))
adamc@446 1163
adamc@446 1164 edecls : ([])
adamc@446 1165 | edecl edecls (edecl :: edecls)
adamc@446 1166
adamc@446 1167 edecl : VAL vali ((EDVal vali, s (VALleft, valiright)))
adamc@446 1168 | VAL REC valis ((EDValRec valis, s (VALleft, valisright)))
adamc@446 1169 | FUN valis ((EDValRec valis, s (FUNleft, valisright)))
adamc@446 1170
adamc@310 1171 enterDml : (inDml := true)
adamc@310 1172 leaveDml : (inDml := false)
adamc@310 1173
adamc@403 1174 texp : SYMBOL (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
adamc@302 1175 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
adamc@302 1176
adamc@302 1177 fields : fident ([fident])
adamc@302 1178 | fident COMMA fields (fident :: fields)
adamc@302 1179
adamc@302 1180 sqlexps: sqlexp ([sqlexp])
adamc@302 1181 | sqlexp COMMA sqlexps (sqlexp :: sqlexps)
adamc@302 1182
adamc@303 1183 fsets : fident EQ sqlexp ([(fident, sqlexp)])
adamc@303 1184 | fident EQ sqlexp COMMA fsets ((fident, sqlexp) :: fsets)
adamc@303 1185
adamc@200 1186 idents : ident ([ident])
adamc@200 1187 | ident DOT idents (ident :: idents)
adamc@200 1188
adamc@195 1189 etuple : eexp COMMA eexp ([eexp1, eexp2])
adamc@195 1190 | eexp COMMA etuple (eexp :: etuple)
adamc@195 1191
adamc@170 1192 branch : pat DARROW eexp (pat, eexp)
adamc@170 1193
adamc@170 1194 branchs: ([])
adamc@170 1195 | BAR branch branchs (branch :: branchs)
adamc@170 1196
adamc@170 1197 pat : pterm (pterm)
adamc@170 1198 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
adamc@170 1199
adamc@170 1200 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
adamc@170 1201 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
adamc@170 1202 | UNDER (PWild, s (UNDERleft, UNDERright))
adamc@173 1203 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
adamc@173 1204 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@170 1205 | LPAREN pat RPAREN (pat)
adamc@174 1206 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
adamc@174 1207 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
adamc@174 1208 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
adamc@195 1209 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
adamc@195 1210 false),
adamc@195 1211 s (LPARENleft, RPARENright))
adamc@174 1212
adamc@175 1213 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
adamc@243 1214 | INT EQ pat ([(Int64.toString INT, pat)], false)
adamc@174 1215 | DOTDOTDOT ([], true)
adamc@175 1216 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
adamc@243 1217 | INT EQ pat COMMA rpat ((Int64.toString INT, pat) :: #1 rpat, #2 rpat)
adamc@170 1218
adamc@195 1219 ptuple : pat COMMA pat ([pat1, pat2])
adamc@195 1220 | pat COMMA ptuple (pat :: ptuple)
adamc@195 1221
adamc@12 1222 rexp : ([])
adamc@12 1223 | ident EQ eexp ([(ident, eexp)])
adamc@12 1224 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
adamc@91 1225
adamc@141 1226 xml : xmlOne xml (let
adamc@141 1227 val pos = s (xmlOneleft, xmlright)
adamc@141 1228 in
adamc@720 1229 (EApp ((EApp (
adamc@720 1230 (EVar (["Basis"], "join", Infer), pos),
adamc@720 1231 xmlOne), pos),
adamc@720 1232 xml), pos)
adamc@141 1233 end)
adamc@141 1234 | xmlOne (xmlOne)
adamc@91 1235
adamc@403 1236 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata", Infer), s (NOTAGSleft, NOTAGSright)),
adamc@141 1237 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
adamc@141 1238 s (NOTAGSleft, NOTAGSright))
adamc@141 1239 | tag DIVIDE GT (let
adamc@141 1240 val pos = s (tagleft, GTright)
adamc@710 1241
adamc@710 1242 val cdata =
adamc@756 1243 if #1 (#1 tag) = "submit" orelse #1 (#1 tag) = "dyn" then
adamc@710 1244 let
adamc@710 1245 val e = (EVar (["Basis"], "cdata", DontInfer), pos)
adamc@710 1246 val e = (ECApp (e, (CWild (KWild, pos), pos)), pos)
adamc@710 1247 in
adamc@710 1248 (ECApp (e, (CRecord [], pos)), pos)
adamc@710 1249 end
adamc@710 1250 else
adamc@710 1251 (EVar (["Basis"], "cdata", Infer), pos)
adamc@710 1252
adamc@710 1253 val cdata = (EApp (cdata,
adamc@710 1254 (EPrim (Prim.String ""), pos)),
adamc@710 1255 pos)
adamc@141 1256 in
adamc@710 1257 (EApp (#2 tag, cdata), pos)
adamc@141 1258 end)
adamc@141 1259
adamc@141 1260 | tag GT xml END_TAG (let
adamc@141 1261 val pos = s (tagleft, GTright)
adamc@325 1262 val et = tagIn END_TAG
adamc@141 1263 in
adamc@756 1264 if #1 (#1 tag) = et then
adamc@361 1265 if et = "form" then
adamc@403 1266 (EApp ((EVar (["Basis"], "form", Infer), pos),
adamc@141 1267 xml), pos)
adamc@756 1268 else if et = "subform" then
adamc@756 1269 (EApp ((EDisjointApp (#2 (#1 tag)), pos),
adamc@756 1270 xml), pos)
adamc@758 1271 else if et = "subforms" then
adamc@758 1272 (EApp ((EDisjointApp (#2 (#1 tag)), pos),
adamc@758 1273 xml), pos)
adamc@758 1274 else if et = "entry" then
adamc@758 1275 (EApp ((EVar (["Basis"], "entry", Infer), pos),
adamc@758 1276 xml), pos)
adamc@141 1277 else
adamc@141 1278 (EApp (#2 tag, xml), pos)
adamc@141 1279 else
adamc@325 1280 (if ErrorMsg.anyErrors () then
adamc@325 1281 ()
adamc@325 1282 else
adamc@325 1283 ErrorMsg.errorAt pos "Begin and end tags don't match.";
adamc@623 1284 (EWild, pos))
adamc@141 1285 end)
adamc@141 1286 | LBRACE eexp RBRACE (eexp)
adamc@391 1287 | LBRACE LBRACK eexp RBRACK RBRACE (let
adamc@391 1288 val loc = s (LBRACEleft, RBRACEright)
adamc@403 1289 val e = (EVar (["Top"], "txt", Infer), loc)
adamc@391 1290 in
adamc@391 1291 (EApp (e, eexp), loc)
adamc@391 1292 end)
adamc@92 1293
adamc@141 1294 tag : tagHead attrs (let
adamc@141 1295 val pos = s (tagHeadleft, attrsright)
adamc@721 1296
adamc@721 1297 val e = (EVar (["Basis"], "tag", Infer), pos)
adamc@721 1298 val eo = case #1 attrs of
adamc@721 1299 NONE => (EVar (["Basis"], "None", Infer), pos)
adamc@721 1300 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos),
adamc@721 1301 e), pos)
adamc@721 1302 val e = (EApp (e, eo), pos)
adamc@721 1303 val e = (EApp (e, (ERecord (#2 attrs), pos)), pos)
adamc@721 1304 val e = (EApp (e, (EApp (#2 tagHead,
adamc@721 1305 (ERecord [], pos)), pos)), pos)
adamc@141 1306 in
adamc@756 1307 (tagHead, e)
adamc@141 1308 end)
adamc@141 1309
adamc@141 1310 tagHead: BEGIN_TAG (let
adamc@325 1311 val bt = tagIn BEGIN_TAG
adamc@141 1312 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
adamc@141 1313 in
adamc@325 1314 (bt,
adamc@473 1315 (EVar (["Basis"], bt, Infer), pos))
adamc@141 1316 end)
adamc@141 1317 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
adamc@92 1318
adamc@721 1319 attrs : (NONE, [])
adamc@721 1320 | attr attrs (let
adamc@721 1321 val loc = s (attrleft, attrsright)
adamc@721 1322 in
adamc@721 1323 case attr of
adamc@721 1324 Class e =>
adamc@721 1325 (case #1 attrs of
adamc@721 1326 NONE => ()
adamc@721 1327 | SOME _ => ErrorMsg.errorAt loc "Multiple classes specified for tag";
adamc@721 1328 (SOME e, #2 attrs))
adamc@721 1329 | Normal xe =>
adamc@721 1330 (#1 attrs, xe :: #2 attrs)
adamc@721 1331 end)
adamc@104 1332
adamc@721 1333 attr : SYMBOL EQ attrv (if SYMBOL = "class" then
adamc@721 1334 Class attrv
adamc@717 1335 else
adamc@724 1336 let
adamc@724 1337 val sym =
adamc@724 1338 case SYMBOL of
adamc@724 1339 "type" => "Typ"
adamc@724 1340 | x => capitalize x
adamc@724 1341 in
adamc@724 1342 Normal ((CName sym, s (SYMBOLleft, SYMBOLright)),
adamc@724 1343 if (sym = "Href" orelse sym = "Src")
adamc@724 1344 andalso (case #1 attrv of
adamc@724 1345 EPrim _ => true
adamc@724 1346 | _ => false) then
adamc@724 1347 let
adamc@724 1348 val loc = s (attrvleft, attrvright)
adamc@724 1349 in
adamc@724 1350 (EApp ((EVar (["Basis"], "bless", Infer), loc),
adamc@724 1351 attrv), loc)
adamc@724 1352 end
adamc@724 1353 else
adamc@724 1354 attrv)
adamc@724 1355 end)
adamc@204 1356
adamc@104 1357 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@104 1358 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@104 1359 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@110 1360 | LBRACE eexp RBRACE (eexp)
adamc@226 1361
adamc@232 1362 query : query1 obopt lopt ofopt (let
adamc@229 1363 val loc = s (query1left, query1right)
adamc@230 1364
adamc@230 1365 val re = (ERecord [((CName "Rows", loc),
adamc@230 1366 query1),
adamc@230 1367 ((CName "OrderBy", loc),
adamc@231 1368 obopt),
adamc@231 1369 ((CName "Limit", loc),
adamc@232 1370 lopt),
adamc@232 1371 ((CName "Offset", loc),
adamc@232 1372 ofopt)], loc)
adamc@229 1373 in
adamc@403 1374 (EApp ((EVar (["Basis"], "sql_query", Infer), loc), re), loc)
adamc@229 1375 end)
adamc@204 1376
adamc@227 1377 query1 : SELECT select FROM tables wopt gopt hopt
adamc@209 1378 (let
adamc@204 1379 val loc = s (SELECTleft, tablesright)
adamc@207 1380
adamc@233 1381 val (sel, exps) =
adamc@207 1382 case select of
adamc@748 1383 Star => (map (fn nm =>
adamc@233 1384 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
adamc@233 1385 loc),
adamc@233 1386 (CRecord [], loc)],
adamc@748 1387 loc))) (#1 tables),
adamc@233 1388 [])
adamc@207 1389 | Items sis =>
adamc@207 1390 let
adamc@748 1391 val tabs = map (fn nm => (nm, (CRecord [], loc))) (#1 tables)
adamc@233 1392 val (tabs, exps) = foldl (amend_select loc) (tabs, []) sis
adamc@207 1393 in
adamc@233 1394 (map (fn (nm, c) => (nm,
adamc@233 1395 (CTuple [c,
adamc@233 1396 (CWild (KRecord (KType, loc), loc),
adamc@233 1397 loc)], loc))) tabs,
adamc@233 1398 exps)
adamc@207 1399 end
adamc@207 1400
adamc@207 1401 val sel = (CRecord sel, loc)
adamc@207 1402
adamc@226 1403 val grp = case gopt of
adamc@403 1404 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all",
adamc@403 1405 Infer), loc),
adamc@226 1406 (CWild (KRecord (KRecord (KType, loc), loc),
adamc@226 1407 loc), loc)), loc)
adamc@226 1408 | SOME gis =>
adamc@226 1409 let
adamc@748 1410 val tabs = map (fn nm =>
adamc@748 1411 (nm, (CRecord [], loc))) (#1 tables)
adamc@226 1412 val tabs = foldl (amend_group loc) tabs gis
adamc@226 1413
adamc@226 1414 val tabs = map (fn (nm, c) =>
adamc@226 1415 (nm,
adamc@226 1416 (CTuple [c,
adamc@226 1417 (CWild (KRecord (KType, loc),
adamc@226 1418 loc),
adamc@226 1419 loc)], loc))) tabs
adamc@226 1420 in
adamc@403 1421 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@226 1422 (CRecord tabs, loc)), loc)
adamc@226 1423 end
adamc@226 1424
adamc@403 1425 val e = (EVar (["Basis"], "sql_query1", Infer), loc)
adamc@209 1426 val re = (ERecord [((CName "From", loc),
adamc@748 1427 #2 tables),
adamc@209 1428 ((CName "Where", loc),
adamc@223 1429 wopt),
adamc@224 1430 ((CName "GroupBy", loc),
adamc@226 1431 grp),
adamc@224 1432 ((CName "Having", loc),
adamc@224 1433 hopt),
adamc@223 1434 ((CName "SelectFields", loc),
adamc@403 1435 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@233 1436 sel), loc)),
adamc@233 1437 ((CName "SelectExps", loc),
adamc@233 1438 (ERecord exps, loc))], loc)
adamc@223 1439
adamc@209 1440 val e = (EApp (e, re), loc)
adamc@204 1441 in
adamc@207 1442 e
adamc@204 1443 end)
adamc@229 1444 | query1 UNION query1 (sql_relop ("union", query11, query12, s (query11left, query12right)))
adamc@229 1445 | query1 INTERSECT query1 (sql_relop ("intersect", query11, query12, s (query11left, query12right)))
adamc@229 1446 | query1 EXCEPT query1 (sql_relop ("except", query11, query12, s (query11left, query12right)))
adamc@204 1447
adamc@749 1448 tables : fitem (fitem)
adamc@749 1449 | fitem COMMA tables (let
adamc@749 1450 val loc = s (fitemleft, tablesright)
adamc@748 1451
adamc@748 1452 val e = (EVar (["Basis"], "sql_from_comma", Infer), loc)
adamc@749 1453 val e = (EApp (e, #2 fitem), loc)
adamc@748 1454 in
adamc@749 1455 (#1 fitem @ #1 tables,
adamc@748 1456 (EApp (e, #2 tables), loc))
adamc@748 1457 end)
adamc@204 1458
adamc@749 1459 fitem : table' ([#1 table'], #2 table')
adamc@749 1460 | fitem JOIN fitem ON sqlexp (let
adamc@749 1461 val loc = s (fitem1left, sqlexpright)
adamc@749 1462
adamc@749 1463 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1464 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1465 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1466 in
adamc@749 1467 (#1 fitem1 @ #1 fitem2,
adamc@749 1468 (EApp (e, sqlexp), loc))
adamc@749 1469 end)
adamc@749 1470 | fitem INNER JOIN fitem ON sqlexp (let
adamc@749 1471 val loc = s (fitem1left, sqlexpright)
adamc@749 1472
adamc@749 1473 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1474 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1475 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1476 in
adamc@749 1477 (#1 fitem1 @ #1 fitem2,
adamc@749 1478 (EApp (e, sqlexp), loc))
adamc@749 1479 end)
adamc@749 1480 | fitem CROSS JOIN fitem (let
adamc@749 1481 val loc = s (fitem1left, fitem2right)
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 val tru = sql_inject (EVar (["Basis"], "True", Infer), loc)
adamc@749 1487 in
adamc@749 1488 (#1 fitem1 @ #1 fitem2,
adamc@749 1489 (EApp (e, tru), loc))
adamc@749 1490 end)
adamc@750 1491 | fitem LEFT JOIN fitem ON sqlexp (let
adamc@750 1492 val loc = s (fitem1left, sqlexpright)
adamc@750 1493
adamc@750 1494 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
adamc@750 1495 val e = (EApp (e, #2 fitem1), loc)
adamc@750 1496 val e = (EApp (e, #2 fitem2), loc)
adamc@750 1497 in
adamc@750 1498 (#1 fitem1 @ #1 fitem2,
adamc@750 1499 (EApp (e, sqlexp), loc))
adamc@750 1500 end)
adamc@751 1501 | fitem LEFT OUTER JOIN fitem ON sqlexp (let
adamc@751 1502 val loc = s (fitem1left, sqlexpright)
adamc@751 1503
adamc@751 1504 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
adamc@751 1505 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1506 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1507 in
adamc@751 1508 (#1 fitem1 @ #1 fitem2,
adamc@751 1509 (EApp (e, sqlexp), loc))
adamc@751 1510 end)
adamc@751 1511 | fitem RIGHT JOIN fitem ON sqlexp (let
adamc@751 1512 val loc = s (fitem1left, sqlexpright)
adamc@751 1513
adamc@751 1514 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
adamc@751 1515 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1516 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1517 in
adamc@751 1518 (#1 fitem1 @ #1 fitem2,
adamc@751 1519 (EApp (e, sqlexp), loc))
adamc@751 1520 end)
adamc@751 1521 | fitem RIGHT 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_right_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 FULL JOIN fitem ON sqlexp (let
adamc@751 1532 val loc = s (fitem1left, sqlexpright)
adamc@751 1533
adamc@751 1534 val e = (EVar (["Basis"], "sql_full_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 FULL 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_full_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@749 1551
adamc@204 1552 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@204 1553 | LBRACE cexp RBRACE (cexp)
adamc@204 1554
adamc@243 1555 table : SYMBOL ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)),
adamc@403 1556 (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@403 1557 | SYMBOL AS tname (tname, (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@221 1558 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
adamc@207 1559
adamc@748 1560 table' : table (let
adamc@748 1561 val loc = s (tableleft, tableright)
adamc@748 1562 val e = (EVar (["Basis"], "sql_from_table", Infer), loc)
adamc@748 1563 val e = (ECApp (e, #1 table), loc)
adamc@748 1564 in
adamc@748 1565 (#1 table, (EApp (e, #2 table), loc))
adamc@748 1566 end)
adamc@748 1567
adamc@243 1568 tident : SYMBOL (CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@207 1569 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@221 1570 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
adamc@207 1571
adamc@207 1572 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@207 1573 | LBRACE cexp RBRACE (cexp)
adamc@207 1574
adamc@207 1575 seli : tident DOT fident (Field (tident, fident))
adamc@233 1576 | sqlexp AS fident (Exp (fident, sqlexp))
adamc@341 1577 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (Fields (tident, cexp))
adamc@207 1578
adamc@207 1579 selis : seli ([seli])
adamc@207 1580 | seli COMMA selis (seli :: selis)
adamc@207 1581
adamc@207 1582 select : STAR (Star)
adamc@207 1583 | selis (Items selis)
adamc@209 1584
adamc@403 1585 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", Infer),
adamc@209 1586 s (TRUEleft, TRUEright)))
adamc@403 1587 | FALSE (sql_inject (EVar (["Basis"], "False", Infer),
adamc@209 1588 s (FALSEleft, FALSEright)))
adamc@209 1589
adamc@222 1590 | INT (sql_inject (EPrim (Prim.Int INT),
adamc@222 1591 s (INTleft, INTright)))
adamc@222 1592 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
adamc@222 1593 s (FLOATleft, FLOATright)))
adamc@229 1594 | STRING (sql_inject (EPrim (Prim.String STRING),
adamc@229 1595 s (STRINGleft, STRINGright)))
adamc@441 1596 | CURRENT_TIMESTAMP (sql_nfunc ("current_timestamp",
adamc@441 1597 s (CURRENT_TIMESTAMPleft, CURRENT_TIMESTAMPright)))
adamc@222 1598
adamc@221 1599 | tident DOT fident (let
adamc@221 1600 val loc = s (tidentleft, fidentright)
adamc@403 1601 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@221 1602 val e = (ECApp (e, tident), loc)
adamc@221 1603 in
adamc@221 1604 (ECApp (e, fident), loc)
adamc@221 1605 end)
adamc@234 1606 | CSYMBOL (let
adamc@234 1607 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@310 1608 in
adamc@310 1609 if !inDml then
adamc@310 1610 let
adamc@403 1611 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@310 1612 val e = (ECApp (e, (CName "T", loc)), loc)
adamc@310 1613 in
adamc@310 1614 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1615 end
adamc@310 1616 else
adamc@310 1617 let
adamc@403 1618 val e = (EVar (["Basis"], "sql_exp", Infer), loc)
adamc@310 1619 in
adamc@310 1620 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1621 end
adamc@310 1622 end)
adamc@221 1623
adamc@471 1624 | LBRACE eexp RBRACE (eexp)
adamc@470 1625
adamc@559 1626 | sqlexp EQ sqlexp (sql_binary ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1627 | sqlexp NE sqlexp (sql_binary ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1628 | sqlexp LT sqlexp (sql_binary ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1629 | sqlexp LE sqlexp (sql_binary ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1630 | sqlexp GT sqlexp (sql_binary ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1631 | sqlexp GE sqlexp (sql_binary ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1632
adamc@559 1633 | sqlexp PLUS sqlexp (sql_binary ("plus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1634 | sqlexp MINUS sqlexp (sql_binary ("minus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1635 | sqlexp STAR sqlexp (sql_binary ("times", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1636 | sqlexp DIVIDE sqlexp (sql_binary ("div", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1637 | sqlexp MOD sqlexp (sql_binary ("mod", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1638
adamc@220 1639 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@220 1640 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 1641
adamc@220 1642 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
adamc@559 1643 | MINUS sqlexp (sql_unary ("neg", sqlexp, s (MINUSleft, sqlexpright)))
adamc@220 1644
adamc@470 1645 | sqlexp IS NULL (let
adamc@470 1646 val loc = s (sqlexpleft, NULLright)
adamc@470 1647 in
adamc@470 1648 (EApp ((EVar (["Basis"], "sql_is_null", Infer), loc),
adamc@470 1649 sqlexp), loc)
adamc@470 1650 end)
adamc@470 1651
adamc@471 1652 | LBRACE LBRACK eexp RBRACK RBRACE (sql_inject (#1 eexp,
adamc@471 1653 s (LBRACEleft, RBRACEright)))
adamc@220 1654 | LPAREN sqlexp RPAREN (sqlexp)
adamc@210 1655
adamc@467 1656 | NULL (sql_inject ((EVar (["Basis"], "None", Infer),
adamc@467 1657 s (NULLleft, NULLright))))
adamc@467 1658
adamc@235 1659 | COUNT LPAREN STAR RPAREN (let
adamc@235 1660 val loc = s (COUNTleft, RPARENright)
adamc@235 1661 in
adamc@544 1662 (EVar (["Basis"], "sql_count", Infer), loc)
adamc@235 1663 end)
adamc@236 1664 | sqlagg LPAREN sqlexp RPAREN (let
adamc@236 1665 val loc = s (sqlaggleft, RPARENright)
adamc@236 1666
adamc@403 1667 val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
adamc@403 1668 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
adamc@236 1669 e), loc)
adamc@236 1670 in
adamc@236 1671 (EApp (e, sqlexp), loc)
adamc@236 1672 end)
adamc@746 1673 | fname LPAREN sqlexp RPAREN (let
adamc@746 1674 val loc = s (fnameleft, RPARENright)
adamc@746 1675
adamc@746 1676 val e = (EVar (["Basis"], "sql_ufunc", Infer), loc)
adamc@746 1677 val e = (EApp (e, fname), loc)
adamc@746 1678 in
adamc@746 1679 (EApp (e, sqlexp), loc)
adamc@746 1680 end)
adamc@746 1681
adamc@746 1682 fname : SYMBOL (EVar (["Basis"], "sql_" ^ SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
adamc@746 1683 | LBRACE eexp RBRACE (eexp)
adamc@235 1684
adamc@403 1685 wopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 1686 dummy))
adamc@209 1687 | CWHERE sqlexp (sqlexp)
adamc@226 1688
adamc@226 1689 groupi : tident DOT fident (GField (tident, fident))
adamc@226 1690
adamc@226 1691 groupis: groupi ([groupi])
adamc@226 1692 | groupi COMMA groupis (groupi :: groupis)
adamc@226 1693
adamc@226 1694 gopt : (NONE)
adamc@226 1695 | GROUP BY groupis (SOME groupis)
adamc@227 1696
adamc@403 1697 hopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 1698 dummy))
adamc@227 1699 | HAVING sqlexp (sqlexp)
adamc@230 1700
adamc@403 1701 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
adamc@234 1702 (CWild (KRecord (KType, dummy), dummy), dummy)),
adamc@230 1703 dummy)
adamc@230 1704 | ORDER BY obexps (obexps)
adamc@230 1705
adamc@268 1706 obitem : sqlexp diropt (sqlexp, diropt)
adamc@268 1707
adamc@268 1708 obexps : obitem (let
adamc@268 1709 val loc = s (obitemleft, obitemright)
adamc@230 1710
adamc@403 1711 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), loc),
adamc@234 1712 (CWild (KRecord (KType, loc), loc), loc)),
adamc@230 1713 loc)
adamc@403 1714 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 1715 #1 obitem), loc)
adamc@268 1716 val e = (EApp (e, #2 obitem), loc)
adamc@230 1717 in
adamc@230 1718 (EApp (e, e'), loc)
adamc@230 1719 end)
adamc@268 1720 | obitem COMMA obexps (let
adamc@268 1721 val loc = s (obitemleft, obexpsright)
adamc@230 1722
adamc@403 1723 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 1724 #1 obitem), loc)
adamc@268 1725 val e = (EApp (e, #2 obitem), loc)
adamc@230 1726 in
adamc@230 1727 (EApp (e, obexps), loc)
adamc@230 1728 end)
adamc@231 1729
adamc@403 1730 diropt : (EVar (["Basis"], "sql_asc", Infer), dummy)
adamc@403 1731 | ASC (EVar (["Basis"], "sql_asc", Infer), s (ASCleft, ASCright))
adamc@403 1732 | DESC (EVar (["Basis"], "sql_desc", Infer), s (DESCleft, DESCright))
adamc@268 1733
adamc@403 1734 lopt : (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@403 1735 | LIMIT ALL (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@231 1736 | LIMIT sqlint (let
adamc@231 1737 val loc = s (LIMITleft, sqlintright)
adamc@231 1738 in
adamc@403 1739 (EApp ((EVar (["Basis"], "sql_limit", Infer), loc), sqlint), loc)
adamc@231 1740 end)
adamc@231 1741
adamc@403 1742 ofopt : (EVar (["Basis"], "sql_no_offset", Infer), dummy)
adamc@232 1743 | OFFSET sqlint (let
adamc@232 1744 val loc = s (OFFSETleft, sqlintright)
adamc@232 1745 in
adamc@403 1746 (EApp ((EVar (["Basis"], "sql_offset", Infer), loc), sqlint), loc)
adamc@232 1747 end)
adamc@232 1748
adamc@231 1749 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@231 1750 | LBRACE eexp RBRACE (eexp)
adamc@236 1751
adamc@236 1752 sqlagg : AVG ("avg")
adamc@236 1753 | SUM ("sum")
adamc@236 1754 | MIN ("min")
adamc@236 1755 | MAX ("max")