annotate src/urweb.grm @ 383:49c95753bf3b

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