annotate src/urweb.grm @ 302:bc89dfdbc495

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