annotate src/urweb.grm @ 389:acaf9d19fbb7

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