annotate src/lacweb.grm @ 239:fc6f04889bf2

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