annotate src/urweb.grm @ 473:04b91c33ef54

Resolve all tag named in [Basis]; deal with C compilation failure without leaving /tmp files
author Adam Chlipala <adamc@hcoop.net>
date Sat, 08 Nov 2008 10:33:58 -0500
parents 20fab0e96217
children 6ee1c761818f
rev   line source
adamc@1 1 (* Copyright (c) 2008, 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@219 122 fun sql_compare (oper, sqlexp1, sqlexp2, loc) =
adamc@219 123 let
adamc@403 124 val e = (EVar (["Basis"], "sql_comparison", Infer), loc)
adamc@403 125 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adamc@219 126 val e = (EApp (e, sqlexp1), loc)
adamc@219 127 in
adamc@234 128 (EApp (e, sqlexp2), loc)
adamc@220 129 end
adamc@220 130
adamc@220 131 fun sql_binary (oper, sqlexp1, sqlexp2, loc) =
adamc@220 132 let
adamc@403 133 val e = (EVar (["Basis"], "sql_binary", Infer), loc)
adamc@403 134 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adamc@220 135 val e = (EApp (e, sqlexp1), loc)
adamc@220 136 in
adamc@220 137 (EApp (e, sqlexp2), loc)
adamc@220 138 end
adamc@220 139
adamc@220 140 fun sql_unary (oper, sqlexp, loc) =
adamc@220 141 let
adamc@403 142 val e = (EVar (["Basis"], "sql_unary", Infer), loc)
adamc@403 143 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adamc@220 144 in
adamc@220 145 (EApp (e, sqlexp), loc)
adamc@219 146 end
adamc@219 147
adamc@229 148 fun sql_relop (oper, sqlexp1, sqlexp2, loc) =
adamc@229 149 let
adamc@403 150 val e = (EVar (["Basis"], "sql_relop", Infer), loc)
adamc@403 151 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adamc@229 152 val e = (EApp (e, sqlexp1), loc)
adamc@229 153 in
adamc@229 154 (EApp (e, sqlexp2), loc)
adamc@229 155 end
adamc@229 156
adamc@441 157 fun sql_nfunc (oper, loc) =
adamc@441 158 let
adamc@441 159 val e = (EVar (["Basis"], "sql_nfunc", Infer), loc)
adamc@441 160 in
adamc@441 161 (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adamc@441 162 end
adamc@441 163
adamc@389 164 fun native_unop (oper, e1, loc) =
adamc@389 165 let
adamc@403 166 val e = (EVar (["Basis"], oper, Infer), loc)
adamc@389 167 in
adamc@389 168 (EApp (e, e1), loc)
adamc@389 169 end
adamc@389 170
adamc@256 171 fun native_op (oper, e1, e2, loc) =
adamc@256 172 let
adamc@403 173 val e = (EVar (["Basis"], oper, Infer), loc)
adamc@256 174 val e = (EApp (e, e1), loc)
adamc@256 175 in
adamc@256 176 (EApp (e, e2), loc)
adamc@256 177 end
adamc@256 178
adamc@310 179 val inDml = ref false
adamc@310 180
adamc@325 181 fun tagIn bt =
adamc@325 182 case bt of
adamc@325 183 "table" => "tabl"
adamc@325 184 | _ => bt
adamc@325 185
adamc@1 186 %%
adamc@244 187 %header (functor UrwebLrValsFn(structure Token : TOKEN))
adamc@1 188
adamc@1 189 %term
adamc@1 190 EOF
adamc@14 191 | STRING of string | INT of Int64.int | FLOAT of Real64.real
adamc@1 192 | SYMBOL of string | CSYMBOL of string
adamc@1 193 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
adamc@156 194 | EQ | COMMA | COLON | DCOLON | TCOLON | DOT | HASH | UNDER | UNDERUNDER | BAR
adamc@403 195 | PLUS | MINUS | DIVIDE | DOTDOTDOT | MOD | AT
adamc@242 196 | CON | LTYPE | VAL | REC | AND | FUN | FOLD | UNIT | KUNIT | CLASS
adamc@156 197 | DATATYPE | OF
adamc@7 198 | TYPE | NAME
adamc@243 199 | ARROW | LARROW | DARROW | STAR | SEMI
adamc@149 200 | FN | PLUSPLUS | MINUSMINUS | DOLLAR | TWIDDLE
adamc@446 201 | LET | IN
adamc@445 202 | STRUCTURE | SIGNATURE | STRUCT | SIG | END | FUNCTOR | WHERE | EXTERN | SQL
adamc@338 203 | INCLUDE | OPEN | CONSTRAINT | CONSTRAINTS | EXPORT | TABLE | SEQUENCE
adamc@459 204 | COOKIE
adamc@190 205 | CASE | IF | THEN | ELSE
adamc@1 206
adamc@360 207 | XML_BEGIN of string | XML_END | XML_BEGIN_END of string
adamc@91 208 | NOTAGS of string
adamc@91 209 | BEGIN_TAG of string | END_TAG of string
adamc@91 210
adamc@230 211 | SELECT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING
adamc@229 212 | UNION | INTERSECT | EXCEPT
adamc@232 213 | LIMIT | OFFSET | ALL
adamc@220 214 | TRUE | FALSE | CAND | OR | NOT
adamc@236 215 | COUNT | AVG | SUM | MIN | MAX
adamc@268 216 | ASC | DESC
adamc@470 217 | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS
adamc@441 218 | CURRENT_TIMESTAMP
adamc@219 219 | NE | LT | LE | GT | GE
adamc@204 220
adamc@30 221 %nonterm
adamc@1 222 file of decl list
adamc@1 223 | decls of decl list
adamc@325 224 | decl of decl list
adamc@123 225 | vali of string * con option * exp
adamc@123 226 | valis of (string * con option * exp) list
adamc@242 227 | copt of con option
adamc@1 228
adamc@191 229 | dargs of string list
adamc@156 230 | barOpt of unit
adamc@156 231 | dcons of (string * con option) list
adamc@156 232 | dcon of string * con option
adamc@156 233
adamc@30 234 | sgn of sgn
adamc@42 235 | sgntm of sgn
adamc@30 236 | sgi of sgn_item
adamc@30 237 | sgis of sgn_item list
adamc@30 238
adamc@30 239 | str of str
adamc@30 240
adamc@1 241 | kind of kind
adamc@207 242 | ktuple of kind list
adamc@1 243 | kcolon of explicitness
adamc@240 244 | kopt of kind option
adamc@1 245
adamc@34 246 | path of string list * string
adamc@156 247 | cpath of string list * string
adamc@34 248 | spath of str
adamc@59 249 | mpath of string list
adamc@34 250
adamc@1 251 | cexp of con
adamc@1 252 | capps of con
adamc@1 253 | cterm of con
adamc@195 254 | ctuple of con list
adamc@207 255 | ctuplev of con list
adamc@1 256 | ident of con
adamc@200 257 | idents of con list
adamc@1 258 | rcon of (con * con) list
adamc@83 259 | rconn of (con * con) list
adamc@1 260 | rcone of (con * con) list
adamc@239 261 | cargs of con * kind -> con * kind
adamc@239 262 | cargl of con * kind -> con * kind
adamc@240 263 | cargl2 of con * kind -> con * kind
adamc@239 264 | carg of con * kind -> con * kind
adamc@239 265 | cargp of con * kind -> con * kind
adamc@1 266
adamc@8 267 | eexp of exp
adamc@8 268 | eapps of exp
adamc@8 269 | eterm of exp
adamc@195 270 | etuple of exp list
adamc@12 271 | rexp of (con * exp) list
adamc@91 272 | xml of exp
adamc@91 273 | xmlOne of exp
adamc@141 274 | tag of string * exp
adamc@141 275 | tagHead of string * exp
adamc@434 276 | bind of string * con option * exp
adamc@446 277 | edecl of edecl
adamc@446 278 | edecls of edecl list
adamc@8 279
adamc@241 280 | earg of exp * con -> exp * con
adamc@241 281 | eargp of exp * con -> exp * con
adamc@241 282 | eargs of exp * con -> exp * con
adamc@241 283 | eargl of exp * con -> exp * con
adamc@242 284 | eargl2 of exp * con -> exp * con
adamc@241 285
adamc@170 286 | branch of pat * exp
adamc@170 287 | branchs of (pat * exp) list
adamc@170 288 | pat of pat
adamc@170 289 | pterm of pat
adamc@174 290 | rpat of (string * pat) list * bool
adamc@195 291 | ptuple of pat list
adamc@170 292
adamc@104 293 | attrs of (con * exp) list
adamc@104 294 | attr of con * exp
adamc@104 295 | attrv of exp
adamc@104 296
adamc@204 297 | query of exp
adamc@226 298 | query1 of exp
adamc@204 299 | tables of (con * exp) list
adamc@204 300 | tname of con
adamc@204 301 | table of con * exp
adamc@207 302 | tident of con
adamc@207 303 | fident of con
adamc@207 304 | seli of select_item
adamc@207 305 | selis of select_item list
adamc@207 306 | select of select
adamc@209 307 | sqlexp of exp
adamc@209 308 | wopt of exp
adamc@226 309 | groupi of group_item
adamc@226 310 | groupis of group_item list
adamc@226 311 | gopt of group_item list option
adamc@227 312 | hopt of exp
adamc@230 313 | obopt of exp
adamc@268 314 | obitem of exp * exp
adamc@230 315 | obexps of exp
adamc@268 316 | diropt of exp
adamc@231 317 | lopt of exp
adamc@232 318 | ofopt of exp
adamc@231 319 | sqlint of exp
adamc@236 320 | sqlagg of string
adamc@207 321
adamc@302 322 | texp of exp
adamc@302 323 | fields of con list
adamc@302 324 | sqlexps of exp list
adamc@303 325 | fsets of (con * exp) list
adamc@310 326 | enterDml of unit
adamc@310 327 | leaveDml of unit
adamc@302 328
adamc@204 329
adamc@1 330 %verbose (* print summary of errors *)
adamc@1 331 %pos int (* positions *)
adamc@1 332 %start file
adamc@1 333 %pure
adamc@1 334 %eop EOF
adamc@1 335 %noshift EOF
adamc@1 336
adamc@244 337 %name Urweb
adamc@1 338
adamc@243 339 %right SEMI
adamc@243 340 %nonassoc LARROW
adamc@195 341 %nonassoc IF THEN ELSE
adamc@1 342 %nonassoc DARROW
adamc@1 343 %nonassoc COLON
adamc@6 344 %nonassoc DCOLON TCOLON
adamc@229 345 %left UNION INTERSECT EXCEPT
adamc@1 346 %right COMMA
adamc@220 347 %right OR
adamc@220 348 %right CAND
adamc@470 349 %nonassoc EQ NE LT LE GT GE IS
adamc@243 350 %right ARROW
adamc@149 351 %right PLUSPLUS MINUSMINUS
adamc@389 352 %left PLUS MINUS
adamc@389 353 %left STAR DIVIDE MOD
adamc@220 354 %left NOT
adamc@84 355 %nonassoc TWIDDLE
adamc@1 356 %nonassoc DOLLAR
adamc@1 357 %left DOT
adamc@221 358 %nonassoc LBRACE RBRACE
adamc@1 359
adamc@1 360 %%
adamc@1 361
adamc@1 362 file : decls (decls)
adamc@54 363 | SIG sgis ([(DSgn ("?", (SgnConst sgis, s (SIGleft, sgisright))),
adamc@54 364 s (SIGleft, sgisright))])
adamc@1 365
adamc@1 366 decls : ([])
adamc@325 367 | decl decls (decl @ decls)
adamc@1 368
adamc@240 369 decl : CON SYMBOL cargl2 kopt EQ cexp (let
adamc@240 370 val loc = s (CONleft, cexpright)
adamc@240 371
adamc@240 372 val k = Option.getOpt (kopt, (KWild, loc))
adamc@240 373 val (c, k) = cargl2 (cexp, k)
adamc@240 374 in
adamc@325 375 [(DCon (SYMBOL, SOME k, c), loc)]
adamc@240 376 end)
adamc@325 377 | LTYPE SYMBOL EQ cexp ([(DCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
adamc@325 378 s (LTYPEleft, cexpright))])
adamc@325 379 | DATATYPE SYMBOL dargs EQ barOpt dcons([(DDatatype (SYMBOL, dargs, dcons), s (DATATYPEleft, dconsright))])
adamc@191 380 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
adamc@191 381 (case dargs of
adamc@325 382 [] => [(DDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))]
adamc@191 383 | _ => raise Fail "Arguments specified for imported datatype")
adamc@325 384 | VAL vali ([(DVal vali, s (VALleft, valiright))])
adamc@325 385 | VAL REC valis ([(DValRec valis, s (VALleft, valisright))])
adamc@325 386 | FUN valis ([(DValRec valis, s (FUNleft, valisright))])
adamc@1 387
adamc@325 388 | SIGNATURE CSYMBOL EQ sgn ([(DSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))])
adamc@325 389 | STRUCTURE CSYMBOL EQ str ([(DStr (CSYMBOL, NONE, str), s (STRUCTUREleft, strright))])
adamc@325 390 | STRUCTURE CSYMBOL COLON sgn EQ str ([(DStr (CSYMBOL, SOME sgn, str), s (STRUCTUREleft, strright))])
adamc@42 391 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN EQ str
adamc@325 392 ([(DStr (CSYMBOL1, NONE,
adamc@325 393 (StrFun (CSYMBOL2, sgn1, NONE, str), s (FUNCTORleft, strright))),
adamc@325 394 s (FUNCTORleft, strright))])
adamc@42 395 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn EQ str
adamc@325 396 ([(DStr (CSYMBOL1, NONE,
adamc@325 397 (StrFun (CSYMBOL2, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))),
adamc@325 398 s (FUNCTORleft, strright))])
adamc@325 399 | EXTERN STRUCTURE CSYMBOL COLON sgn ([(DFfiStr (CSYMBOL, sgn), s (EXTERNleft, sgnright))])
adamc@61 400 | OPEN mpath (case mpath of
adamc@61 401 [] => raise Fail "Impossible mpath parse [1]"
adamc@325 402 | m :: ms => [(DOpen (m, ms), s (OPENleft, mpathright))])
adamc@325 403 | OPEN mpath LPAREN str RPAREN (let
adamc@325 404 val loc = s (OPENleft, RPARENright)
adamc@325 405
adamc@325 406 val m = case mpath of
adamc@325 407 [] => raise Fail "Impossible mpath parse [4]"
adamc@325 408 | m :: ms =>
adamc@325 409 foldl (fn (m, str) => (StrProj (str, m), loc))
adamc@325 410 (StrVar m, loc) ms
adamc@325 411 in
adamc@325 412 [(DStr ("anon", NONE, (StrApp (m, str), loc)), loc),
adamc@325 413 (DOpen ("anon", []), loc)]
adamc@325 414 end)
adamc@88 415 | OPEN CONSTRAINTS mpath (case mpath of
adamc@88 416 [] => raise Fail "Impossible mpath parse [3]"
adamc@325 417 | m :: ms => [(DOpenConstraints (m, ms), s (OPENleft, mpathright))])
adamc@325 418 | CONSTRAINT cterm TWIDDLE cterm ([(DConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))])
adamc@325 419 | EXPORT spath ([(DExport spath, s (EXPORTleft, spathright))])
adamc@325 420 | TABLE SYMBOL COLON cexp ([(DTable (SYMBOL, entable cexp), s (TABLEleft, cexpright))])
adamc@338 421 | SEQUENCE SYMBOL ([(DSequence SYMBOL, s (SEQUENCEleft, SYMBOLright))])
adamc@325 422 | CLASS SYMBOL EQ cexp ([(DClass (SYMBOL, cexp), s (CLASSleft, cexpright))])
adamc@211 423 | CLASS SYMBOL SYMBOL EQ cexp (let
adamc@211 424 val loc = s (CLASSleft, cexpright)
adamc@211 425 val k = (KType, loc)
adamc@211 426 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
adamc@211 427 in
adamc@325 428 [(DClass (SYMBOL1, c), s (CLASSleft, cexpright))]
adamc@211 429 end)
adamc@459 430 | COOKIE SYMBOL COLON cexp ([(DCookie (SYMBOL, cexp), s (COOKIEleft, cexpright))])
adamc@30 431
adamc@240 432 kopt : (NONE)
adamc@240 433 | DCOLON kind (SOME kind)
adamc@240 434
adamc@191 435 dargs : ([])
adamc@191 436 | SYMBOL dargs (SYMBOL :: dargs)
adamc@191 437
adamc@156 438 barOpt : ()
adamc@156 439 | BAR ()
adamc@156 440
adamc@156 441 dcons : dcon ([dcon])
adamc@156 442 | dcon BAR dcons (dcon :: dcons)
adamc@156 443
adamc@156 444 dcon : CSYMBOL (CSYMBOL, NONE)
adamc@156 445 | CSYMBOL OF cexp (CSYMBOL, SOME cexp)
adamc@156 446
adamc@242 447 vali : SYMBOL eargl2 copt EQ eexp (let
adamc@242 448 val loc = s (SYMBOLleft, eexpright)
adamc@242 449 val t = Option.getOpt (copt, (CWild (KType, loc), loc))
adamc@242 450
adamc@242 451 val (e, t) = eargl2 (eexp, t)
adamc@242 452 in
adamc@242 453 (SYMBOL, SOME t, e)
adamc@242 454 end)
adamc@242 455
adamc@242 456 copt : (NONE)
adamc@242 457 | COLON cexp (SOME cexp)
adamc@123 458
adamc@123 459 valis : vali ([vali])
adamc@123 460 | vali AND valis (vali :: valis)
adamc@123 461
adamc@42 462 sgn : sgntm (sgntm)
adamc@40 463 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@40 464 (SgnFun (CSYMBOL, sgn1, sgn2), s (FUNCTORleft, sgn2right))
adamc@30 465
adamc@42 466 sgntm : SIG sgis END (SgnConst sgis, s (SIGleft, ENDright))
adamc@59 467 | mpath (case mpath of
adamc@61 468 [] => raise Fail "Impossible mpath parse [2]"
adamc@59 469 | [x] => SgnVar x
adamc@59 470 | m :: ms => SgnProj (m,
adamc@59 471 List.take (ms, length ms - 1),
adamc@59 472 List.nth (ms, length ms - 1)),
adamc@59 473 s (mpathleft, mpathright))
adamc@42 474 | sgntm WHERE CON SYMBOL EQ cexp (SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
adamc@42 475 | sgntm WHERE LTYPE SYMBOL EQ cexp(SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
adamc@42 476 | LPAREN sgn RPAREN (sgn)
adamc@42 477
adamc@30 478 sgi : CON SYMBOL DCOLON kind (SgiConAbs (SYMBOL, kind), s (CONleft, kindright))
adamc@30 479 | LTYPE SYMBOL (SgiConAbs (SYMBOL, (KType, s (LTYPEleft, SYMBOLright))),
adamc@30 480 s (LTYPEleft, SYMBOLright))
adamc@30 481 | CON SYMBOL EQ cexp (SgiCon (SYMBOL, NONE, cexp), s (CONleft, cexpright))
adamc@30 482 | CON SYMBOL DCOLON kind EQ cexp (SgiCon (SYMBOL, SOME kind, cexp), s (CONleft, cexpright))
adamc@30 483 | LTYPE SYMBOL EQ cexp (SgiCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
adamc@30 484 s (LTYPEleft, cexpright))
adamc@191 485 | DATATYPE SYMBOL dargs EQ barOpt dcons(SgiDatatype (SYMBOL, dargs, dcons), s (DATATYPEleft, dconsright))
adamc@191 486 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
adamc@191 487 (case dargs of
adamc@191 488 [] => (SgiDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
adamc@191 489 | _ => raise Fail "Arguments specified for imported datatype")
adamc@30 490 | VAL SYMBOL COLON cexp (SgiVal (SYMBOL, cexp), s (VALleft, cexpright))
adamc@30 491
adamc@30 492 | STRUCTURE CSYMBOL COLON sgn (SgiStr (CSYMBOL, sgn), s (STRUCTUREleft, sgnright))
adamc@59 493 | SIGNATURE CSYMBOL EQ sgn (SgiSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))
adamc@42 494 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@42 495 (SgiStr (CSYMBOL1,
adamc@42 496 (SgnFun (CSYMBOL2, sgn1, sgn2), s (FUNCTORleft, sgn2right))),
adamc@42 497 s (FUNCTORleft, sgn2right))
adamc@58 498 | INCLUDE sgn (SgiInclude sgn, s (INCLUDEleft, sgnright))
adamc@88 499 | CONSTRAINT cterm TWIDDLE cterm (SgiConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))
adamc@460 500 | TABLE SYMBOL COLON cexp (let
adamc@460 501 val loc = s (TABLEleft, cexpright)
adamc@460 502 val t = (CApp ((CVar (["Basis"], "sql_table"), loc),
adamc@460 503 entable cexp), loc)
adamc@460 504 in
adamc@460 505 (SgiVal (SYMBOL, t), loc)
adamc@460 506 end)
adamc@460 507 | SEQUENCE SYMBOL (let
adamc@460 508 val loc = s (SEQUENCEleft, SYMBOLright)
adamc@460 509 val t = (CVar (["Basis"], "sql_sequence"), loc)
adamc@460 510 in
adamc@460 511 (SgiVal (SYMBOL, t), loc)
adamc@460 512 end)
adamc@211 513 | CLASS SYMBOL (SgiClassAbs SYMBOL, s (CLASSleft, SYMBOLright))
adamc@211 514 | CLASS SYMBOL EQ cexp (SgiClass (SYMBOL, cexp), s (CLASSleft, cexpright))
adamc@211 515 | CLASS SYMBOL SYMBOL EQ cexp (let
adamc@211 516 val loc = s (CLASSleft, cexpright)
adamc@211 517 val k = (KType, loc)
adamc@211 518 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
adamc@211 519 in
adamc@211 520 (SgiClass (SYMBOL1, c), s (CLASSleft, cexpright))
adamc@211 521 end)
adamc@460 522 | COOKIE SYMBOL COLON cexp (let
adamc@460 523 val loc = s (COOKIEleft, cexpright)
adamc@460 524 val t = (CApp ((CVar (["Basis"], "http_cookie"), loc),
adamc@460 525 entable cexp), loc)
adamc@460 526 in
adamc@460 527 (SgiVal (SYMBOL, t), loc)
adamc@460 528 end)
adamc@30 529
adamc@30 530 sgis : ([])
adamc@30 531 | sgi sgis (sgi :: sgis)
adamc@30 532
adamc@30 533 str : STRUCT decls END (StrConst decls, s (STRUCTleft, ENDright))
adamc@34 534 | spath (spath)
adamc@40 535 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN DARROW str
adamc@40 536 (StrFun (CSYMBOL, sgn, NONE, str), s (FUNCTORleft, strright))
adamc@40 537 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn DARROW str
adamc@40 538 (StrFun (CSYMBOL, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))
adamc@44 539 | spath LPAREN str RPAREN (StrApp (spath, str), s (spathleft, RPARENright))
adamc@34 540
adamc@34 541 spath : CSYMBOL (StrVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@34 542 | spath DOT CSYMBOL (StrProj (spath, CSYMBOL), s (spathleft, CSYMBOLright))
adamc@30 543
adamc@1 544 kind : TYPE (KType, s (TYPEleft, TYPEright))
adamc@1 545 | NAME (KName, s (NAMEleft, NAMEright))
adamc@1 546 | LBRACE kind RBRACE (KRecord kind, s (LBRACEleft, RBRACEright))
adamc@1 547 | kind ARROW kind (KArrow (kind1, kind2), s (kind1left, kind2right))
adamc@1 548 | LPAREN kind RPAREN (#1 kind, s (LPARENleft, RPARENright))
adamc@82 549 | KUNIT (KUnit, s (KUNITleft, KUNITright))
adamc@18 550 | UNDERUNDER (KWild, s (UNDERUNDERleft, UNDERUNDERright))
adamc@207 551 | LPAREN ktuple RPAREN (KTuple ktuple, s (LPARENleft, RPARENright))
adamc@207 552
adamc@207 553 ktuple : kind STAR kind ([kind1, kind2])
adamc@207 554 | kind STAR ktuple (kind :: ktuple)
adamc@1 555
adamc@1 556 capps : cterm (cterm)
adamc@1 557 | capps cterm (CApp (capps, cterm), s (cappsleft, ctermright))
adamc@1 558
adamc@1 559 cexp : capps (capps)
adamc@1 560 | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right))
adamc@15 561 | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright))
adamc@1 562
adamc@1 563 | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right))
adamc@1 564
adamc@239 565 | FN cargs DARROW cexp (#1 (cargs (cexp, (KWild, s (FNleft, cexpright)))))
adamc@1 566
adamc@8 567 | LPAREN cexp RPAREN DCOLON kind (CAnnot (cexp, kind), s (LPARENleft, kindright))
adamc@6 568
adamc@18 569 | UNDER DCOLON kind (CWild kind, s (UNDERleft, UNDERright))
adamc@195 570 | ctuple (let
adamc@195 571 val loc = s (ctupleleft, ctupleright)
adamc@195 572 in
adamc@195 573 (TRecord (CRecord (ListUtil.mapi (fn (i, c) =>
adamc@195 574 ((CName (Int.toString (i + 1)), loc),
adamc@195 575 c)) ctuple),
adamc@195 576 loc), loc)
adamc@195 577 end)
adamc@18 578
adamc@1 579 kcolon : DCOLON (Explicit)
adamc@1 580 | TCOLON (Implicit)
adamc@1 581
adamc@239 582 cargs : carg (carg)
adamc@239 583 | cargl (cargl)
adamc@239 584
adamc@239 585 cargl : cargp cargp (cargp1 o cargp2)
adamc@239 586 | cargp cargl (cargp o cargl)
adamc@239 587
adamc@240 588 cargl2 : (fn x => x)
adamc@240 589 | cargp cargl2 (cargp o cargl2)
adamc@240 590
adamc@241 591 carg : SYMBOL DCOLON kind (fn (c, k) =>
adamc@239 592 let
adamc@239 593 val loc = s (SYMBOLleft, kindright)
adamc@239 594 in
adamc@239 595 ((CAbs (SYMBOL, SOME kind, c), loc),
adamc@239 596 (KArrow (kind, k), loc))
adamc@239 597 end)
adamc@329 598 | UNDER DCOLON kind (fn (c, k) =>
adamc@329 599 let
adamc@329 600 val loc = s (UNDERleft, kindright)
adamc@329 601 in
adamc@329 602 ((CAbs ("_", SOME kind, c), loc),
adamc@329 603 (KArrow (kind, k), loc))
adamc@329 604 end)
adamc@241 605 | cargp (cargp)
adamc@239 606
adamc@239 607 cargp : SYMBOL (fn (c, k) =>
adamc@239 608 let
adamc@239 609 val loc = s (SYMBOLleft, SYMBOLright)
adamc@239 610 in
adamc@239 611 ((CAbs (SYMBOL, NONE, c), loc),
adamc@239 612 (KArrow ((KWild, loc), k), loc))
adamc@239 613 end)
adamc@329 614 | UNDER (fn (c, k) =>
adamc@329 615 let
adamc@329 616 val loc = s (UNDERleft, UNDERright)
adamc@329 617 in
adamc@329 618 ((CAbs ("_", NONE, c), loc),
adamc@329 619 (KArrow ((KWild, loc), k), loc))
adamc@329 620 end)
adamc@239 621 | LPAREN SYMBOL DCOLON kind RPAREN (fn (c, k) =>
adamc@239 622 let
adamc@239 623 val loc = s (LPARENleft, RPARENright)
adamc@239 624 in
adamc@239 625 ((CAbs (SYMBOL, SOME kind, c), loc),
adamc@239 626 (KArrow (kind, k), loc))
adamc@239 627 end)
adamc@354 628 | LBRACK cterm TWIDDLE cterm RBRACK (fn (c, k) =>
adamc@354 629 let
adamc@354 630 val loc = s (LBRACKleft, RBRACKright)
adamc@354 631 in
adamc@354 632 ((CDisjoint (cterm1, cterm2, c), loc),
adamc@354 633 k)
adamc@354 634 end)
adamc@239 635
adamc@34 636 path : SYMBOL ([], SYMBOL)
adamc@34 637 | CSYMBOL DOT path (let val (ms, x) = path in (CSYMBOL :: ms, x) end)
adamc@34 638
adamc@156 639 cpath : CSYMBOL ([], CSYMBOL)
adamc@156 640 | CSYMBOL DOT cpath (let val (ms, x) = cpath in (CSYMBOL :: ms, x) end)
adamc@156 641
adamc@59 642 mpath : CSYMBOL ([CSYMBOL])
adamc@59 643 | CSYMBOL DOT mpath (CSYMBOL :: mpath)
adamc@59 644
adamc@1 645 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright))
adamc@1 646 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright))
adamc@83 647 | LBRACK rconn RBRACK (CRecord rconn, s (LBRACKleft, RBRACKright))
adamc@1 648 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)),
adamc@1 649 s (LBRACEleft, RBRACEright))
adamc@1 650 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright))
adamc@1 651 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright))
adamc@195 652 | HASH INT (CName (Int64.toString INT), s (HASHleft, INTright))
adamc@1 653
adamc@34 654 | path (CVar path, s (pathleft, pathright))
adamc@207 655 | path DOT INT (CProj ((CVar path, s (pathleft, pathright)), Int64.toInt INT),
adamc@207 656 s (pathleft, INTright))
adamc@18 657 | UNDER (CWild (KWild, s (UNDERleft, UNDERright)), s (UNDERleft, UNDERright))
adamc@67 658 | FOLD (CFold, s (FOLDleft, FOLDright))
adamc@82 659 | UNIT (CUnit, s (UNITleft, UNITright))
adamc@207 660 | LPAREN ctuplev RPAREN (CTuple ctuplev, s (LPARENleft, RPARENright))
adamc@207 661
adamc@207 662 ctuplev: cexp COMMA cexp ([cexp1, cexp2])
adamc@207 663 | cexp COMMA ctuplev (cexp :: ctuplev)
adamc@1 664
adamc@196 665 ctuple : capps STAR capps ([capps1, capps2])
adamc@196 666 | capps STAR ctuple (capps :: ctuple)
adamc@195 667
adamc@1 668 rcon : ([])
adamc@1 669 | ident EQ cexp ([(ident, cexp)])
adamc@1 670 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon)
adamc@1 671
adamc@83 672 rconn : ident ([(ident, (CUnit, s (identleft, identright)))])
adamc@83 673 | ident COMMA rconn ((ident, (CUnit, s (identleft, identright))) :: rconn)
adamc@83 674
adamc@1 675 rcone : ([])
adamc@1 676 | ident COLON cexp ([(ident, cexp)])
adamc@1 677 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone)
adamc@1 678
adamc@1 679 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@195 680 | INT (CName (Int64.toString INT), s (INTleft, INTright))
adamc@200 681 | SYMBOL (CVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@8 682
adamc@8 683 eapps : eterm (eterm)
adamc@8 684 | eapps eterm (EApp (eapps, eterm), s (eappsleft, etermright))
adamc@8 685 | eapps LBRACK cexp RBRACK (ECApp (eapps, cexp), s (eappsleft, RBRACKright))
adamc@8 686
adamc@8 687 eexp : eapps (eapps)
adamc@241 688 | FN eargs DARROW eexp (let
adamc@93 689 val loc = s (FNleft, eexpright)
adamc@93 690 in
adamc@241 691 #1 (eargs (eexp, (CWild (KType, loc), loc)))
adamc@93 692 end)
adamc@196 693 | eexp COLON cexp (EAnnot (eexp, cexp), s (eexpleft, cexpright))
adamc@149 694 | eexp MINUSMINUS cexp (ECut (eexp, cexp), s (eexpleft, cexpright))
adamc@170 695 | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
adamc@190 696 | IF eexp THEN eexp ELSE eexp (let
adamc@190 697 val loc = s (IFleft, eexp3right)
adamc@190 698 in
adamc@190 699 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc), eexp2),
adamc@190 700 ((PCon (["Basis"], "False", NONE), loc), eexp3)]), loc)
adamc@190 701 end)
adamc@434 702 | bind SEMI eexp (let
adamc@434 703 val loc = s (bindleft, eexpright)
adamc@434 704 val (v, to, e1) = bind
adamc@403 705 val e = (EVar (["Basis"], "bind", Infer), loc)
adamc@434 706 val e = (EApp (e, e1), loc)
adamc@243 707 in
adamc@434 708 (EApp (e, (EAbs (v, to, eexp), loc)), loc)
adamc@299 709 end)
adamc@256 710 | eexp EQ eexp (native_op ("eq", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@257 711 | eexp NE eexp (native_op ("ne", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 712 | MINUS eterm (native_unop ("neg", eterm, s (MINUSleft, etermright)))
adamc@389 713 | eexp PLUS eexp (native_op ("plus", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 714 | eexp MINUS eexp (native_op ("minus", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 715 | eterm STAR eexp (native_op ("times", eterm, eexp, s (etermleft, eexpright)))
adamc@389 716 | eexp DIVIDE eexp (native_op ("div", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 717 | eexp MOD eexp (native_op ("mod", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 718
adamc@391 719 | eexp LT eexp (native_op ("lt", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 720 | eexp LE eexp (native_op ("le", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 721 | eexp GT eexp (native_op ("gt", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 722 | eexp GE eexp (native_op ("ge", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 723
adamc@445 724 | eexp PLUSPLUS eexp (EConcat (eexp1, eexp2), s (eexp1left, eexp2right))
adamc@8 725
adamc@434 726 bind : SYMBOL LARROW eapps (SYMBOL, NONE, eapps)
adamc@434 727 | UNIT LARROW eapps (let
adamc@434 728 val loc = s (UNITleft, eappsright)
adamc@434 729 in
adamc@434 730 ("_", SOME (TRecord (CRecord [], loc), loc), eapps)
adamc@434 731 end)
adamc@434 732 | eapps (let
adamc@434 733 val loc = s (eappsleft, eappsright)
adamc@434 734 in
adamc@434 735 ("_", SOME (TRecord (CRecord [], loc), loc), eapps)
adamc@434 736 end)
adamc@434 737
adamc@241 738 eargs : earg (earg)
adamc@241 739 | eargl (eargl)
adamc@241 740
adamc@241 741 eargl : eargp eargp (eargp1 o eargp2)
adamc@241 742 | eargp eargl (eargp o eargl)
adamc@241 743
adamc@242 744 eargl2 : (fn x => x)
adamc@242 745 | eargp eargl2 (eargp o eargl2)
adamc@242 746
adamc@241 747 earg : SYMBOL kcolon kind (fn (e, t) =>
adamc@241 748 let
adamc@241 749 val loc = s (SYMBOLleft, kindright)
adamc@241 750 in
adamc@241 751 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
adamc@241 752 (TCFun (kcolon, SYMBOL, kind, t), loc))
adamc@241 753 end)
adamc@241 754 | SYMBOL COLON cexp (fn (e, t) =>
adamc@241 755 let
adamc@241 756 val loc = s (SYMBOLleft, cexpright)
adamc@241 757 in
adamc@241 758 ((EAbs (SYMBOL, SOME cexp, e), loc),
adamc@241 759 (TFun (cexp, t), loc))
adamc@241 760 end)
adamc@241 761 | UNDER COLON cexp (fn (e, t) =>
adamc@241 762 let
adamc@241 763 val loc = s (UNDERleft, cexpright)
adamc@241 764 in
adamc@241 765 ((EAbs ("_", SOME cexp, e), loc),
adamc@241 766 (TFun (cexp, t), loc))
adamc@241 767 end)
adamc@241 768 | eargp (eargp)
adamc@241 769
adamc@241 770 eargp : SYMBOL (fn (e, t) =>
adamc@241 771 let
adamc@241 772 val loc = s (SYMBOLleft, SYMBOLright)
adamc@241 773 in
adamc@241 774 ((EAbs (SYMBOL, NONE, e), loc),
adamc@241 775 (TFun ((CWild (KType, loc), loc), t), loc))
adamc@241 776 end)
adamc@241 777 | UNIT (fn (e, t) =>
adamc@241 778 let
adamc@241 779 val loc = s (UNITleft, UNITright)
adamc@241 780 val t' = (TRecord (CRecord [], loc), loc)
adamc@241 781 in
adamc@241 782 ((EAbs ("_", SOME t', e), loc),
adamc@241 783 (TFun (t', t), loc))
adamc@241 784 end)
adamc@241 785 | UNDER (fn (e, t) =>
adamc@241 786 let
adamc@241 787 val loc = s (UNDERleft, UNDERright)
adamc@241 788 in
adamc@241 789 ((EAbs ("_", NONE, e), loc),
adamc@241 790 (TFun ((CWild (KType, loc), loc), t), loc))
adamc@241 791 end)
adamc@241 792 | LPAREN SYMBOL kcolon kind RPAREN(fn (e, t) =>
adamc@241 793 let
adamc@241 794 val loc = s (LPARENleft, RPARENright)
adamc@241 795 in
adamc@241 796 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
adamc@241 797 (TCFun (kcolon, SYMBOL, kind, t), loc))
adamc@241 798 end)
adamc@241 799 | LPAREN SYMBOL COLON cexp RPAREN (fn (e, t) =>
adamc@241 800 let
adamc@241 801 val loc = s (LPARENleft, RPARENright)
adamc@241 802 in
adamc@241 803 ((EAbs (SYMBOL, SOME cexp, e), loc),
adamc@241 804 (TFun (cexp, t), loc))
adamc@241 805 end)
adamc@241 806 | LPAREN UNDER COLON cexp RPAREN (fn (e, t) =>
adamc@241 807 let
adamc@241 808 val loc = s (LPARENleft, RPARENright)
adamc@241 809 in
adamc@241 810 ((EAbs ("_", SOME cexp, e), loc),
adamc@241 811 (TFun (cexp, t), loc))
adamc@241 812 end)
adamc@354 813 | LPAREN cterm TWIDDLE cterm RPAREN(fn (e, t) =>
adamc@354 814 let
adamc@354 815 val loc = s (LPARENleft, RPARENright)
adamc@354 816 in
adamc@354 817 ((EDisjoint (cterm1, cterm2, e), loc),
adamc@354 818 (CDisjoint (cterm1, cterm2, t), loc))
adamc@354 819 end)
adamc@356 820 | LBRACK cterm TWIDDLE cterm RBRACK(fn (e, t) =>
adamc@356 821 let
adamc@356 822 val loc = s (LBRACKleft, RBRACKright)
adamc@356 823 in
adamc@356 824 ((EDisjoint (cterm1, cterm2, e), loc),
adamc@356 825 (CDisjoint (cterm1, cterm2, t), loc))
adamc@356 826 end)
adamc@241 827
adamc@8 828 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
adamc@195 829 | LPAREN etuple RPAREN (let
adamc@195 830 val loc = s (LPARENleft, RPARENright)
adamc@195 831 in
adamc@195 832 (ERecord (ListUtil.mapi (fn (i, e) =>
adamc@195 833 ((CName (Int.toString (i + 1)), loc),
adamc@195 834 e)) etuple), loc)
adamc@195 835 end)
adamc@8 836
adamc@403 837 | path (EVar (#1 path, #2 path, Infer), s (pathleft, pathright))
adamc@403 838 | cpath (EVar (#1 cpath, #2 cpath, Infer), s (cpathleft, cpathright))
adamc@403 839 | AT path (EVar (#1 path, #2 path, TypesOnly), s (ATleft, pathright))
adamc@403 840 | AT AT path (EVar (#1 path, #2 path, DontInfer), s (AT1left, pathright))
adamc@403 841 | AT cpath (EVar (#1 cpath, #2 cpath, TypesOnly), s (ATleft, cpathright))
adamc@403 842 | AT AT cpath (EVar (#1 cpath, #2 cpath, DontInfer), s (AT1left, cpathright))
adamc@12 843 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
adamc@110 844 | UNIT (ERecord [], s (UNITleft, UNITright))
adamc@12 845
adamc@14 846 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@14 847 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@14 848 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@14 849
adamc@200 850 | path DOT idents (let
adamc@200 851 val loc = s (pathleft, identsright)
adamc@200 852 in
adamc@200 853 foldl (fn (ident, e) =>
adamc@200 854 (EField (e, ident), loc))
adamc@403 855 (EVar (#1 path, #2 path, Infer), s (pathleft, pathright)) idents
adamc@403 856 end)
adamc@403 857 | AT path DOT idents (let
adamc@403 858 val loc = s (ATleft, identsright)
adamc@403 859 in
adamc@403 860 foldl (fn (ident, e) =>
adamc@403 861 (EField (e, ident), loc))
adamc@403 862 (EVar (#1 path, #2 path, TypesOnly), s (pathleft, pathright)) idents
adamc@403 863 end)
adamc@403 864 | AT AT path DOT idents (let
adamc@403 865 val loc = s (AT1left, identsright)
adamc@403 866 in
adamc@403 867 foldl (fn (ident, e) =>
adamc@403 868 (EField (e, ident), loc))
adamc@403 869 (EVar (#1 path, #2 path, DontInfer), s (pathleft, pathright)) idents
adamc@200 870 end)
adamc@71 871 | FOLD (EFold, s (FOLDleft, FOLDright))
adamc@71 872
adamc@360 873 | XML_BEGIN xml XML_END (let
adamc@360 874 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 875 in
adamc@360 876 if XML_BEGIN = "xml" then
adamc@360 877 ()
adamc@360 878 else
adamc@360 879 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@360 880 xml
adamc@360 881 end)
adamc@360 882 | XML_BEGIN XML_END (let
adamc@360 883 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 884 in
adamc@360 885 if XML_BEGIN = "xml" then
adamc@360 886 ()
adamc@360 887 else
adamc@360 888 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@403 889 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
adamc@360 890 (EPrim (Prim.String ""), loc)),
adamc@360 891 loc)
adamc@360 892 end)
adamc@360 893 | XML_BEGIN_END (let
adamc@360 894 val loc = s (XML_BEGIN_ENDleft, XML_BEGIN_ENDright)
adamc@360 895 in
adamc@360 896 if XML_BEGIN_END = "xml" then
adamc@360 897 ()
adamc@360 898 else
adamc@360 899 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@403 900 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
adamc@360 901 (EPrim (Prim.String ""), loc)),
adamc@360 902 loc)
adamc@360 903 end)
adamc@302 904
adamc@204 905 | LPAREN query RPAREN (query)
adamc@300 906 | LPAREN CWHERE sqlexp RPAREN (sqlexp)
adamc@339 907 | LPAREN SQL sqlexp RPAREN (sqlexp)
adamc@302 908
adamc@302 909 | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN
adamc@302 910 (let
adamc@302 911 val loc = s (LPAREN1left, RPAREN3right)
adamc@302 912
adamc@403 913 val e = (EVar (["Basis"], "insert", Infer), loc)
adamc@302 914 val e = (EApp (e, texp), loc)
adamc@302 915 in
adamc@302 916 if length fields <> length sqlexps then
adamc@302 917 ErrorMsg.errorAt loc "Length mismatch in INSERT field specification"
adamc@302 918 else
adamc@302 919 ();
adamc@302 920 (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
adamc@302 921 end)
adamc@310 922 | LPAREN enterDml UPDATE texp SET fsets CWHERE sqlexp leaveDml RPAREN
adamc@303 923 (let
adamc@303 924 val loc = s (LPARENleft, RPARENright)
adamc@303 925
adamc@403 926 val e = (EVar (["Basis"], "update", Infer), loc)
adamc@342 927 val e = (ECApp (e, (CWild (KRecord (KType, loc), loc), loc)), loc)
adamc@306 928 val e = (EApp (e, (ERecord fsets, loc)), loc)
adamc@305 929 val e = (EApp (e, texp), loc)
adamc@303 930 in
adamc@303 931 (EApp (e, sqlexp), loc)
adamc@303 932 end)
adamc@310 933 | LPAREN enterDml DELETE FROM texp CWHERE sqlexp leaveDml RPAREN
adamc@304 934 (let
adamc@304 935 val loc = s (LPARENleft, RPARENright)
adamc@304 936
adamc@403 937 val e = (EVar (["Basis"], "delete", Infer), loc)
adamc@304 938 val e = (EApp (e, texp), loc)
adamc@304 939 in
adamc@304 940 (EApp (e, sqlexp), loc)
adamc@304 941 end)
adamc@302 942
adamc@211 943 | UNDER (EWild, s (UNDERleft, UNDERright))
adamc@91 944
adamc@446 945 | LET edecls IN eexp END (ELet (edecls, eexp), s (LETleft, ENDright))
adamc@446 946
adamc@446 947 edecls : ([])
adamc@446 948 | edecl edecls (edecl :: edecls)
adamc@446 949
adamc@446 950 edecl : VAL vali ((EDVal vali, s (VALleft, valiright)))
adamc@446 951 | VAL REC valis ((EDValRec valis, s (VALleft, valisright)))
adamc@446 952 | FUN valis ((EDValRec valis, s (FUNleft, valisright)))
adamc@446 953
adamc@310 954 enterDml : (inDml := true)
adamc@310 955 leaveDml : (inDml := false)
adamc@310 956
adamc@403 957 texp : SYMBOL (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
adamc@302 958 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
adamc@302 959
adamc@302 960 fields : fident ([fident])
adamc@302 961 | fident COMMA fields (fident :: fields)
adamc@302 962
adamc@302 963 sqlexps: sqlexp ([sqlexp])
adamc@302 964 | sqlexp COMMA sqlexps (sqlexp :: sqlexps)
adamc@302 965
adamc@303 966 fsets : fident EQ sqlexp ([(fident, sqlexp)])
adamc@303 967 | fident EQ sqlexp COMMA fsets ((fident, sqlexp) :: fsets)
adamc@303 968
adamc@200 969 idents : ident ([ident])
adamc@200 970 | ident DOT idents (ident :: idents)
adamc@200 971
adamc@195 972 etuple : eexp COMMA eexp ([eexp1, eexp2])
adamc@195 973 | eexp COMMA etuple (eexp :: etuple)
adamc@195 974
adamc@170 975 branch : pat DARROW eexp (pat, eexp)
adamc@170 976
adamc@170 977 branchs: ([])
adamc@170 978 | BAR branch branchs (branch :: branchs)
adamc@170 979
adamc@170 980 pat : pterm (pterm)
adamc@170 981 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
adamc@170 982
adamc@170 983 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
adamc@170 984 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
adamc@170 985 | UNDER (PWild, s (UNDERleft, UNDERright))
adamc@173 986 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
adamc@173 987 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@170 988 | LPAREN pat RPAREN (pat)
adamc@174 989 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
adamc@174 990 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
adamc@174 991 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
adamc@195 992 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
adamc@195 993 false),
adamc@195 994 s (LPARENleft, RPARENright))
adamc@174 995
adamc@175 996 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
adamc@243 997 | INT EQ pat ([(Int64.toString INT, pat)], false)
adamc@174 998 | DOTDOTDOT ([], true)
adamc@175 999 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
adamc@243 1000 | INT EQ pat COMMA rpat ((Int64.toString INT, pat) :: #1 rpat, #2 rpat)
adamc@170 1001
adamc@195 1002 ptuple : pat COMMA pat ([pat1, pat2])
adamc@195 1003 | pat COMMA ptuple (pat :: ptuple)
adamc@195 1004
adamc@12 1005 rexp : ([])
adamc@12 1006 | ident EQ eexp ([(ident, eexp)])
adamc@12 1007 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
adamc@91 1008
adamc@141 1009 xml : xmlOne xml (let
adamc@141 1010 val pos = s (xmlOneleft, xmlright)
adamc@141 1011 in
adamc@141 1012 (EApp ((EApp (
adamc@403 1013 (EVar (["Basis"], "join", Infer), pos),
adamc@91 1014 xmlOne), pos),
adamc@141 1015 xml), pos)
adamc@141 1016 end)
adamc@141 1017 | xmlOne (xmlOne)
adamc@91 1018
adamc@403 1019 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata", Infer), s (NOTAGSleft, NOTAGSright)),
adamc@141 1020 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
adamc@141 1021 s (NOTAGSleft, NOTAGSright))
adamc@141 1022 | tag DIVIDE GT (let
adamc@141 1023 val pos = s (tagleft, GTright)
adamc@141 1024 in
adamc@141 1025 (EApp (#2 tag,
adamc@403 1026 (EApp ((EVar (["Basis"], "cdata", Infer), pos),
adamc@141 1027 (EPrim (Prim.String ""), pos)),
adamc@141 1028 pos)), pos)
adamc@141 1029 end)
adamc@141 1030
adamc@141 1031 | tag GT xml END_TAG (let
adamc@141 1032 val pos = s (tagleft, GTright)
adamc@325 1033 val et = tagIn END_TAG
adamc@141 1034 in
adamc@325 1035 if #1 tag = et then
adamc@361 1036 if et = "form" then
adamc@403 1037 (EApp ((EVar (["Basis"], "form", Infer), pos),
adamc@141 1038 xml), pos)
adamc@141 1039 else
adamc@141 1040 (EApp (#2 tag, xml), pos)
adamc@141 1041 else
adamc@325 1042 (if ErrorMsg.anyErrors () then
adamc@325 1043 ()
adamc@325 1044 else
adamc@325 1045 ErrorMsg.errorAt pos "Begin and end tags don't match.";
adamc@141 1046 (EFold, pos))
adamc@141 1047 end)
adamc@141 1048 | LBRACE eexp RBRACE (eexp)
adamc@391 1049 | LBRACE LBRACK eexp RBRACK RBRACE (let
adamc@391 1050 val loc = s (LBRACEleft, RBRACEright)
adamc@403 1051 val e = (EVar (["Top"], "txt", Infer), loc)
adamc@391 1052 in
adamc@391 1053 (EApp (e, eexp), loc)
adamc@391 1054 end)
adamc@92 1055
adamc@141 1056 tag : tagHead attrs (let
adamc@141 1057 val pos = s (tagHeadleft, attrsright)
adamc@141 1058 in
adamc@141 1059 (#1 tagHead,
adamc@403 1060 (EApp ((EApp ((EVar (["Basis"], "tag", Infer), pos),
adamc@141 1061 (ERecord attrs, pos)), pos),
adamc@141 1062 (EApp (#2 tagHead,
adamc@141 1063 (ERecord [], pos)), pos)),
adamc@141 1064 pos))
adamc@141 1065 end)
adamc@141 1066
adamc@141 1067 tagHead: BEGIN_TAG (let
adamc@325 1068 val bt = tagIn BEGIN_TAG
adamc@141 1069 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
adamc@141 1070 in
adamc@325 1071 (bt,
adamc@473 1072 (EVar (["Basis"], bt, Infer), pos))
adamc@141 1073 end)
adamc@141 1074 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
adamc@92 1075
adamc@104 1076 attrs : ([])
adamc@104 1077 | attr attrs (attr :: attrs)
adamc@104 1078
adamc@204 1079 attr : SYMBOL EQ attrv ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)), attrv)
adamc@204 1080
adamc@104 1081 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@104 1082 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@104 1083 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@110 1084 | LBRACE eexp RBRACE (eexp)
adamc@226 1085
adamc@232 1086 query : query1 obopt lopt ofopt (let
adamc@229 1087 val loc = s (query1left, query1right)
adamc@230 1088
adamc@230 1089 val re = (ERecord [((CName "Rows", loc),
adamc@230 1090 query1),
adamc@230 1091 ((CName "OrderBy", loc),
adamc@231 1092 obopt),
adamc@231 1093 ((CName "Limit", loc),
adamc@232 1094 lopt),
adamc@232 1095 ((CName "Offset", loc),
adamc@232 1096 ofopt)], loc)
adamc@229 1097 in
adamc@403 1098 (EApp ((EVar (["Basis"], "sql_query", Infer), loc), re), loc)
adamc@229 1099 end)
adamc@204 1100
adamc@227 1101 query1 : SELECT select FROM tables wopt gopt hopt
adamc@209 1102 (let
adamc@204 1103 val loc = s (SELECTleft, tablesright)
adamc@207 1104
adamc@233 1105 val (sel, exps) =
adamc@207 1106 case select of
adamc@233 1107 Star => (map (fn (nm, _) =>
adamc@233 1108 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
adamc@233 1109 loc),
adamc@233 1110 (CRecord [], loc)],
adamc@233 1111 loc))) tables,
adamc@233 1112 [])
adamc@207 1113 | Items sis =>
adamc@207 1114 let
adamc@207 1115 val tabs = map (fn (nm, _) => (nm, (CRecord [], loc))) tables
adamc@233 1116 val (tabs, exps) = foldl (amend_select loc) (tabs, []) sis
adamc@207 1117 in
adamc@233 1118 (map (fn (nm, c) => (nm,
adamc@233 1119 (CTuple [c,
adamc@233 1120 (CWild (KRecord (KType, loc), loc),
adamc@233 1121 loc)], loc))) tabs,
adamc@233 1122 exps)
adamc@207 1123 end
adamc@207 1124
adamc@207 1125 val sel = (CRecord sel, loc)
adamc@207 1126
adamc@226 1127 val grp = case gopt of
adamc@403 1128 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all",
adamc@403 1129 Infer), loc),
adamc@226 1130 (CWild (KRecord (KRecord (KType, loc), loc),
adamc@226 1131 loc), loc)), loc)
adamc@226 1132 | SOME gis =>
adamc@226 1133 let
adamc@226 1134 val tabs = map (fn (nm, _) =>
adamc@226 1135 (nm, (CRecord [], loc))) tables
adamc@226 1136 val tabs = foldl (amend_group loc) tabs gis
adamc@226 1137
adamc@226 1138 val tabs = map (fn (nm, c) =>
adamc@226 1139 (nm,
adamc@226 1140 (CTuple [c,
adamc@226 1141 (CWild (KRecord (KType, loc),
adamc@226 1142 loc),
adamc@226 1143 loc)], loc))) tabs
adamc@226 1144 in
adamc@403 1145 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@226 1146 (CRecord tabs, loc)), loc)
adamc@226 1147 end
adamc@226 1148
adamc@403 1149 val e = (EVar (["Basis"], "sql_query1", Infer), loc)
adamc@209 1150 val re = (ERecord [((CName "From", loc),
adamc@209 1151 (ERecord tables, loc)),
adamc@209 1152 ((CName "Where", loc),
adamc@223 1153 wopt),
adamc@224 1154 ((CName "GroupBy", loc),
adamc@226 1155 grp),
adamc@224 1156 ((CName "Having", loc),
adamc@224 1157 hopt),
adamc@223 1158 ((CName "SelectFields", loc),
adamc@403 1159 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@233 1160 sel), loc)),
adamc@233 1161 ((CName "SelectExps", loc),
adamc@233 1162 (ERecord exps, loc))], loc)
adamc@223 1163
adamc@209 1164 val e = (EApp (e, re), loc)
adamc@204 1165 in
adamc@207 1166 e
adamc@204 1167 end)
adamc@229 1168 | query1 UNION query1 (sql_relop ("union", query11, query12, s (query11left, query12right)))
adamc@229 1169 | query1 INTERSECT query1 (sql_relop ("intersect", query11, query12, s (query11left, query12right)))
adamc@229 1170 | query1 EXCEPT query1 (sql_relop ("except", query11, query12, s (query11left, query12right)))
adamc@204 1171
adamc@204 1172 tables : table ([table])
adamc@204 1173 | table COMMA tables (table :: tables)
adamc@204 1174
adamc@204 1175 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@204 1176 | LBRACE cexp RBRACE (cexp)
adamc@204 1177
adamc@243 1178 table : SYMBOL ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)),
adamc@403 1179 (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@403 1180 | SYMBOL AS tname (tname, (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@221 1181 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
adamc@207 1182
adamc@243 1183 tident : SYMBOL (CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@207 1184 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@221 1185 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
adamc@207 1186
adamc@207 1187 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@207 1188 | LBRACE cexp RBRACE (cexp)
adamc@207 1189
adamc@207 1190 seli : tident DOT fident (Field (tident, fident))
adamc@233 1191 | sqlexp AS fident (Exp (fident, sqlexp))
adamc@341 1192 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (Fields (tident, cexp))
adamc@207 1193
adamc@207 1194 selis : seli ([seli])
adamc@207 1195 | seli COMMA selis (seli :: selis)
adamc@207 1196
adamc@207 1197 select : STAR (Star)
adamc@207 1198 | selis (Items selis)
adamc@209 1199
adamc@403 1200 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", Infer),
adamc@209 1201 s (TRUEleft, TRUEright)))
adamc@403 1202 | FALSE (sql_inject (EVar (["Basis"], "False", Infer),
adamc@209 1203 s (FALSEleft, FALSEright)))
adamc@209 1204
adamc@222 1205 | INT (sql_inject (EPrim (Prim.Int INT),
adamc@222 1206 s (INTleft, INTright)))
adamc@222 1207 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
adamc@222 1208 s (FLOATleft, FLOATright)))
adamc@229 1209 | STRING (sql_inject (EPrim (Prim.String STRING),
adamc@229 1210 s (STRINGleft, STRINGright)))
adamc@441 1211 | CURRENT_TIMESTAMP (sql_nfunc ("current_timestamp",
adamc@441 1212 s (CURRENT_TIMESTAMPleft, CURRENT_TIMESTAMPright)))
adamc@222 1213
adamc@221 1214 | tident DOT fident (let
adamc@221 1215 val loc = s (tidentleft, fidentright)
adamc@403 1216 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@221 1217 val e = (ECApp (e, tident), loc)
adamc@221 1218 in
adamc@221 1219 (ECApp (e, fident), loc)
adamc@221 1220 end)
adamc@234 1221 | CSYMBOL (let
adamc@234 1222 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@310 1223 in
adamc@310 1224 if !inDml then
adamc@310 1225 let
adamc@403 1226 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@310 1227 val e = (ECApp (e, (CName "T", loc)), loc)
adamc@310 1228 in
adamc@310 1229 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1230 end
adamc@310 1231 else
adamc@310 1232 let
adamc@403 1233 val e = (EVar (["Basis"], "sql_exp", Infer), loc)
adamc@310 1234 in
adamc@310 1235 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1236 end
adamc@310 1237 end)
adamc@221 1238
adamc@471 1239 | LBRACE eexp RBRACE (eexp)
adamc@470 1240
adamc@219 1241 | sqlexp EQ sqlexp (sql_compare ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1242 | sqlexp NE sqlexp (sql_compare ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1243 | sqlexp LT sqlexp (sql_compare ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1244 | sqlexp LE sqlexp (sql_compare ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1245 | sqlexp GT sqlexp (sql_compare ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1246 | sqlexp GE sqlexp (sql_compare ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1247
adamc@220 1248 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@220 1249 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@220 1250 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
adamc@220 1251
adamc@470 1252 | sqlexp IS NULL (let
adamc@470 1253 val loc = s (sqlexpleft, NULLright)
adamc@470 1254 in
adamc@470 1255 (EApp ((EVar (["Basis"], "sql_is_null", Infer), loc),
adamc@470 1256 sqlexp), loc)
adamc@470 1257 end)
adamc@470 1258
adamc@471 1259 | LBRACE LBRACK eexp RBRACK RBRACE (sql_inject (#1 eexp,
adamc@471 1260 s (LBRACEleft, RBRACEright)))
adamc@220 1261 | LPAREN sqlexp RPAREN (sqlexp)
adamc@210 1262
adamc@467 1263 | NULL (sql_inject ((EVar (["Basis"], "None", Infer),
adamc@467 1264 s (NULLleft, NULLright))))
adamc@467 1265
adamc@235 1266 | COUNT LPAREN STAR RPAREN (let
adamc@235 1267 val loc = s (COUNTleft, RPARENright)
adamc@235 1268 in
adamc@403 1269 (EApp ((EVar (["Basis"], "sql_count", Infer), loc),
adamc@235 1270 (ERecord [], loc)), loc)
adamc@235 1271 end)
adamc@236 1272 | sqlagg LPAREN sqlexp RPAREN (let
adamc@236 1273 val loc = s (sqlaggleft, RPARENright)
adamc@236 1274
adamc@403 1275 val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
adamc@403 1276 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
adamc@236 1277 e), loc)
adamc@236 1278 in
adamc@236 1279 (EApp (e, sqlexp), loc)
adamc@236 1280 end)
adamc@235 1281
adamc@403 1282 wopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 1283 dummy))
adamc@209 1284 | CWHERE sqlexp (sqlexp)
adamc@226 1285
adamc@226 1286 groupi : tident DOT fident (GField (tident, fident))
adamc@226 1287
adamc@226 1288 groupis: groupi ([groupi])
adamc@226 1289 | groupi COMMA groupis (groupi :: groupis)
adamc@226 1290
adamc@226 1291 gopt : (NONE)
adamc@226 1292 | GROUP BY groupis (SOME groupis)
adamc@227 1293
adamc@403 1294 hopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 1295 dummy))
adamc@227 1296 | HAVING sqlexp (sqlexp)
adamc@230 1297
adamc@403 1298 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
adamc@234 1299 (CWild (KRecord (KType, dummy), dummy), dummy)),
adamc@230 1300 dummy)
adamc@230 1301 | ORDER BY obexps (obexps)
adamc@230 1302
adamc@268 1303 obitem : sqlexp diropt (sqlexp, diropt)
adamc@268 1304
adamc@268 1305 obexps : obitem (let
adamc@268 1306 val loc = s (obitemleft, obitemright)
adamc@230 1307
adamc@403 1308 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), loc),
adamc@234 1309 (CWild (KRecord (KType, loc), loc), loc)),
adamc@230 1310 loc)
adamc@403 1311 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 1312 #1 obitem), loc)
adamc@268 1313 val e = (EApp (e, #2 obitem), loc)
adamc@230 1314 in
adamc@230 1315 (EApp (e, e'), loc)
adamc@230 1316 end)
adamc@268 1317 | obitem COMMA obexps (let
adamc@268 1318 val loc = s (obitemleft, obexpsright)
adamc@230 1319
adamc@403 1320 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 1321 #1 obitem), loc)
adamc@268 1322 val e = (EApp (e, #2 obitem), loc)
adamc@230 1323 in
adamc@230 1324 (EApp (e, obexps), loc)
adamc@230 1325 end)
adamc@231 1326
adamc@403 1327 diropt : (EVar (["Basis"], "sql_asc", Infer), dummy)
adamc@403 1328 | ASC (EVar (["Basis"], "sql_asc", Infer), s (ASCleft, ASCright))
adamc@403 1329 | DESC (EVar (["Basis"], "sql_desc", Infer), s (DESCleft, DESCright))
adamc@268 1330
adamc@403 1331 lopt : (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@403 1332 | LIMIT ALL (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@231 1333 | LIMIT sqlint (let
adamc@231 1334 val loc = s (LIMITleft, sqlintright)
adamc@231 1335 in
adamc@403 1336 (EApp ((EVar (["Basis"], "sql_limit", Infer), loc), sqlint), loc)
adamc@231 1337 end)
adamc@231 1338
adamc@403 1339 ofopt : (EVar (["Basis"], "sql_no_offset", Infer), dummy)
adamc@232 1340 | OFFSET sqlint (let
adamc@232 1341 val loc = s (OFFSETleft, sqlintright)
adamc@232 1342 in
adamc@403 1343 (EApp ((EVar (["Basis"], "sql_offset", Infer), loc), sqlint), loc)
adamc@232 1344 end)
adamc@232 1345
adamc@231 1346 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@231 1347 | LBRACE eexp RBRACE (eexp)
adamc@236 1348
adamc@236 1349 sqlagg : AVG ("avg")
adamc@236 1350 | SUM ("sum")
adamc@236 1351 | MIN ("min")
adamc@236 1352 | MAX ("max")