annotate src/urweb.grm @ 441:c5335613f31e

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