annotate src/lacweb.grm @ 242:cc193f680193

Shorthand for multi-binding exp declaration
author Adam Chlipala <adamc@hcoop.net>
date Thu, 28 Aug 2008 14:05:47 -0400
parents 052126db06e7
children 2b9dfaffb008
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@1 15 * THIS SOFTWARE 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@1 28 (* Grammar for Laconic/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@207 46
adamc@207 47 datatype select =
adamc@207 48 Star
adamc@207 49 | Items of select_item list
adamc@207 50
adamc@226 51 datatype group_item =
adamc@226 52 GField of con * con
adamc@226 53
adamc@207 54 fun eqTnames ((c1, _), (c2, _)) =
adamc@207 55 case (c1, c2) of
adamc@207 56 (CVar (ms1, x1), CVar (ms2, x2)) => ms1 = ms2 andalso x1 = x2
adamc@207 57 | (CName x1, CName x2) => x1 = x2
adamc@207 58 | _ => false
adamc@207 59
adamc@233 60 fun amend_select loc (si, (tabs, exps)) =
adamc@233 61 case si of
adamc@233 62 Field (tx, fx) =>
adamc@233 63 let
adamc@233 64 val c = (CRecord ([(fx, (CWild (KType, loc), loc))]), loc)
adamc@207 65
adamc@233 66 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
adamc@233 67 if eqTnames (tx, tx') then
adamc@233 68 ((tx', (CConcat (c, c'), loc)), true)
adamc@233 69 else
adamc@233 70 ((tx', c'), found))
adamc@233 71 false tabs
adamc@233 72 in
adamc@233 73 if found then
adamc@233 74 ()
adamc@233 75 else
adamc@233 76 ErrorMsg.errorAt loc "Select of field from unbound table";
adamc@233 77
adamc@233 78 (tabs, exps)
adamc@233 79 end
adamc@233 80 | Exp (c, e) => (tabs, (c, e) :: exps)
adamc@207 81
adamc@226 82 fun amend_group loc (gi, tabs) =
adamc@226 83 let
adamc@226 84 val (tx, c) = case gi of
adamc@226 85 GField (tx, fx) => (tx, (CRecord ([(fx, (CWild (KType, loc), loc))]), loc))
adamc@226 86
adamc@226 87 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
adamc@226 88 if eqTnames (tx, tx') then
adamc@226 89 ((tx', (CConcat (c, c'), loc)), true)
adamc@226 90 else
adamc@226 91 ((tx', c'), found))
adamc@226 92 false tabs
adamc@226 93 in
adamc@226 94 if found then
adamc@226 95 ()
adamc@226 96 else
adamc@226 97 ErrorMsg.errorAt loc "Select of field from unbound table";
adamc@226 98
adamc@226 99 tabs
adamc@226 100 end
adamc@226 101
adamc@209 102 fun sql_inject (v, t, loc) =
adamc@209 103 let
adamc@234 104 val e = (EApp ((EVar (["Basis"], "sql_inject"), loc), (t, loc)), loc)
adamc@209 105 in
adamc@234 106 (EApp (e, (v, loc)), loc)
adamc@209 107 end
adamc@209 108
adamc@219 109 fun sql_compare (oper, sqlexp1, sqlexp2, loc) =
adamc@219 110 let
adamc@219 111 val e = (EVar (["Basis"], "sql_comparison"), loc)
adamc@219 112 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper), loc)), loc)
adamc@219 113 val e = (EApp (e, sqlexp1), loc)
adamc@219 114 in
adamc@234 115 (EApp (e, sqlexp2), loc)
adamc@220 116 end
adamc@220 117
adamc@220 118 fun sql_binary (oper, sqlexp1, sqlexp2, loc) =
adamc@220 119 let
adamc@220 120 val e = (EVar (["Basis"], "sql_binary"), loc)
adamc@220 121 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper), loc)), loc)
adamc@220 122 val e = (EApp (e, sqlexp1), loc)
adamc@220 123 in
adamc@220 124 (EApp (e, sqlexp2), loc)
adamc@220 125 end
adamc@220 126
adamc@220 127 fun sql_unary (oper, sqlexp, loc) =
adamc@220 128 let
adamc@220 129 val e = (EVar (["Basis"], "sql_unary"), loc)
adamc@220 130 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper), loc)), loc)
adamc@220 131 in
adamc@220 132 (EApp (e, sqlexp), loc)
adamc@219 133 end
adamc@219 134
adamc@229 135 fun sql_relop (oper, sqlexp1, sqlexp2, loc) =
adamc@229 136 let
adamc@229 137 val e = (EVar (["Basis"], "sql_relop"), loc)
adamc@229 138 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper), loc)), loc)
adamc@229 139 val e = (EApp (e, sqlexp1), loc)
adamc@229 140 in
adamc@229 141 (EApp (e, sqlexp2), loc)
adamc@229 142 end
adamc@229 143
adamc@1 144 %%
adamc@1 145 %header (functor LacwebLrValsFn(structure Token : TOKEN))
adamc@1 146
adamc@1 147 %term
adamc@1 148 EOF
adamc@14 149 | STRING of string | INT of Int64.int | FLOAT of Real64.real
adamc@1 150 | SYMBOL of string | CSYMBOL of string
adamc@1 151 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
adamc@156 152 | EQ | COMMA | COLON | DCOLON | TCOLON | DOT | HASH | UNDER | UNDERUNDER | BAR
adamc@219 153 | DIVIDE | DOTDOTDOT
adamc@242 154 | CON | LTYPE | VAL | REC | AND | FUN | FOLD | UNIT | KUNIT | CLASS
adamc@156 155 | DATATYPE | OF
adamc@7 156 | TYPE | NAME
adamc@195 157 | ARROW | LARROW | DARROW | STAR
adamc@149 158 | FN | PLUSPLUS | MINUSMINUS | DOLLAR | TWIDDLE
adamc@88 159 | STRUCTURE | SIGNATURE | STRUCT | SIG | END | FUNCTOR | WHERE | EXTERN
adamc@203 160 | INCLUDE | OPEN | CONSTRAINT | CONSTRAINTS | EXPORT | TABLE
adamc@190 161 | CASE | IF | THEN | ELSE
adamc@1 162
adamc@91 163 | XML_BEGIN of string | XML_END
adamc@91 164 | NOTAGS of string
adamc@91 165 | BEGIN_TAG of string | END_TAG of string
adamc@91 166
adamc@230 167 | SELECT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING
adamc@229 168 | UNION | INTERSECT | EXCEPT
adamc@232 169 | LIMIT | OFFSET | ALL
adamc@220 170 | TRUE | FALSE | CAND | OR | NOT
adamc@236 171 | COUNT | AVG | SUM | MIN | MAX
adamc@219 172 | NE | LT | LE | GT | GE
adamc@204 173
adamc@30 174 %nonterm
adamc@1 175 file of decl list
adamc@1 176 | decls of decl list
adamc@1 177 | decl of decl
adamc@123 178 | vali of string * con option * exp
adamc@123 179 | valis of (string * con option * exp) list
adamc@242 180 | copt of con option
adamc@1 181
adamc@191 182 | dargs of string list
adamc@156 183 | barOpt of unit
adamc@156 184 | dcons of (string * con option) list
adamc@156 185 | dcon of string * con option
adamc@156 186
adamc@30 187 | sgn of sgn
adamc@42 188 | sgntm of sgn
adamc@30 189 | sgi of sgn_item
adamc@30 190 | sgis of sgn_item list
adamc@30 191
adamc@30 192 | str of str
adamc@30 193
adamc@1 194 | kind of kind
adamc@207 195 | ktuple of kind list
adamc@1 196 | kcolon of explicitness
adamc@240 197 | kopt of kind option
adamc@1 198
adamc@34 199 | path of string list * string
adamc@156 200 | cpath of string list * string
adamc@34 201 | spath of str
adamc@59 202 | mpath of string list
adamc@34 203
adamc@1 204 | cexp of con
adamc@1 205 | capps of con
adamc@1 206 | cterm of con
adamc@195 207 | ctuple of con list
adamc@207 208 | ctuplev of con list
adamc@1 209 | ident of con
adamc@200 210 | idents of con list
adamc@1 211 | rcon of (con * con) list
adamc@83 212 | rconn of (con * con) list
adamc@1 213 | rcone of (con * con) list
adamc@239 214 | cargs of con * kind -> con * kind
adamc@239 215 | cargl of con * kind -> con * kind
adamc@240 216 | cargl2 of con * kind -> con * kind
adamc@239 217 | carg of con * kind -> con * kind
adamc@239 218 | cargp of con * kind -> con * kind
adamc@1 219
adamc@8 220 | eexp of exp
adamc@8 221 | eapps of exp
adamc@8 222 | eterm of exp
adamc@195 223 | etuple of exp list
adamc@12 224 | rexp of (con * exp) list
adamc@91 225 | xml of exp
adamc@91 226 | xmlOne of exp
adamc@141 227 | tag of string * exp
adamc@141 228 | tagHead of string * exp
adamc@8 229
adamc@241 230 | earg of exp * con -> exp * con
adamc@241 231 | eargp of exp * con -> exp * con
adamc@241 232 | eargs of exp * con -> exp * con
adamc@241 233 | eargl of exp * con -> exp * con
adamc@242 234 | eargl2 of exp * con -> exp * con
adamc@241 235
adamc@170 236 | branch of pat * exp
adamc@170 237 | branchs of (pat * exp) list
adamc@170 238 | pat of pat
adamc@170 239 | pterm of pat
adamc@174 240 | rpat of (string * pat) list * bool
adamc@195 241 | ptuple of pat list
adamc@170 242
adamc@104 243 | attrs of (con * exp) list
adamc@104 244 | attr of con * exp
adamc@104 245 | attrv of exp
adamc@104 246
adamc@204 247 | query of exp
adamc@226 248 | query1 of exp
adamc@204 249 | tables of (con * exp) list
adamc@204 250 | tname of con
adamc@204 251 | table of con * exp
adamc@207 252 | tident of con
adamc@207 253 | fident of con
adamc@207 254 | seli of select_item
adamc@207 255 | selis of select_item list
adamc@207 256 | select of select
adamc@209 257 | sqlexp of exp
adamc@209 258 | wopt of exp
adamc@226 259 | groupi of group_item
adamc@226 260 | groupis of group_item list
adamc@226 261 | gopt of group_item list option
adamc@227 262 | hopt of exp
adamc@230 263 | obopt of exp
adamc@230 264 | obexps of exp
adamc@231 265 | lopt of exp
adamc@232 266 | ofopt of exp
adamc@231 267 | sqlint of exp
adamc@236 268 | sqlagg of string
adamc@207 269
adamc@204 270
adamc@1 271 %verbose (* print summary of errors *)
adamc@1 272 %pos int (* positions *)
adamc@1 273 %start file
adamc@1 274 %pure
adamc@1 275 %eop EOF
adamc@1 276 %noshift EOF
adamc@1 277
adamc@1 278 %name Lacweb
adamc@1 279
adamc@195 280 %nonassoc IF THEN ELSE
adamc@1 281 %nonassoc DARROW
adamc@1 282 %nonassoc COLON
adamc@6 283 %nonassoc DCOLON TCOLON
adamc@229 284 %left UNION INTERSECT EXCEPT
adamc@1 285 %right COMMA
adamc@220 286 %right OR
adamc@220 287 %right CAND
adamc@219 288 %nonassoc EQ NE LT LE GT GE
adamc@1 289 %right ARROW LARROW
adamc@149 290 %right PLUSPLUS MINUSMINUS
adamc@195 291 %right STAR
adamc@220 292 %left NOT
adamc@84 293 %nonassoc TWIDDLE
adamc@1 294 %nonassoc DOLLAR
adamc@1 295 %left DOT
adamc@221 296 %nonassoc LBRACE RBRACE
adamc@1 297
adamc@1 298 %%
adamc@1 299
adamc@1 300 file : decls (decls)
adamc@54 301 | SIG sgis ([(DSgn ("?", (SgnConst sgis, s (SIGleft, sgisright))),
adamc@54 302 s (SIGleft, sgisright))])
adamc@1 303
adamc@1 304 decls : ([])
adamc@1 305 | decl decls (decl :: decls)
adamc@1 306
adamc@240 307 decl : CON SYMBOL cargl2 kopt EQ cexp (let
adamc@240 308 val loc = s (CONleft, cexpright)
adamc@240 309
adamc@240 310 val k = Option.getOpt (kopt, (KWild, loc))
adamc@240 311 val (c, k) = cargl2 (cexp, k)
adamc@240 312 in
adamc@240 313 (DCon (SYMBOL, SOME k, c), loc)
adamc@240 314 end)
adamc@7 315 | LTYPE SYMBOL EQ cexp (DCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
adamc@7 316 s (LTYPEleft, cexpright))
adamc@191 317 | DATATYPE SYMBOL dargs EQ barOpt dcons(DDatatype (SYMBOL, dargs, dcons), s (DATATYPEleft, dconsright))
adamc@191 318 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
adamc@191 319 (case dargs of
adamc@191 320 [] => (DDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
adamc@191 321 | _ => raise Fail "Arguments specified for imported datatype")
adamc@123 322 | VAL vali (DVal vali, s (VALleft, valiright))
adamc@123 323 | VAL REC valis (DValRec valis, s (VALleft, valisright))
adamc@242 324 | FUN valis (DValRec valis, s (FUNleft, valisright))
adamc@1 325
adamc@30 326 | SIGNATURE CSYMBOL EQ sgn (DSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))
adamc@30 327 | STRUCTURE CSYMBOL EQ str (DStr (CSYMBOL, NONE, str), s (STRUCTUREleft, strright))
adamc@30 328 | STRUCTURE CSYMBOL COLON sgn EQ str (DStr (CSYMBOL, SOME sgn, str), s (STRUCTUREleft, strright))
adamc@42 329 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN EQ str
adamc@42 330 (DStr (CSYMBOL1, NONE,
adamc@42 331 (StrFun (CSYMBOL2, sgn1, NONE, str), s (FUNCTORleft, strright))),
adamc@42 332 s (FUNCTORleft, strright))
adamc@42 333 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn EQ str
adamc@42 334 (DStr (CSYMBOL1, NONE,
adamc@42 335 (StrFun (CSYMBOL2, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))),
adamc@42 336 s (FUNCTORleft, strright))
adamc@48 337 | EXTERN STRUCTURE CSYMBOL COLON sgn (DFfiStr (CSYMBOL, sgn), s (EXTERNleft, sgnright))
adamc@61 338 | OPEN mpath (case mpath of
adamc@61 339 [] => raise Fail "Impossible mpath parse [1]"
adamc@61 340 | m :: ms => (DOpen (m, ms), s (OPENleft, mpathright)))
adamc@88 341 | OPEN CONSTRAINTS mpath (case mpath of
adamc@88 342 [] => raise Fail "Impossible mpath parse [3]"
adamc@88 343 | m :: ms => (DOpenConstraints (m, ms), s (OPENleft, mpathright)))
adamc@88 344 | CONSTRAINT cterm TWIDDLE cterm (DConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))
adamc@109 345 | EXPORT spath (DExport spath, s (EXPORTleft, spathright))
adamc@203 346 | TABLE SYMBOL COLON cexp (DTable (SYMBOL, entable cexp), s (TABLEleft, cexpright))
adamc@211 347 | CLASS SYMBOL EQ cexp (DClass (SYMBOL, cexp), s (CLASSleft, cexpright))
adamc@211 348 | CLASS SYMBOL SYMBOL EQ cexp (let
adamc@211 349 val loc = s (CLASSleft, cexpright)
adamc@211 350 val k = (KType, loc)
adamc@211 351 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
adamc@211 352 in
adamc@211 353 (DClass (SYMBOL1, c), s (CLASSleft, cexpright))
adamc@211 354 end)
adamc@30 355
adamc@240 356 kopt : (NONE)
adamc@240 357 | DCOLON kind (SOME kind)
adamc@240 358
adamc@191 359 dargs : ([])
adamc@191 360 | SYMBOL dargs (SYMBOL :: dargs)
adamc@191 361
adamc@156 362 barOpt : ()
adamc@156 363 | BAR ()
adamc@156 364
adamc@156 365 dcons : dcon ([dcon])
adamc@156 366 | dcon BAR dcons (dcon :: dcons)
adamc@156 367
adamc@156 368 dcon : CSYMBOL (CSYMBOL, NONE)
adamc@156 369 | CSYMBOL OF cexp (CSYMBOL, SOME cexp)
adamc@156 370
adamc@242 371 vali : SYMBOL eargl2 copt EQ eexp (let
adamc@242 372 val loc = s (SYMBOLleft, eexpright)
adamc@242 373 val t = Option.getOpt (copt, (CWild (KType, loc), loc))
adamc@242 374
adamc@242 375 val (e, t) = eargl2 (eexp, t)
adamc@242 376 in
adamc@242 377 (SYMBOL, SOME t, e)
adamc@242 378 end)
adamc@242 379
adamc@242 380 copt : (NONE)
adamc@242 381 | COLON cexp (SOME cexp)
adamc@123 382
adamc@123 383 valis : vali ([vali])
adamc@123 384 | vali AND valis (vali :: valis)
adamc@123 385
adamc@42 386 sgn : sgntm (sgntm)
adamc@40 387 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@40 388 (SgnFun (CSYMBOL, sgn1, sgn2), s (FUNCTORleft, sgn2right))
adamc@30 389
adamc@42 390 sgntm : SIG sgis END (SgnConst sgis, s (SIGleft, ENDright))
adamc@59 391 | mpath (case mpath of
adamc@61 392 [] => raise Fail "Impossible mpath parse [2]"
adamc@59 393 | [x] => SgnVar x
adamc@59 394 | m :: ms => SgnProj (m,
adamc@59 395 List.take (ms, length ms - 1),
adamc@59 396 List.nth (ms, length ms - 1)),
adamc@59 397 s (mpathleft, mpathright))
adamc@42 398 | sgntm WHERE CON SYMBOL EQ cexp (SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
adamc@42 399 | sgntm WHERE LTYPE SYMBOL EQ cexp(SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
adamc@42 400 | LPAREN sgn RPAREN (sgn)
adamc@42 401
adamc@30 402 sgi : CON SYMBOL DCOLON kind (SgiConAbs (SYMBOL, kind), s (CONleft, kindright))
adamc@30 403 | LTYPE SYMBOL (SgiConAbs (SYMBOL, (KType, s (LTYPEleft, SYMBOLright))),
adamc@30 404 s (LTYPEleft, SYMBOLright))
adamc@30 405 | CON SYMBOL EQ cexp (SgiCon (SYMBOL, NONE, cexp), s (CONleft, cexpright))
adamc@30 406 | CON SYMBOL DCOLON kind EQ cexp (SgiCon (SYMBOL, SOME kind, cexp), s (CONleft, cexpright))
adamc@30 407 | LTYPE SYMBOL EQ cexp (SgiCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
adamc@30 408 s (LTYPEleft, cexpright))
adamc@191 409 | DATATYPE SYMBOL dargs EQ barOpt dcons(SgiDatatype (SYMBOL, dargs, dcons), s (DATATYPEleft, dconsright))
adamc@191 410 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
adamc@191 411 (case dargs of
adamc@191 412 [] => (SgiDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
adamc@191 413 | _ => raise Fail "Arguments specified for imported datatype")
adamc@30 414 | VAL SYMBOL COLON cexp (SgiVal (SYMBOL, cexp), s (VALleft, cexpright))
adamc@30 415
adamc@30 416 | STRUCTURE CSYMBOL COLON sgn (SgiStr (CSYMBOL, sgn), s (STRUCTUREleft, sgnright))
adamc@59 417 | SIGNATURE CSYMBOL EQ sgn (SgiSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))
adamc@42 418 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@42 419 (SgiStr (CSYMBOL1,
adamc@42 420 (SgnFun (CSYMBOL2, sgn1, sgn2), s (FUNCTORleft, sgn2right))),
adamc@42 421 s (FUNCTORleft, sgn2right))
adamc@58 422 | INCLUDE sgn (SgiInclude sgn, s (INCLUDEleft, sgnright))
adamc@88 423 | CONSTRAINT cterm TWIDDLE cterm (SgiConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))
adamc@203 424 | TABLE SYMBOL COLON cexp (SgiTable (SYMBOL, entable cexp), s (TABLEleft, cexpright))
adamc@211 425 | CLASS SYMBOL (SgiClassAbs SYMBOL, s (CLASSleft, SYMBOLright))
adamc@211 426 | CLASS SYMBOL EQ cexp (SgiClass (SYMBOL, cexp), s (CLASSleft, cexpright))
adamc@211 427 | CLASS SYMBOL SYMBOL EQ cexp (let
adamc@211 428 val loc = s (CLASSleft, cexpright)
adamc@211 429 val k = (KType, loc)
adamc@211 430 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
adamc@211 431 in
adamc@211 432 (SgiClass (SYMBOL1, c), s (CLASSleft, cexpright))
adamc@211 433 end)
adamc@30 434
adamc@30 435 sgis : ([])
adamc@30 436 | sgi sgis (sgi :: sgis)
adamc@30 437
adamc@30 438 str : STRUCT decls END (StrConst decls, s (STRUCTleft, ENDright))
adamc@34 439 | spath (spath)
adamc@40 440 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN DARROW str
adamc@40 441 (StrFun (CSYMBOL, sgn, NONE, str), s (FUNCTORleft, strright))
adamc@40 442 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn DARROW str
adamc@40 443 (StrFun (CSYMBOL, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))
adamc@44 444 | spath LPAREN str RPAREN (StrApp (spath, str), s (spathleft, RPARENright))
adamc@34 445
adamc@34 446 spath : CSYMBOL (StrVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@34 447 | spath DOT CSYMBOL (StrProj (spath, CSYMBOL), s (spathleft, CSYMBOLright))
adamc@30 448
adamc@1 449 kind : TYPE (KType, s (TYPEleft, TYPEright))
adamc@1 450 | NAME (KName, s (NAMEleft, NAMEright))
adamc@1 451 | LBRACE kind RBRACE (KRecord kind, s (LBRACEleft, RBRACEright))
adamc@1 452 | kind ARROW kind (KArrow (kind1, kind2), s (kind1left, kind2right))
adamc@1 453 | LPAREN kind RPAREN (#1 kind, s (LPARENleft, RPARENright))
adamc@82 454 | KUNIT (KUnit, s (KUNITleft, KUNITright))
adamc@18 455 | UNDERUNDER (KWild, s (UNDERUNDERleft, UNDERUNDERright))
adamc@207 456 | LPAREN ktuple RPAREN (KTuple ktuple, s (LPARENleft, RPARENright))
adamc@207 457
adamc@207 458 ktuple : kind STAR kind ([kind1, kind2])
adamc@207 459 | kind STAR ktuple (kind :: ktuple)
adamc@1 460
adamc@1 461 capps : cterm (cterm)
adamc@1 462 | capps cterm (CApp (capps, cterm), s (cappsleft, ctermright))
adamc@1 463
adamc@1 464 cexp : capps (capps)
adamc@1 465 | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right))
adamc@15 466 | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright))
adamc@1 467
adamc@1 468 | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right))
adamc@1 469
adamc@239 470 | FN cargs DARROW cexp (#1 (cargs (cexp, (KWild, s (FNleft, cexpright)))))
adamc@84 471 | cterm TWIDDLE cterm DARROW cexp(CDisjoint (cterm1, cterm2, cexp), s (cterm1left, cexpright))
adamc@85 472 | cterm TWIDDLE cterm ARROW cexp (TDisjoint (cterm1, cterm2, cexp), s (cterm1left, cexpright))
adamc@1 473
adamc@8 474 | LPAREN cexp RPAREN DCOLON kind (CAnnot (cexp, kind), s (LPARENleft, kindright))
adamc@6 475
adamc@18 476 | UNDER DCOLON kind (CWild kind, s (UNDERleft, UNDERright))
adamc@195 477 | ctuple (let
adamc@195 478 val loc = s (ctupleleft, ctupleright)
adamc@195 479 in
adamc@195 480 (TRecord (CRecord (ListUtil.mapi (fn (i, c) =>
adamc@195 481 ((CName (Int.toString (i + 1)), loc),
adamc@195 482 c)) ctuple),
adamc@195 483 loc), loc)
adamc@195 484 end)
adamc@18 485
adamc@1 486 kcolon : DCOLON (Explicit)
adamc@1 487 | TCOLON (Implicit)
adamc@1 488
adamc@239 489 cargs : carg (carg)
adamc@239 490 | cargl (cargl)
adamc@239 491
adamc@239 492 cargl : cargp cargp (cargp1 o cargp2)
adamc@239 493 | cargp cargl (cargp o cargl)
adamc@239 494
adamc@240 495 cargl2 : (fn x => x)
adamc@240 496 | cargp cargl2 (cargp o cargl2)
adamc@240 497
adamc@241 498 carg : SYMBOL DCOLON kind (fn (c, k) =>
adamc@239 499 let
adamc@239 500 val loc = s (SYMBOLleft, kindright)
adamc@239 501 in
adamc@239 502 ((CAbs (SYMBOL, SOME kind, c), loc),
adamc@239 503 (KArrow (kind, k), loc))
adamc@239 504 end)
adamc@241 505 | cargp (cargp)
adamc@239 506
adamc@239 507 cargp : SYMBOL (fn (c, k) =>
adamc@239 508 let
adamc@239 509 val loc = s (SYMBOLleft, SYMBOLright)
adamc@239 510 in
adamc@239 511 ((CAbs (SYMBOL, NONE, c), loc),
adamc@239 512 (KArrow ((KWild, loc), k), loc))
adamc@239 513 end)
adamc@239 514 | LPAREN SYMBOL DCOLON kind RPAREN (fn (c, k) =>
adamc@239 515 let
adamc@239 516 val loc = s (LPARENleft, RPARENright)
adamc@239 517 in
adamc@239 518 ((CAbs (SYMBOL, SOME kind, c), loc),
adamc@239 519 (KArrow (kind, k), loc))
adamc@239 520 end)
adamc@239 521
adamc@34 522 path : SYMBOL ([], SYMBOL)
adamc@34 523 | CSYMBOL DOT path (let val (ms, x) = path in (CSYMBOL :: ms, x) end)
adamc@34 524
adamc@156 525 cpath : CSYMBOL ([], CSYMBOL)
adamc@156 526 | CSYMBOL DOT cpath (let val (ms, x) = cpath in (CSYMBOL :: ms, x) end)
adamc@156 527
adamc@59 528 mpath : CSYMBOL ([CSYMBOL])
adamc@59 529 | CSYMBOL DOT mpath (CSYMBOL :: mpath)
adamc@59 530
adamc@1 531 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright))
adamc@1 532 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright))
adamc@83 533 | LBRACK rconn RBRACK (CRecord rconn, s (LBRACKleft, RBRACKright))
adamc@1 534 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)),
adamc@1 535 s (LBRACEleft, RBRACEright))
adamc@1 536 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright))
adamc@1 537 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright))
adamc@195 538 | HASH INT (CName (Int64.toString INT), s (HASHleft, INTright))
adamc@1 539
adamc@34 540 | path (CVar path, s (pathleft, pathright))
adamc@207 541 | path DOT INT (CProj ((CVar path, s (pathleft, pathright)), Int64.toInt INT),
adamc@207 542 s (pathleft, INTright))
adamc@18 543 | UNDER (CWild (KWild, s (UNDERleft, UNDERright)), s (UNDERleft, UNDERright))
adamc@67 544 | FOLD (CFold, s (FOLDleft, FOLDright))
adamc@82 545 | UNIT (CUnit, s (UNITleft, UNITright))
adamc@207 546 | LPAREN ctuplev RPAREN (CTuple ctuplev, s (LPARENleft, RPARENright))
adamc@207 547
adamc@207 548 ctuplev: cexp COMMA cexp ([cexp1, cexp2])
adamc@207 549 | cexp COMMA ctuplev (cexp :: ctuplev)
adamc@1 550
adamc@196 551 ctuple : capps STAR capps ([capps1, capps2])
adamc@196 552 | capps STAR ctuple (capps :: ctuple)
adamc@195 553
adamc@1 554 rcon : ([])
adamc@1 555 | ident EQ cexp ([(ident, cexp)])
adamc@1 556 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon)
adamc@1 557
adamc@83 558 rconn : ident ([(ident, (CUnit, s (identleft, identright)))])
adamc@83 559 | ident COMMA rconn ((ident, (CUnit, s (identleft, identright))) :: rconn)
adamc@83 560
adamc@1 561 rcone : ([])
adamc@1 562 | ident COLON cexp ([(ident, cexp)])
adamc@1 563 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone)
adamc@1 564
adamc@1 565 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@195 566 | INT (CName (Int64.toString INT), s (INTleft, INTright))
adamc@200 567 | SYMBOL (CVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@8 568
adamc@8 569 eapps : eterm (eterm)
adamc@8 570 | eapps eterm (EApp (eapps, eterm), s (eappsleft, etermright))
adamc@8 571 | eapps LBRACK cexp RBRACK (ECApp (eapps, cexp), s (eappsleft, RBRACKright))
adamc@8 572
adamc@8 573 eexp : eapps (eapps)
adamc@241 574 | FN eargs DARROW eexp (let
adamc@93 575 val loc = s (FNleft, eexpright)
adamc@93 576 in
adamc@241 577 #1 (eargs (eexp, (CWild (KType, loc), loc)))
adamc@93 578 end)
adamc@241 579 | LBRACK cterm TWIDDLE cterm RBRACK DARROW eexp(EDisjoint (cterm1, cterm2, eexp), s (LBRACKleft, RBRACKright))
adamc@196 580 | eexp COLON cexp (EAnnot (eexp, cexp), s (eexpleft, cexpright))
adamc@149 581 | eexp MINUSMINUS cexp (ECut (eexp, cexp), s (eexpleft, cexpright))
adamc@170 582 | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
adamc@190 583 | IF eexp THEN eexp ELSE eexp (let
adamc@190 584 val loc = s (IFleft, eexp3right)
adamc@190 585 in
adamc@190 586 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc), eexp2),
adamc@190 587 ((PCon (["Basis"], "False", NONE), loc), eexp3)]), loc)
adamc@190 588 end)
adamc@8 589
adamc@241 590 eargs : earg (earg)
adamc@241 591 | eargl (eargl)
adamc@241 592
adamc@241 593 eargl : eargp eargp (eargp1 o eargp2)
adamc@241 594 | eargp eargl (eargp o eargl)
adamc@241 595
adamc@242 596 eargl2 : (fn x => x)
adamc@242 597 | eargp eargl2 (eargp o eargl2)
adamc@242 598
adamc@241 599 earg : SYMBOL kcolon kind (fn (e, t) =>
adamc@241 600 let
adamc@241 601 val loc = s (SYMBOLleft, kindright)
adamc@241 602 in
adamc@241 603 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
adamc@241 604 (TCFun (kcolon, SYMBOL, kind, t), loc))
adamc@241 605 end)
adamc@241 606 | SYMBOL COLON cexp (fn (e, t) =>
adamc@241 607 let
adamc@241 608 val loc = s (SYMBOLleft, cexpright)
adamc@241 609 in
adamc@241 610 ((EAbs (SYMBOL, SOME cexp, e), loc),
adamc@241 611 (TFun (cexp, t), loc))
adamc@241 612 end)
adamc@241 613 | UNDER COLON cexp (fn (e, t) =>
adamc@241 614 let
adamc@241 615 val loc = s (UNDERleft, cexpright)
adamc@241 616 in
adamc@241 617 ((EAbs ("_", SOME cexp, e), loc),
adamc@241 618 (TFun (cexp, t), loc))
adamc@241 619 end)
adamc@241 620 | eargp (eargp)
adamc@241 621
adamc@241 622 eargp : SYMBOL (fn (e, t) =>
adamc@241 623 let
adamc@241 624 val loc = s (SYMBOLleft, SYMBOLright)
adamc@241 625 in
adamc@241 626 ((EAbs (SYMBOL, NONE, e), loc),
adamc@241 627 (TFun ((CWild (KType, loc), loc), t), loc))
adamc@241 628 end)
adamc@241 629 | UNIT (fn (e, t) =>
adamc@241 630 let
adamc@241 631 val loc = s (UNITleft, UNITright)
adamc@241 632 val t' = (TRecord (CRecord [], loc), loc)
adamc@241 633 in
adamc@241 634 ((EAbs ("_", SOME t', e), loc),
adamc@241 635 (TFun (t', t), loc))
adamc@241 636 end)
adamc@241 637 | UNDER (fn (e, t) =>
adamc@241 638 let
adamc@241 639 val loc = s (UNDERleft, UNDERright)
adamc@241 640 in
adamc@241 641 ((EAbs ("_", NONE, e), loc),
adamc@241 642 (TFun ((CWild (KType, loc), loc), t), loc))
adamc@241 643 end)
adamc@241 644 | LPAREN SYMBOL kcolon kind RPAREN(fn (e, t) =>
adamc@241 645 let
adamc@241 646 val loc = s (LPARENleft, RPARENright)
adamc@241 647 in
adamc@241 648 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
adamc@241 649 (TCFun (kcolon, SYMBOL, kind, t), loc))
adamc@241 650 end)
adamc@241 651 | LPAREN SYMBOL COLON cexp RPAREN (fn (e, t) =>
adamc@241 652 let
adamc@241 653 val loc = s (LPARENleft, RPARENright)
adamc@241 654 in
adamc@241 655 ((EAbs (SYMBOL, SOME cexp, e), loc),
adamc@241 656 (TFun (cexp, t), loc))
adamc@241 657 end)
adamc@241 658 | LPAREN UNDER COLON cexp RPAREN (fn (e, t) =>
adamc@241 659 let
adamc@241 660 val loc = s (LPARENleft, RPARENright)
adamc@241 661 in
adamc@241 662 ((EAbs ("_", SOME cexp, e), loc),
adamc@241 663 (TFun (cexp, t), loc))
adamc@241 664 end)
adamc@241 665
adamc@8 666 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
adamc@195 667 | LPAREN etuple RPAREN (let
adamc@195 668 val loc = s (LPARENleft, RPARENright)
adamc@195 669 in
adamc@195 670 (ERecord (ListUtil.mapi (fn (i, e) =>
adamc@195 671 ((CName (Int.toString (i + 1)), loc),
adamc@195 672 e)) etuple), loc)
adamc@195 673 end)
adamc@8 674
adamc@34 675 | path (EVar path, s (pathleft, pathright))
adamc@156 676 | cpath (EVar cpath, s (cpathleft, cpathright))
adamc@12 677 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
adamc@110 678 | UNIT (ERecord [], s (UNITleft, UNITright))
adamc@12 679
adamc@14 680 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@14 681 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@14 682 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@14 683
adamc@200 684 | path DOT idents (let
adamc@200 685 val loc = s (pathleft, identsright)
adamc@200 686 in
adamc@200 687 foldl (fn (ident, e) =>
adamc@200 688 (EField (e, ident), loc))
adamc@200 689 (EVar path, s (pathleft, pathright)) idents
adamc@200 690 end)
adamc@71 691 | FOLD (EFold, s (FOLDleft, FOLDright))
adamc@71 692
adamc@91 693 | XML_BEGIN xml XML_END (xml)
adamc@91 694 | XML_BEGIN XML_END (EApp ((EVar (["Basis"], "cdata"), s (XML_BEGINleft, XML_ENDright)),
adamc@91 695 (EPrim (Prim.String ""), s (XML_BEGINleft, XML_ENDright))),
adamc@91 696 s (XML_BEGINleft, XML_ENDright))
adamc@204 697 | LPAREN query RPAREN (query)
adamc@211 698 | UNDER (EWild, s (UNDERleft, UNDERright))
adamc@91 699
adamc@200 700 idents : ident ([ident])
adamc@200 701 | ident DOT idents (ident :: idents)
adamc@200 702
adamc@195 703 etuple : eexp COMMA eexp ([eexp1, eexp2])
adamc@195 704 | eexp COMMA etuple (eexp :: etuple)
adamc@195 705
adamc@170 706 branch : pat DARROW eexp (pat, eexp)
adamc@170 707
adamc@170 708 branchs: ([])
adamc@170 709 | BAR branch branchs (branch :: branchs)
adamc@170 710
adamc@170 711 pat : pterm (pterm)
adamc@170 712 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
adamc@170 713
adamc@170 714 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
adamc@170 715 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
adamc@170 716 | UNDER (PWild, s (UNDERleft, UNDERright))
adamc@173 717 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
adamc@173 718 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@170 719 | LPAREN pat RPAREN (pat)
adamc@174 720 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
adamc@174 721 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
adamc@174 722 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
adamc@195 723 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
adamc@195 724 false),
adamc@195 725 s (LPARENleft, RPARENright))
adamc@174 726
adamc@175 727 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
adamc@174 728 | DOTDOTDOT ([], true)
adamc@175 729 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
adamc@170 730
adamc@195 731 ptuple : pat COMMA pat ([pat1, pat2])
adamc@195 732 | pat COMMA ptuple (pat :: ptuple)
adamc@195 733
adamc@12 734 rexp : ([])
adamc@12 735 | ident EQ eexp ([(ident, eexp)])
adamc@12 736 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
adamc@91 737
adamc@141 738 xml : xmlOne xml (let
adamc@141 739 val pos = s (xmlOneleft, xmlright)
adamc@141 740 in
adamc@141 741 (EApp ((EApp (
adamc@141 742 (EVar (["Basis"], "join"), pos),
adamc@91 743 xmlOne), pos),
adamc@141 744 xml), pos)
adamc@141 745 end)
adamc@141 746 | xmlOne (xmlOne)
adamc@91 747
adamc@141 748 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata"), s (NOTAGSleft, NOTAGSright)),
adamc@141 749 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
adamc@141 750 s (NOTAGSleft, NOTAGSright))
adamc@141 751 | tag DIVIDE GT (let
adamc@141 752 val pos = s (tagleft, GTright)
adamc@141 753 in
adamc@141 754 (EApp (#2 tag,
adamc@141 755 (EApp ((EVar (["Basis"], "cdata"), pos),
adamc@141 756 (EPrim (Prim.String ""), pos)),
adamc@141 757 pos)), pos)
adamc@141 758 end)
adamc@141 759
adamc@141 760 | tag GT xml END_TAG (let
adamc@141 761 val pos = s (tagleft, GTright)
adamc@141 762 in
adamc@141 763 if #1 tag = END_TAG then
adamc@141 764 if END_TAG = "lform" then
adamc@141 765 (EApp ((EVar (["Basis"], "lform"), pos),
adamc@141 766 xml), pos)
adamc@141 767 else
adamc@141 768 (EApp (#2 tag, xml), pos)
adamc@141 769 else
adamc@141 770 (ErrorMsg.errorAt pos "Begin and end tags don't match.";
adamc@141 771 (EFold, pos))
adamc@141 772 end)
adamc@141 773 | LBRACE eexp RBRACE (eexp)
adamc@92 774
adamc@141 775 tag : tagHead attrs (let
adamc@141 776 val pos = s (tagHeadleft, attrsright)
adamc@141 777 in
adamc@141 778 (#1 tagHead,
adamc@141 779 (EApp ((EApp ((EVar (["Basis"], "tag"), pos),
adamc@141 780 (ERecord attrs, pos)), pos),
adamc@141 781 (EApp (#2 tagHead,
adamc@141 782 (ERecord [], pos)), pos)),
adamc@141 783 pos))
adamc@141 784 end)
adamc@141 785
adamc@141 786 tagHead: BEGIN_TAG (let
adamc@141 787 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
adamc@141 788 in
adamc@141 789 (BEGIN_TAG,
adamc@141 790 (EVar ([], BEGIN_TAG), pos))
adamc@141 791 end)
adamc@141 792 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
adamc@92 793
adamc@104 794 attrs : ([])
adamc@104 795 | attr attrs (attr :: attrs)
adamc@104 796
adamc@204 797 attr : SYMBOL EQ attrv ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)), attrv)
adamc@204 798
adamc@104 799 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@104 800 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@104 801 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@110 802 | LBRACE eexp RBRACE (eexp)
adamc@226 803
adamc@232 804 query : query1 obopt lopt ofopt (let
adamc@229 805 val loc = s (query1left, query1right)
adamc@230 806
adamc@230 807 val re = (ERecord [((CName "Rows", loc),
adamc@230 808 query1),
adamc@230 809 ((CName "OrderBy", loc),
adamc@231 810 obopt),
adamc@231 811 ((CName "Limit", loc),
adamc@232 812 lopt),
adamc@232 813 ((CName "Offset", loc),
adamc@232 814 ofopt)], loc)
adamc@229 815 in
adamc@230 816 (EApp ((EVar (["Basis"], "sql_query"), loc), re), loc)
adamc@229 817 end)
adamc@204 818
adamc@227 819 query1 : SELECT select FROM tables wopt gopt hopt
adamc@209 820 (let
adamc@204 821 val loc = s (SELECTleft, tablesright)
adamc@207 822
adamc@233 823 val (sel, exps) =
adamc@207 824 case select of
adamc@233 825 Star => (map (fn (nm, _) =>
adamc@233 826 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
adamc@233 827 loc),
adamc@233 828 (CRecord [], loc)],
adamc@233 829 loc))) tables,
adamc@233 830 [])
adamc@207 831 | Items sis =>
adamc@207 832 let
adamc@207 833 val tabs = map (fn (nm, _) => (nm, (CRecord [], loc))) tables
adamc@233 834 val (tabs, exps) = foldl (amend_select loc) (tabs, []) sis
adamc@207 835 in
adamc@233 836 (map (fn (nm, c) => (nm,
adamc@233 837 (CTuple [c,
adamc@233 838 (CWild (KRecord (KType, loc), loc),
adamc@233 839 loc)], loc))) tabs,
adamc@233 840 exps)
adamc@207 841 end
adamc@207 842
adamc@207 843 val sel = (CRecord sel, loc)
adamc@207 844
adamc@226 845 val grp = case gopt of
adamc@226 846 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all"), loc),
adamc@226 847 (CWild (KRecord (KRecord (KType, loc), loc),
adamc@226 848 loc), loc)), loc)
adamc@226 849 | SOME gis =>
adamc@226 850 let
adamc@226 851 val tabs = map (fn (nm, _) =>
adamc@226 852 (nm, (CRecord [], loc))) tables
adamc@226 853 val tabs = foldl (amend_group loc) tabs gis
adamc@226 854
adamc@226 855 val tabs = map (fn (nm, c) =>
adamc@226 856 (nm,
adamc@226 857 (CTuple [c,
adamc@226 858 (CWild (KRecord (KType, loc),
adamc@226 859 loc),
adamc@226 860 loc)], loc))) tabs
adamc@226 861 in
adamc@226 862 (ECApp ((EVar (["Basis"], "sql_subset"), loc),
adamc@226 863 (CRecord tabs, loc)), loc)
adamc@226 864 end
adamc@226 865
adamc@229 866 val e = (EVar (["Basis"], "sql_query1"), loc)
adamc@209 867 val re = (ERecord [((CName "From", loc),
adamc@209 868 (ERecord tables, loc)),
adamc@209 869 ((CName "Where", loc),
adamc@223 870 wopt),
adamc@224 871 ((CName "GroupBy", loc),
adamc@226 872 grp),
adamc@224 873 ((CName "Having", loc),
adamc@224 874 hopt),
adamc@223 875 ((CName "SelectFields", loc),
adamc@223 876 (ECApp ((EVar (["Basis"], "sql_subset"), loc),
adamc@233 877 sel), loc)),
adamc@233 878 ((CName "SelectExps", loc),
adamc@233 879 (ERecord exps, loc))], loc)
adamc@223 880
adamc@209 881 val e = (EApp (e, re), loc)
adamc@204 882 in
adamc@207 883 e
adamc@204 884 end)
adamc@229 885 | query1 UNION query1 (sql_relop ("union", query11, query12, s (query11left, query12right)))
adamc@229 886 | query1 INTERSECT query1 (sql_relop ("intersect", query11, query12, s (query11left, query12right)))
adamc@229 887 | query1 EXCEPT query1 (sql_relop ("except", query11, query12, s (query11left, query12right)))
adamc@204 888
adamc@204 889 tables : table ([table])
adamc@204 890 | table COMMA tables (table :: tables)
adamc@204 891
adamc@204 892 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@204 893 | LBRACE cexp RBRACE (cexp)
adamc@204 894
adamc@207 895 table : SYMBOL ((CName SYMBOL, s (SYMBOLleft, SYMBOLright)),
adamc@204 896 (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright)))
adamc@204 897 | SYMBOL AS tname (tname, (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright)))
adamc@221 898 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
adamc@207 899
adamc@207 900 tident : SYMBOL (CName SYMBOL, s (SYMBOLleft, SYMBOLright))
adamc@207 901 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@221 902 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
adamc@207 903
adamc@207 904 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@207 905 | LBRACE cexp RBRACE (cexp)
adamc@207 906
adamc@207 907 seli : tident DOT fident (Field (tident, fident))
adamc@233 908 | sqlexp AS fident (Exp (fident, sqlexp))
adamc@207 909
adamc@207 910 selis : seli ([seli])
adamc@207 911 | seli COMMA selis (seli :: selis)
adamc@207 912
adamc@207 913 select : STAR (Star)
adamc@207 914 | selis (Items selis)
adamc@209 915
adamc@209 916 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True"),
adamc@209 917 EVar (["Basis"], "sql_bool"),
adamc@209 918 s (TRUEleft, TRUEright)))
adamc@209 919 | FALSE (sql_inject (EVar (["Basis"], "False"),
adamc@209 920 EVar (["Basis"], "sql_bool"),
adamc@209 921 s (FALSEleft, FALSEright)))
adamc@209 922
adamc@222 923 | INT (sql_inject (EPrim (Prim.Int INT),
adamc@222 924 EVar (["Basis"], "sql_int"),
adamc@222 925 s (INTleft, INTright)))
adamc@222 926 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
adamc@222 927 EVar (["Basis"], "sql_float"),
adamc@222 928 s (FLOATleft, FLOATright)))
adamc@229 929 | STRING (sql_inject (EPrim (Prim.String STRING),
adamc@229 930 EVar (["Basis"], "sql_string"),
adamc@229 931 s (STRINGleft, STRINGright)))
adamc@222 932
adamc@221 933 | tident DOT fident (let
adamc@221 934 val loc = s (tidentleft, fidentright)
adamc@221 935 val e = (EVar (["Basis"], "sql_field"), loc)
adamc@221 936 val e = (ECApp (e, tident), loc)
adamc@221 937 in
adamc@221 938 (ECApp (e, fident), loc)
adamc@221 939 end)
adamc@234 940 | CSYMBOL (let
adamc@234 941 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@234 942 val e = (EVar (["Basis"], "sql_exp"), loc)
adamc@234 943 in
adamc@234 944 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@234 945 end)
adamc@221 946
adamc@219 947 | sqlexp EQ sqlexp (sql_compare ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 948 | sqlexp NE sqlexp (sql_compare ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 949 | sqlexp LT sqlexp (sql_compare ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 950 | sqlexp LE sqlexp (sql_compare ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 951 | sqlexp GT sqlexp (sql_compare ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 952 | sqlexp GE sqlexp (sql_compare ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 953
adamc@220 954 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@220 955 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@220 956 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
adamc@220 957
adamc@210 958 | LBRACE eexp RBRACE (sql_inject (#1 eexp,
adamc@211 959 EWild,
adamc@210 960 s (LBRACEleft, RBRACEright)))
adamc@220 961 | LPAREN sqlexp RPAREN (sqlexp)
adamc@210 962
adamc@235 963 | COUNT LPAREN STAR RPAREN (let
adamc@235 964 val loc = s (COUNTleft, RPARENright)
adamc@235 965 in
adamc@235 966 (EApp ((EVar (["Basis"], "sql_count"), loc),
adamc@235 967 (ERecord [], loc)), loc)
adamc@235 968 end)
adamc@236 969 | sqlagg LPAREN sqlexp RPAREN (let
adamc@236 970 val loc = s (sqlaggleft, RPARENright)
adamc@236 971
adamc@236 972 val e = (EApp ((EVar (["Basis"], "sql_" ^ sqlagg), loc),
adamc@236 973 (EWild, loc)), loc)
adamc@236 974 val e = (EApp ((EVar (["Basis"], "sql_aggregate"), loc),
adamc@236 975 e), loc)
adamc@236 976 in
adamc@236 977 (EApp (e, sqlexp), loc)
adamc@236 978 end)
adamc@235 979
adamc@209 980 wopt : (sql_inject (EVar (["Basis"], "True"),
adamc@209 981 EVar (["Basis"], "sql_bool"),
adamc@230 982 dummy))
adamc@209 983 | CWHERE sqlexp (sqlexp)
adamc@226 984
adamc@226 985 groupi : tident DOT fident (GField (tident, fident))
adamc@226 986
adamc@226 987 groupis: groupi ([groupi])
adamc@226 988 | groupi COMMA groupis (groupi :: groupis)
adamc@226 989
adamc@226 990 gopt : (NONE)
adamc@226 991 | GROUP BY groupis (SOME groupis)
adamc@227 992
adamc@227 993 hopt : (sql_inject (EVar (["Basis"], "True"),
adamc@227 994 EVar (["Basis"], "sql_bool"),
adamc@230 995 dummy))
adamc@227 996 | HAVING sqlexp (sqlexp)
adamc@230 997
adamc@230 998 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil"), dummy),
adamc@234 999 (CWild (KRecord (KType, dummy), dummy), dummy)),
adamc@230 1000 dummy)
adamc@230 1001 | ORDER BY obexps (obexps)
adamc@230 1002
adamc@230 1003 obexps : sqlexp (let
adamc@230 1004 val loc = s (sqlexpleft, sqlexpright)
adamc@230 1005
adamc@230 1006 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil"), loc),
adamc@234 1007 (CWild (KRecord (KType, loc), loc), loc)),
adamc@230 1008 loc)
adamc@230 1009 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons"), loc),
adamc@230 1010 sqlexp), loc)
adamc@230 1011 in
adamc@230 1012 (EApp (e, e'), loc)
adamc@230 1013 end)
adamc@230 1014 | sqlexp COMMA obexps (let
adamc@230 1015 val loc = s (sqlexpleft, obexpsright)
adamc@230 1016
adamc@230 1017 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons"), loc),
adamc@230 1018 sqlexp), loc)
adamc@230 1019 in
adamc@230 1020 (EApp (e, obexps), loc)
adamc@230 1021 end)
adamc@231 1022
adamc@231 1023 lopt : (EVar (["Basis"], "sql_no_limit"), dummy)
adamc@232 1024 | LIMIT ALL (EVar (["Basis"], "sql_no_limit"), dummy)
adamc@231 1025 | LIMIT sqlint (let
adamc@231 1026 val loc = s (LIMITleft, sqlintright)
adamc@231 1027 in
adamc@231 1028 (EApp ((EVar (["Basis"], "sql_limit"), loc), sqlint), loc)
adamc@231 1029 end)
adamc@231 1030
adamc@232 1031 ofopt : (EVar (["Basis"], "sql_no_offset"), dummy)
adamc@232 1032 | OFFSET sqlint (let
adamc@232 1033 val loc = s (OFFSETleft, sqlintright)
adamc@232 1034 in
adamc@232 1035 (EApp ((EVar (["Basis"], "sql_offset"), loc), sqlint), loc)
adamc@232 1036 end)
adamc@232 1037
adamc@231 1038 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@231 1039 | LBRACE eexp RBRACE (eexp)
adamc@236 1040
adamc@236 1041 sqlagg : AVG ("avg")
adamc@236 1042 | SUM ("sum")
adamc@236 1043 | MIN ("min")
adamc@236 1044 | MAX ("max")