annotate src/urweb.grm @ 257:32f9212583b2

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