annotate src/urweb.grm @ 391:fe8f75f7e130

lt, le working for int
author Adam Chlipala <adamc@hcoop.net>
date Tue, 21 Oct 2008 10:56:43 -0400
parents acaf9d19fbb7
children 8084fa9216de
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@391 700
adamc@391 701 | eexp LT eexp (native_op ("lt", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 702 | eexp LE eexp (native_op ("le", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 703 | eexp GT eexp (native_op ("gt", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 704 | eexp GE eexp (native_op ("ge", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 705
adamc@339 706 | eexp WITH cterm EQ eexp (EWith (eexp1, cterm, eexp2), s (eexp1left, eexp2right))
adamc@8 707
adamc@241 708 eargs : earg (earg)
adamc@241 709 | eargl (eargl)
adamc@241 710
adamc@241 711 eargl : eargp eargp (eargp1 o eargp2)
adamc@241 712 | eargp eargl (eargp o eargl)
adamc@241 713
adamc@242 714 eargl2 : (fn x => x)
adamc@242 715 | eargp eargl2 (eargp o eargl2)
adamc@242 716
adamc@241 717 earg : SYMBOL kcolon kind (fn (e, t) =>
adamc@241 718 let
adamc@241 719 val loc = s (SYMBOLleft, kindright)
adamc@241 720 in
adamc@241 721 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
adamc@241 722 (TCFun (kcolon, SYMBOL, kind, t), loc))
adamc@241 723 end)
adamc@241 724 | SYMBOL COLON cexp (fn (e, t) =>
adamc@241 725 let
adamc@241 726 val loc = s (SYMBOLleft, cexpright)
adamc@241 727 in
adamc@241 728 ((EAbs (SYMBOL, SOME cexp, e), loc),
adamc@241 729 (TFun (cexp, t), loc))
adamc@241 730 end)
adamc@241 731 | UNDER COLON cexp (fn (e, t) =>
adamc@241 732 let
adamc@241 733 val loc = s (UNDERleft, cexpright)
adamc@241 734 in
adamc@241 735 ((EAbs ("_", SOME cexp, e), loc),
adamc@241 736 (TFun (cexp, t), loc))
adamc@241 737 end)
adamc@241 738 | eargp (eargp)
adamc@241 739
adamc@241 740 eargp : SYMBOL (fn (e, t) =>
adamc@241 741 let
adamc@241 742 val loc = s (SYMBOLleft, SYMBOLright)
adamc@241 743 in
adamc@241 744 ((EAbs (SYMBOL, NONE, e), loc),
adamc@241 745 (TFun ((CWild (KType, loc), loc), t), loc))
adamc@241 746 end)
adamc@241 747 | UNIT (fn (e, t) =>
adamc@241 748 let
adamc@241 749 val loc = s (UNITleft, UNITright)
adamc@241 750 val t' = (TRecord (CRecord [], loc), loc)
adamc@241 751 in
adamc@241 752 ((EAbs ("_", SOME t', e), loc),
adamc@241 753 (TFun (t', t), loc))
adamc@241 754 end)
adamc@241 755 | UNDER (fn (e, t) =>
adamc@241 756 let
adamc@241 757 val loc = s (UNDERleft, UNDERright)
adamc@241 758 in
adamc@241 759 ((EAbs ("_", NONE, e), loc),
adamc@241 760 (TFun ((CWild (KType, loc), loc), t), loc))
adamc@241 761 end)
adamc@241 762 | LPAREN SYMBOL kcolon kind RPAREN(fn (e, t) =>
adamc@241 763 let
adamc@241 764 val loc = s (LPARENleft, RPARENright)
adamc@241 765 in
adamc@241 766 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
adamc@241 767 (TCFun (kcolon, SYMBOL, kind, t), loc))
adamc@241 768 end)
adamc@241 769 | LPAREN SYMBOL COLON cexp RPAREN (fn (e, t) =>
adamc@241 770 let
adamc@241 771 val loc = s (LPARENleft, RPARENright)
adamc@241 772 in
adamc@241 773 ((EAbs (SYMBOL, SOME cexp, e), loc),
adamc@241 774 (TFun (cexp, t), loc))
adamc@241 775 end)
adamc@241 776 | LPAREN UNDER COLON cexp RPAREN (fn (e, t) =>
adamc@241 777 let
adamc@241 778 val loc = s (LPARENleft, RPARENright)
adamc@241 779 in
adamc@241 780 ((EAbs ("_", SOME cexp, e), loc),
adamc@241 781 (TFun (cexp, t), loc))
adamc@241 782 end)
adamc@354 783 | LPAREN cterm TWIDDLE cterm RPAREN(fn (e, t) =>
adamc@354 784 let
adamc@354 785 val loc = s (LPARENleft, RPARENright)
adamc@354 786 in
adamc@354 787 ((EDisjoint (cterm1, cterm2, e), loc),
adamc@354 788 (CDisjoint (cterm1, cterm2, t), loc))
adamc@354 789 end)
adamc@356 790 | LBRACK cterm TWIDDLE cterm RBRACK(fn (e, t) =>
adamc@356 791 let
adamc@356 792 val loc = s (LBRACKleft, RBRACKright)
adamc@356 793 in
adamc@356 794 ((EDisjoint (cterm1, cterm2, e), loc),
adamc@356 795 (CDisjoint (cterm1, cterm2, t), loc))
adamc@356 796 end)
adamc@241 797
adamc@8 798 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
adamc@195 799 | LPAREN etuple RPAREN (let
adamc@195 800 val loc = s (LPARENleft, RPARENright)
adamc@195 801 in
adamc@195 802 (ERecord (ListUtil.mapi (fn (i, e) =>
adamc@195 803 ((CName (Int.toString (i + 1)), loc),
adamc@195 804 e)) etuple), loc)
adamc@195 805 end)
adamc@8 806
adamc@34 807 | path (EVar path, s (pathleft, pathright))
adamc@156 808 | cpath (EVar cpath, s (cpathleft, cpathright))
adamc@12 809 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
adamc@110 810 | UNIT (ERecord [], s (UNITleft, UNITright))
adamc@12 811
adamc@14 812 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@14 813 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@14 814 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@14 815
adamc@200 816 | path DOT idents (let
adamc@200 817 val loc = s (pathleft, identsright)
adamc@200 818 in
adamc@200 819 foldl (fn (ident, e) =>
adamc@200 820 (EField (e, ident), loc))
adamc@200 821 (EVar path, s (pathleft, pathright)) idents
adamc@200 822 end)
adamc@71 823 | FOLD (EFold, s (FOLDleft, FOLDright))
adamc@71 824
adamc@360 825 | XML_BEGIN xml XML_END (let
adamc@360 826 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 827 in
adamc@360 828 if XML_BEGIN = "xml" then
adamc@360 829 ()
adamc@360 830 else
adamc@360 831 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@360 832 xml
adamc@360 833 end)
adamc@360 834 | XML_BEGIN XML_END (let
adamc@360 835 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 836 in
adamc@360 837 if XML_BEGIN = "xml" then
adamc@360 838 ()
adamc@360 839 else
adamc@360 840 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@360 841 (EApp ((EVar (["Basis"], "cdata"), loc),
adamc@360 842 (EPrim (Prim.String ""), loc)),
adamc@360 843 loc)
adamc@360 844 end)
adamc@360 845 | XML_BEGIN_END (let
adamc@360 846 val loc = s (XML_BEGIN_ENDleft, XML_BEGIN_ENDright)
adamc@360 847 in
adamc@360 848 if XML_BEGIN_END = "xml" then
adamc@360 849 ()
adamc@360 850 else
adamc@360 851 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@360 852 (EApp ((EVar (["Basis"], "cdata"), loc),
adamc@360 853 (EPrim (Prim.String ""), loc)),
adamc@360 854 loc)
adamc@360 855 end)
adamc@302 856
adamc@204 857 | LPAREN query RPAREN (query)
adamc@300 858 | LPAREN CWHERE sqlexp RPAREN (sqlexp)
adamc@339 859 | LPAREN SQL sqlexp RPAREN (sqlexp)
adamc@302 860
adamc@302 861 | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN
adamc@302 862 (let
adamc@302 863 val loc = s (LPAREN1left, RPAREN3right)
adamc@302 864
adamc@302 865 val e = (EVar (["Basis"], "insert"), loc)
adamc@302 866 val e = (EApp (e, texp), loc)
adamc@302 867 in
adamc@302 868 if length fields <> length sqlexps then
adamc@302 869 ErrorMsg.errorAt loc "Length mismatch in INSERT field specification"
adamc@302 870 else
adamc@302 871 ();
adamc@302 872 (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
adamc@302 873 end)
adamc@310 874 | LPAREN enterDml UPDATE texp SET fsets CWHERE sqlexp leaveDml RPAREN
adamc@303 875 (let
adamc@303 876 val loc = s (LPARENleft, RPARENright)
adamc@303 877
adamc@303 878 val e = (EVar (["Basis"], "update"), loc)
adamc@342 879 val e = (ECApp (e, (CWild (KRecord (KType, loc), loc), loc)), loc)
adamc@306 880 val e = (EApp (e, (ERecord fsets, loc)), loc)
adamc@305 881 val e = (EApp (e, texp), loc)
adamc@303 882 in
adamc@303 883 (EApp (e, sqlexp), loc)
adamc@303 884 end)
adamc@310 885 | LPAREN enterDml DELETE FROM texp CWHERE sqlexp leaveDml RPAREN
adamc@304 886 (let
adamc@304 887 val loc = s (LPARENleft, RPARENright)
adamc@304 888
adamc@304 889 val e = (EVar (["Basis"], "delete"), loc)
adamc@304 890 val e = (EApp (e, texp), loc)
adamc@304 891 in
adamc@304 892 (EApp (e, sqlexp), loc)
adamc@304 893 end)
adamc@302 894
adamc@211 895 | UNDER (EWild, s (UNDERleft, UNDERright))
adamc@91 896
adamc@310 897 enterDml : (inDml := true)
adamc@310 898 leaveDml : (inDml := false)
adamc@310 899
adamc@302 900 texp : SYMBOL (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@302 901 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
adamc@302 902
adamc@302 903 fields : fident ([fident])
adamc@302 904 | fident COMMA fields (fident :: fields)
adamc@302 905
adamc@302 906 sqlexps: sqlexp ([sqlexp])
adamc@302 907 | sqlexp COMMA sqlexps (sqlexp :: sqlexps)
adamc@302 908
adamc@303 909 fsets : fident EQ sqlexp ([(fident, sqlexp)])
adamc@303 910 | fident EQ sqlexp COMMA fsets ((fident, sqlexp) :: fsets)
adamc@303 911
adamc@200 912 idents : ident ([ident])
adamc@200 913 | ident DOT idents (ident :: idents)
adamc@200 914
adamc@195 915 etuple : eexp COMMA eexp ([eexp1, eexp2])
adamc@195 916 | eexp COMMA etuple (eexp :: etuple)
adamc@195 917
adamc@170 918 branch : pat DARROW eexp (pat, eexp)
adamc@170 919
adamc@170 920 branchs: ([])
adamc@170 921 | BAR branch branchs (branch :: branchs)
adamc@170 922
adamc@170 923 pat : pterm (pterm)
adamc@170 924 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
adamc@170 925
adamc@170 926 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
adamc@170 927 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
adamc@170 928 | UNDER (PWild, s (UNDERleft, UNDERright))
adamc@173 929 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
adamc@173 930 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@170 931 | LPAREN pat RPAREN (pat)
adamc@174 932 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
adamc@174 933 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
adamc@174 934 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
adamc@195 935 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
adamc@195 936 false),
adamc@195 937 s (LPARENleft, RPARENright))
adamc@174 938
adamc@175 939 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
adamc@243 940 | INT EQ pat ([(Int64.toString INT, pat)], false)
adamc@174 941 | DOTDOTDOT ([], true)
adamc@175 942 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
adamc@243 943 | INT EQ pat COMMA rpat ((Int64.toString INT, pat) :: #1 rpat, #2 rpat)
adamc@170 944
adamc@195 945 ptuple : pat COMMA pat ([pat1, pat2])
adamc@195 946 | pat COMMA ptuple (pat :: ptuple)
adamc@195 947
adamc@12 948 rexp : ([])
adamc@12 949 | ident EQ eexp ([(ident, eexp)])
adamc@12 950 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
adamc@91 951
adamc@141 952 xml : xmlOne xml (let
adamc@141 953 val pos = s (xmlOneleft, xmlright)
adamc@141 954 in
adamc@141 955 (EApp ((EApp (
adamc@141 956 (EVar (["Basis"], "join"), pos),
adamc@91 957 xmlOne), pos),
adamc@141 958 xml), pos)
adamc@141 959 end)
adamc@141 960 | xmlOne (xmlOne)
adamc@91 961
adamc@141 962 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata"), s (NOTAGSleft, NOTAGSright)),
adamc@141 963 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
adamc@141 964 s (NOTAGSleft, NOTAGSright))
adamc@141 965 | tag DIVIDE GT (let
adamc@141 966 val pos = s (tagleft, GTright)
adamc@141 967 in
adamc@141 968 (EApp (#2 tag,
adamc@141 969 (EApp ((EVar (["Basis"], "cdata"), pos),
adamc@141 970 (EPrim (Prim.String ""), pos)),
adamc@141 971 pos)), pos)
adamc@141 972 end)
adamc@141 973
adamc@141 974 | tag GT xml END_TAG (let
adamc@141 975 val pos = s (tagleft, GTright)
adamc@325 976 val et = tagIn END_TAG
adamc@141 977 in
adamc@325 978 if #1 tag = et then
adamc@361 979 if et = "form" then
adamc@361 980 (EApp ((EVar (["Basis"], "form"), pos),
adamc@141 981 xml), pos)
adamc@141 982 else
adamc@141 983 (EApp (#2 tag, xml), pos)
adamc@141 984 else
adamc@325 985 (if ErrorMsg.anyErrors () then
adamc@325 986 ()
adamc@325 987 else
adamc@325 988 ErrorMsg.errorAt pos "Begin and end tags don't match.";
adamc@141 989 (EFold, pos))
adamc@141 990 end)
adamc@141 991 | LBRACE eexp RBRACE (eexp)
adamc@391 992 | LBRACE LBRACK eexp RBRACK RBRACE (let
adamc@391 993 val loc = s (LBRACEleft, RBRACEright)
adamc@391 994 val e = (EVar (["Top"], "txt"), loc)
adamc@391 995 val e = (EApp (e, (EWild, loc)), loc)
adamc@391 996 in
adamc@391 997 (EApp (e, eexp), loc)
adamc@391 998 end)
adamc@92 999
adamc@141 1000 tag : tagHead attrs (let
adamc@141 1001 val pos = s (tagHeadleft, attrsright)
adamc@141 1002 in
adamc@141 1003 (#1 tagHead,
adamc@141 1004 (EApp ((EApp ((EVar (["Basis"], "tag"), pos),
adamc@141 1005 (ERecord attrs, pos)), pos),
adamc@141 1006 (EApp (#2 tagHead,
adamc@141 1007 (ERecord [], pos)), pos)),
adamc@141 1008 pos))
adamc@141 1009 end)
adamc@141 1010
adamc@141 1011 tagHead: BEGIN_TAG (let
adamc@325 1012 val bt = tagIn BEGIN_TAG
adamc@141 1013 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
adamc@141 1014 in
adamc@325 1015 (bt,
adamc@325 1016 (EVar ([], bt), pos))
adamc@141 1017 end)
adamc@141 1018 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
adamc@92 1019
adamc@104 1020 attrs : ([])
adamc@104 1021 | attr attrs (attr :: attrs)
adamc@104 1022
adamc@204 1023 attr : SYMBOL EQ attrv ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)), attrv)
adamc@204 1024
adamc@104 1025 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@104 1026 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@104 1027 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@110 1028 | LBRACE eexp RBRACE (eexp)
adamc@226 1029
adamc@232 1030 query : query1 obopt lopt ofopt (let
adamc@229 1031 val loc = s (query1left, query1right)
adamc@230 1032
adamc@230 1033 val re = (ERecord [((CName "Rows", loc),
adamc@230 1034 query1),
adamc@230 1035 ((CName "OrderBy", loc),
adamc@231 1036 obopt),
adamc@231 1037 ((CName "Limit", loc),
adamc@232 1038 lopt),
adamc@232 1039 ((CName "Offset", loc),
adamc@232 1040 ofopt)], loc)
adamc@229 1041 in
adamc@230 1042 (EApp ((EVar (["Basis"], "sql_query"), loc), re), loc)
adamc@229 1043 end)
adamc@204 1044
adamc@227 1045 query1 : SELECT select FROM tables wopt gopt hopt
adamc@209 1046 (let
adamc@204 1047 val loc = s (SELECTleft, tablesright)
adamc@207 1048
adamc@233 1049 val (sel, exps) =
adamc@207 1050 case select of
adamc@233 1051 Star => (map (fn (nm, _) =>
adamc@233 1052 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
adamc@233 1053 loc),
adamc@233 1054 (CRecord [], loc)],
adamc@233 1055 loc))) tables,
adamc@233 1056 [])
adamc@207 1057 | Items sis =>
adamc@207 1058 let
adamc@207 1059 val tabs = map (fn (nm, _) => (nm, (CRecord [], loc))) tables
adamc@233 1060 val (tabs, exps) = foldl (amend_select loc) (tabs, []) sis
adamc@207 1061 in
adamc@233 1062 (map (fn (nm, c) => (nm,
adamc@233 1063 (CTuple [c,
adamc@233 1064 (CWild (KRecord (KType, loc), loc),
adamc@233 1065 loc)], loc))) tabs,
adamc@233 1066 exps)
adamc@207 1067 end
adamc@207 1068
adamc@207 1069 val sel = (CRecord sel, loc)
adamc@207 1070
adamc@226 1071 val grp = case gopt of
adamc@226 1072 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all"), loc),
adamc@226 1073 (CWild (KRecord (KRecord (KType, loc), loc),
adamc@226 1074 loc), loc)), loc)
adamc@226 1075 | SOME gis =>
adamc@226 1076 let
adamc@226 1077 val tabs = map (fn (nm, _) =>
adamc@226 1078 (nm, (CRecord [], loc))) tables
adamc@226 1079 val tabs = foldl (amend_group loc) tabs gis
adamc@226 1080
adamc@226 1081 val tabs = map (fn (nm, c) =>
adamc@226 1082 (nm,
adamc@226 1083 (CTuple [c,
adamc@226 1084 (CWild (KRecord (KType, loc),
adamc@226 1085 loc),
adamc@226 1086 loc)], loc))) tabs
adamc@226 1087 in
adamc@226 1088 (ECApp ((EVar (["Basis"], "sql_subset"), loc),
adamc@226 1089 (CRecord tabs, loc)), loc)
adamc@226 1090 end
adamc@226 1091
adamc@229 1092 val e = (EVar (["Basis"], "sql_query1"), loc)
adamc@209 1093 val re = (ERecord [((CName "From", loc),
adamc@209 1094 (ERecord tables, loc)),
adamc@209 1095 ((CName "Where", loc),
adamc@223 1096 wopt),
adamc@224 1097 ((CName "GroupBy", loc),
adamc@226 1098 grp),
adamc@224 1099 ((CName "Having", loc),
adamc@224 1100 hopt),
adamc@223 1101 ((CName "SelectFields", loc),
adamc@223 1102 (ECApp ((EVar (["Basis"], "sql_subset"), loc),
adamc@233 1103 sel), loc)),
adamc@233 1104 ((CName "SelectExps", loc),
adamc@233 1105 (ERecord exps, loc))], loc)
adamc@223 1106
adamc@209 1107 val e = (EApp (e, re), loc)
adamc@204 1108 in
adamc@207 1109 e
adamc@204 1110 end)
adamc@229 1111 | query1 UNION query1 (sql_relop ("union", query11, query12, s (query11left, query12right)))
adamc@229 1112 | query1 INTERSECT query1 (sql_relop ("intersect", query11, query12, s (query11left, query12right)))
adamc@229 1113 | query1 EXCEPT query1 (sql_relop ("except", query11, query12, s (query11left, query12right)))
adamc@204 1114
adamc@204 1115 tables : table ([table])
adamc@204 1116 | table COMMA tables (table :: tables)
adamc@204 1117
adamc@204 1118 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@204 1119 | LBRACE cexp RBRACE (cexp)
adamc@204 1120
adamc@243 1121 table : SYMBOL ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)),
adamc@204 1122 (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright)))
adamc@204 1123 | SYMBOL AS tname (tname, (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright)))
adamc@221 1124 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
adamc@207 1125
adamc@243 1126 tident : SYMBOL (CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@207 1127 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@221 1128 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
adamc@207 1129
adamc@207 1130 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@207 1131 | LBRACE cexp RBRACE (cexp)
adamc@207 1132
adamc@207 1133 seli : tident DOT fident (Field (tident, fident))
adamc@233 1134 | sqlexp AS fident (Exp (fident, sqlexp))
adamc@341 1135 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (Fields (tident, cexp))
adamc@207 1136
adamc@207 1137 selis : seli ([seli])
adamc@207 1138 | seli COMMA selis (seli :: selis)
adamc@207 1139
adamc@207 1140 select : STAR (Star)
adamc@207 1141 | selis (Items selis)
adamc@209 1142
adamc@209 1143 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True"),
adamc@209 1144 EVar (["Basis"], "sql_bool"),
adamc@209 1145 s (TRUEleft, TRUEright)))
adamc@209 1146 | FALSE (sql_inject (EVar (["Basis"], "False"),
adamc@209 1147 EVar (["Basis"], "sql_bool"),
adamc@209 1148 s (FALSEleft, FALSEright)))
adamc@209 1149
adamc@222 1150 | INT (sql_inject (EPrim (Prim.Int INT),
adamc@222 1151 EVar (["Basis"], "sql_int"),
adamc@222 1152 s (INTleft, INTright)))
adamc@222 1153 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
adamc@222 1154 EVar (["Basis"], "sql_float"),
adamc@222 1155 s (FLOATleft, FLOATright)))
adamc@229 1156 | STRING (sql_inject (EPrim (Prim.String STRING),
adamc@229 1157 EVar (["Basis"], "sql_string"),
adamc@229 1158 s (STRINGleft, STRINGright)))
adamc@222 1159
adamc@221 1160 | tident DOT fident (let
adamc@221 1161 val loc = s (tidentleft, fidentright)
adamc@221 1162 val e = (EVar (["Basis"], "sql_field"), loc)
adamc@221 1163 val e = (ECApp (e, tident), loc)
adamc@221 1164 in
adamc@221 1165 (ECApp (e, fident), loc)
adamc@221 1166 end)
adamc@234 1167 | CSYMBOL (let
adamc@234 1168 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@310 1169 in
adamc@310 1170 if !inDml then
adamc@310 1171 let
adamc@310 1172 val e = (EVar (["Basis"], "sql_field"), loc)
adamc@310 1173 val e = (ECApp (e, (CName "T", loc)), loc)
adamc@310 1174 in
adamc@310 1175 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1176 end
adamc@310 1177 else
adamc@310 1178 let
adamc@310 1179 val e = (EVar (["Basis"], "sql_exp"), loc)
adamc@310 1180 in
adamc@310 1181 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 1182 end
adamc@310 1183 end)
adamc@221 1184
adamc@219 1185 | sqlexp EQ sqlexp (sql_compare ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1186 | sqlexp NE sqlexp (sql_compare ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1187 | sqlexp LT sqlexp (sql_compare ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1188 | sqlexp LE sqlexp (sql_compare ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1189 | sqlexp GT sqlexp (sql_compare ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1190 | sqlexp GE sqlexp (sql_compare ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 1191
adamc@220 1192 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@220 1193 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@220 1194 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
adamc@220 1195
adamc@210 1196 | LBRACE eexp RBRACE (sql_inject (#1 eexp,
adamc@211 1197 EWild,
adamc@210 1198 s (LBRACEleft, RBRACEright)))
adamc@220 1199 | LPAREN sqlexp RPAREN (sqlexp)
adamc@210 1200
adamc@235 1201 | COUNT LPAREN STAR RPAREN (let
adamc@235 1202 val loc = s (COUNTleft, RPARENright)
adamc@235 1203 in
adamc@235 1204 (EApp ((EVar (["Basis"], "sql_count"), loc),
adamc@235 1205 (ERecord [], loc)), loc)
adamc@235 1206 end)
adamc@236 1207 | sqlagg LPAREN sqlexp RPAREN (let
adamc@236 1208 val loc = s (sqlaggleft, RPARENright)
adamc@236 1209
adamc@236 1210 val e = (EApp ((EVar (["Basis"], "sql_" ^ sqlagg), loc),
adamc@236 1211 (EWild, loc)), loc)
adamc@236 1212 val e = (EApp ((EVar (["Basis"], "sql_aggregate"), loc),
adamc@236 1213 e), loc)
adamc@236 1214 in
adamc@236 1215 (EApp (e, sqlexp), loc)
adamc@236 1216 end)
adamc@235 1217
adamc@209 1218 wopt : (sql_inject (EVar (["Basis"], "True"),
adamc@209 1219 EVar (["Basis"], "sql_bool"),
adamc@230 1220 dummy))
adamc@209 1221 | CWHERE sqlexp (sqlexp)
adamc@226 1222
adamc@226 1223 groupi : tident DOT fident (GField (tident, fident))
adamc@226 1224
adamc@226 1225 groupis: groupi ([groupi])
adamc@226 1226 | groupi COMMA groupis (groupi :: groupis)
adamc@226 1227
adamc@226 1228 gopt : (NONE)
adamc@226 1229 | GROUP BY groupis (SOME groupis)
adamc@227 1230
adamc@227 1231 hopt : (sql_inject (EVar (["Basis"], "True"),
adamc@227 1232 EVar (["Basis"], "sql_bool"),
adamc@230 1233 dummy))
adamc@227 1234 | HAVING sqlexp (sqlexp)
adamc@230 1235
adamc@230 1236 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil"), dummy),
adamc@234 1237 (CWild (KRecord (KType, dummy), dummy), dummy)),
adamc@230 1238 dummy)
adamc@230 1239 | ORDER BY obexps (obexps)
adamc@230 1240
adamc@268 1241 obitem : sqlexp diropt (sqlexp, diropt)
adamc@268 1242
adamc@268 1243 obexps : obitem (let
adamc@268 1244 val loc = s (obitemleft, obitemright)
adamc@230 1245
adamc@230 1246 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil"), loc),
adamc@234 1247 (CWild (KRecord (KType, loc), loc), loc)),
adamc@230 1248 loc)
adamc@230 1249 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons"), loc),
adamc@268 1250 #1 obitem), loc)
adamc@268 1251 val e = (EApp (e, #2 obitem), loc)
adamc@230 1252 in
adamc@230 1253 (EApp (e, e'), loc)
adamc@230 1254 end)
adamc@268 1255 | obitem COMMA obexps (let
adamc@268 1256 val loc = s (obitemleft, obexpsright)
adamc@230 1257
adamc@230 1258 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons"), loc),
adamc@268 1259 #1 obitem), loc)
adamc@268 1260 val e = (EApp (e, #2 obitem), loc)
adamc@230 1261 in
adamc@230 1262 (EApp (e, obexps), loc)
adamc@230 1263 end)
adamc@231 1264
adamc@268 1265 diropt : (EVar (["Basis"], "sql_asc"), dummy)
adamc@268 1266 | ASC (EVar (["Basis"], "sql_asc"), s (ASCleft, ASCright))
adamc@268 1267 | DESC (EVar (["Basis"], "sql_desc"), s (DESCleft, DESCright))
adamc@268 1268
adamc@231 1269 lopt : (EVar (["Basis"], "sql_no_limit"), dummy)
adamc@232 1270 | LIMIT ALL (EVar (["Basis"], "sql_no_limit"), dummy)
adamc@231 1271 | LIMIT sqlint (let
adamc@231 1272 val loc = s (LIMITleft, sqlintright)
adamc@231 1273 in
adamc@231 1274 (EApp ((EVar (["Basis"], "sql_limit"), loc), sqlint), loc)
adamc@231 1275 end)
adamc@231 1276
adamc@232 1277 ofopt : (EVar (["Basis"], "sql_no_offset"), dummy)
adamc@232 1278 | OFFSET sqlint (let
adamc@232 1279 val loc = s (OFFSETleft, sqlintright)
adamc@232 1280 in
adamc@232 1281 (EApp ((EVar (["Basis"], "sql_offset"), loc), sqlint), loc)
adamc@232 1282 end)
adamc@232 1283
adamc@231 1284 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@231 1285 | LBRACE eexp RBRACE (eexp)
adamc@236 1286
adamc@236 1287 sqlagg : AVG ("avg")
adamc@236 1288 | SUM ("sum")
adamc@236 1289 | MIN ("min")
adamc@236 1290 | MAX ("max")