annotate src/urweb.grm @ 429:2f2d5c8dd320

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