annotate src/lacweb.grm @ 231:eadeea528f75

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