annotate src/urweb.grm @ 2008:93ff76058825

HTML5 data-* attributes
author Adam Chlipala <adam@chlipala.net>
date Fri, 02 May 2014 15:32:10 -0400
parents c3b03d099e04
children 799be3911ce3
rev   line source
adam@1751 1 (* Copyright (c) 2008-2012, 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@339 15 * THIS SOFTARE 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
adam@1840 38 fun makeAttr s =
adam@1840 39 case s of
adam@1840 40 "type" => "Typ"
adam@1840 41 | "name" => "Nam"
adam@1840 42 | _ => capitalize (String.translate (fn ch => if ch = #"-" then "_" else str ch) s)
adam@1840 43
adamc@203 44 fun entable t =
adamc@203 45 case #1 t of
adamc@203 46 TRecord c => c
adamc@203 47 | _ => t
adamc@203 48
adamc@207 49 datatype select_item =
adamc@207 50 Field of con * con
adamc@1194 51 | Exp of con option * exp
adamc@341 52 | Fields of con * con
adam@1627 53 | StarFields of con
adamc@207 54
adamc@207 55 datatype select =
adamc@207 56 Star
adamc@207 57 | Items of select_item list
adamc@207 58
adamc@226 59 datatype group_item =
adamc@226 60 GField of con * con
adam@1425 61 | GFields of con * con
adamc@226 62
adamc@207 63 fun eqTnames ((c1, _), (c2, _)) =
adamc@207 64 case (c1, c2) of
adamc@207 65 (CVar (ms1, x1), CVar (ms2, x2)) => ms1 = ms2 andalso x1 = x2
adamc@207 66 | (CName x1, CName x2) => x1 = x2
adamc@207 67 | _ => false
adamc@207 68
adam@1424 69 fun nameString (c, _) =
adam@1424 70 case c of
adam@1424 71 CName s => s
adam@1424 72 | CVar (_, x) => x
adam@1424 73 | _ => "?"
adam@1424 74
adam@1627 75 datatype tableMode =
adam@1627 76 Unknown
adam@1627 77 | Everything
adam@1627 78 | Selective of con
adam@1627 79
adamc@1194 80 fun amend_select loc (si, (count, tabs, exps)) =
adamc@233 81 case si of
adamc@233 82 Field (tx, fx) =>
adamc@233 83 let
adamc@233 84 val c = (CRecord ([(fx, (CWild (KType, loc), loc))]), loc)
adamc@207 85
adamc@233 86 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
adamc@233 87 if eqTnames (tx, tx') then
adam@1627 88 case c' of
adam@1627 89 Everything =>
adam@1627 90 (ErrorMsg.errorAt loc
adam@1627 91 "Mixing specific-field and '*' selection of fields from same table";
adam@1627 92 ((tx', c'), found))
adam@1627 93 | Unknown =>
adam@1627 94 ((tx', Selective c), true)
adam@1627 95 | Selective c' =>
adam@1627 96 ((tx', Selective (CConcat (c, c'), loc)), true)
adamc@233 97 else
adamc@233 98 ((tx', c'), found))
adamc@233 99 false tabs
adamc@233 100 in
adamc@233 101 if found then
adamc@233 102 ()
adamc@233 103 else
adam@1424 104 ErrorMsg.errorAt loc ("Select of field " ^ nameString fx ^ " from unbound table " ^ nameString tx);
adamc@233 105
adamc@1194 106 (count, tabs, exps)
adamc@233 107 end
adamc@341 108 | Fields (tx, fs) =>
adamc@341 109 let
adamc@341 110 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
adamc@341 111 if eqTnames (tx, tx') then
adam@1627 112 case c' of
adam@1627 113 Everything =>
adam@1627 114 (ErrorMsg.errorAt loc
adam@1627 115 "Mixing specific-field and '*' selection of fields from same table";
adam@1627 116 ((tx', c'), found))
adam@1627 117 | Selective c' =>
adam@1627 118 ((tx', Selective (CConcat (fs, c'), loc)), true)
adam@1627 119 | Unknown =>
adam@1627 120 ((tx', Selective fs), true)
adamc@341 121 else
adamc@341 122 ((tx', c'), found))
adamc@341 123 false tabs
adamc@341 124 in
adamc@341 125 if found then
adamc@341 126 ()
adamc@341 127 else
adamc@341 128 ErrorMsg.errorAt loc "Select of field from unbound table";
adamc@341 129
adamc@1194 130 (count, tabs, exps)
adamc@341 131 end
adam@1627 132 | StarFields tx =>
adam@1627 133 if List.exists (fn (tx', c') => eqTnames (tx, tx') andalso case c' of
adam@1627 134 Unknown => false
adam@1627 135 | _ => true) tabs then
adam@1627 136 (ErrorMsg.errorAt loc "Selection with '*' from table already mentioned in same SELECT clause";
adam@1627 137 (count, tabs, exps))
adam@1627 138 else if List.all (fn (tx', c') => not (eqTnames (tx, tx'))) tabs then
adam@1627 139 (ErrorMsg.errorAt loc "Select of all fields from unbound table";
adam@1627 140 (count, tabs, exps))
adam@1627 141 else
adam@1627 142 (count, map (fn (tx', c') => (tx', if eqTnames (tx, tx') then Everything else c')) tabs, exps)
adamc@1194 143 | Exp (SOME c, e) => (count, tabs, (c, e) :: exps)
adamc@1194 144 | Exp (NONE, e) => (count+1, tabs, ((CName (Int.toString count), loc), e) :: exps)
adamc@207 145
adamc@226 146 fun amend_group loc (gi, tabs) =
adamc@226 147 let
adamc@226 148 val (tx, c) = case gi of
adamc@226 149 GField (tx, fx) => (tx, (CRecord ([(fx, (CWild (KType, loc), loc))]), loc))
adam@1425 150 | GFields (tx, fxs) => (tx, fxs)
adamc@226 151
adamc@226 152 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
adamc@226 153 if eqTnames (tx, tx') then
adamc@226 154 ((tx', (CConcat (c, c'), loc)), true)
adamc@226 155 else
adamc@226 156 ((tx', c'), found))
adam@1425 157 false tabs
adamc@226 158 in
adamc@226 159 if found then
adamc@226 160 ()
adamc@226 161 else
adamc@226 162 ErrorMsg.errorAt loc "Select of field from unbound table";
adamc@226 163
adamc@226 164 tabs
adamc@226 165 end
adamc@226 166
adamc@403 167 fun sql_inject (v, loc) =
adamc@403 168 (EApp ((EVar (["Basis"], "sql_inject", Infer), loc), (v, loc)), loc)
adamc@209 169
adamc@220 170 fun sql_binary (oper, sqlexp1, sqlexp2, loc) =
adamc@220 171 let
adamc@403 172 val e = (EVar (["Basis"], "sql_binary", Infer), loc)
adamc@403 173 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adamc@220 174 val e = (EApp (e, sqlexp1), loc)
adamc@220 175 in
adamc@220 176 (EApp (e, sqlexp2), loc)
adamc@220 177 end
adamc@220 178
adamc@220 179 fun sql_unary (oper, sqlexp, loc) =
adamc@220 180 let
adamc@403 181 val e = (EVar (["Basis"], "sql_unary", Infer), loc)
adamc@403 182 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adamc@220 183 in
adamc@220 184 (EApp (e, sqlexp), loc)
adamc@219 185 end
adamc@219 186
adam@1427 187 fun sql_relop (oper, all, sqlexp1, sqlexp2, loc) =
adamc@229 188 let
adamc@403 189 val e = (EVar (["Basis"], "sql_relop", Infer), loc)
adamc@403 190 val e = (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adam@1427 191 val e = (EApp (e, (EVar (["Basis"], if all then "True" else "False", Infer), loc)), loc)
adamc@229 192 val e = (EApp (e, sqlexp1), loc)
adamc@229 193 in
adamc@229 194 (EApp (e, sqlexp2), loc)
adamc@229 195 end
adamc@229 196
adamc@441 197 fun sql_nfunc (oper, loc) =
adamc@441 198 let
adamc@441 199 val e = (EVar (["Basis"], "sql_nfunc", Infer), loc)
adamc@441 200 in
adamc@441 201 (EApp (e, (EVar (["Basis"], "sql_" ^ oper, Infer), loc)), loc)
adamc@441 202 end
adamc@441 203
adamc@389 204 fun native_unop (oper, e1, loc) =
adamc@389 205 let
adamc@403 206 val e = (EVar (["Basis"], oper, Infer), loc)
adamc@389 207 in
adamc@389 208 (EApp (e, e1), loc)
adamc@389 209 end
adamc@389 210
adamc@256 211 fun native_op (oper, e1, e2, loc) =
adamc@256 212 let
adamc@403 213 val e = (EVar (["Basis"], oper, Infer), loc)
adamc@256 214 val e = (EApp (e, e1), loc)
adamc@256 215 in
adamc@256 216 (EApp (e, e2), loc)
adamc@256 217 end
adamc@256 218
adamc@310 219 val inDml = ref false
adamc@310 220
adamc@325 221 fun tagIn bt =
adamc@325 222 case bt of
adamc@325 223 "table" => "tabl"
adamc@325 224 | _ => bt
adamc@325 225
adamc@709 226 datatype prop_kind = Delete | Update
adamc@709 227
adam@2008 228 datatype attr = Class of exp | DynClass of exp | Style of exp | DynStyle of exp | Normal of con * exp | Data of string * exp
adamc@721 229
adamc@822 230 fun patType loc (p : pat) =
adamc@822 231 case #1 p of
adamc@822 232 PAnnot (_, t) => t
adamc@822 233 | _ => (CWild (KType, loc), loc)
adamc@822 234
adamc@1265 235 fun tnamesOf (e, _) =
adamc@1265 236 case e of
adamc@1265 237 EApp (e1, e2) => tnamesOf e1 @ tnamesOf e2
adamc@1265 238 | ECApp (e, c as (CName _, _)) =>
adamc@1265 239 let
adamc@1265 240 fun isFt (e, _) =
adamc@1265 241 case e of
adamc@1265 242 EVar (["Basis"], "sql_from_table", _) => true
adamc@1265 243 | EVar ([], "sql_from_table", _) => true
adamc@1265 244 | ECApp (e, _) => isFt e
adamc@1265 245 | EApp (e, _) => isFt e
adamc@1265 246 | EDisjointApp e => isFt e
adamc@1265 247 | _ => false
adamc@1265 248 in
adamc@1265 249 (if isFt e then [c] else []) @ tnamesOf e
adamc@1265 250 end
adamc@1265 251 | ECApp (e, _) => tnamesOf e
adamc@1265 252 | EDisjointApp e => tnamesOf e
adamc@1265 253 | _ => []
adamc@1265 254
adam@1761 255 fun classOut (s, pos) =
adam@1761 256 let
adam@1761 257 val s = case s of
adam@1761 258 "table" => "tabl"
adam@1761 259 | _ => s
adam@1761 260 in
adam@1761 261 (EVar ([], String.translate (fn #"-" => "_" | ch => str ch) s, Infer), pos)
adam@1761 262 end
adam@1749 263
adam@1749 264 fun parseClass s pos =
adam@1749 265 case String.tokens Char.isSpace s of
adam@1749 266 [] => (EVar (["Basis"], "null", Infer), pos)
adam@1749 267 | class :: classes =>
adam@1749 268 foldl (fn (s, e) => (EApp ((EApp ((EVar (["Basis"], "classes", Infer), pos), e), pos), classOut (s, pos)), pos))
adam@1749 269 (classOut (class, pos)) classes
adam@1749 270
adam@1750 271 fun parseValue s pos =
adam@1750 272 if String.isPrefix "url(" s andalso String.isSuffix ")" s then
adam@1750 273 let
adam@1750 274 val s = String.substring (s, 4, size s - 5)
adam@1750 275
adam@1750 276 val s = if size s >= 2
adam@1750 277 andalso ((String.isPrefix "\"" s andalso String.isSuffix "\"" s)
adam@1750 278 orelse (String.isPrefix "'" s andalso String.isSuffix "'" s)) then
adam@1750 279 String.substring (s, 1, size s - 2)
adam@1750 280 else
adam@1750 281 s
adam@1750 282 in
adam@1750 283 (EApp ((EVar (["Basis"], "css_url", Infer), pos),
adam@1750 284 (EApp ((EVar (["Basis"], "bless", Infer), pos),
adam@1750 285 (EPrim (Prim.String s), pos)), pos)), pos)
adam@1750 286 end
adam@1750 287 else
adam@1750 288 (EApp ((EVar (["Basis"], "atom", Infer), pos),
adam@1750 289 (EPrim (Prim.String s), pos)), pos)
adam@1750 290
adam@1750 291 fun parseProperty s pos =
adam@1750 292 let
adam@1750 293 val (befor, after) = Substring.splitl (fn ch => ch <> #":") (Substring.full s)
adam@1750 294 in
adam@1750 295 if Substring.isEmpty after then
adam@1750 296 (ErrorMsg.errorAt pos ("Invalid CSS property syntax: " ^ s);
adam@1750 297 (EPrim (Prim.String ""), pos))
adam@1750 298 else
adam@1750 299 foldl (fn (value, e) => (EApp ((EApp ((EVar (["Basis"], "value", Infer), pos), e), pos), parseValue value pos), pos))
adam@1750 300 (EApp ((EVar (["Basis"], "property", Infer), pos),
adam@1750 301 (EPrim (Prim.String (Substring.string (#2 (Substring.splitl Char.isSpace befor)))), pos)), pos)
adam@1750 302 (String.tokens Char.isSpace (Substring.string (Substring.slice (after, 1, NONE))))
adam@1750 303 end
adam@1750 304
adam@1750 305 fun parseStyle s pos =
adam@1750 306 case String.tokens (fn ch => ch = #";") s of
adam@1750 307 [] => (EVar (["Basis"], "noStyle", Infer), pos)
adam@1750 308 | props =>
adam@1750 309 foldl (fn (s, e) => (EApp ((EApp ((EVar (["Basis"], "oneProperty", Infer), pos), e), pos), parseProperty s pos), pos))
adam@1750 310 (EVar (["Basis"], "noStyle", Infer), pos) props
adam@1750 311
adam@1777 312 fun applyWindow loc e window =
adam@1777 313 let
adam@1777 314 val (pb, ob) = getOpt (window, ((EVar (["Basis"], "sql_no_partition", Infer), dummy),
adam@1777 315 (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
adam@1777 316 (CWild (KRecord (KType, dummy), dummy), dummy)),
adam@1777 317 dummy)))
adam@1778 318 val e' = (EVar (["Basis"], "sql_window_function", Infer), loc)
adam@1777 319 val e' = (EApp (e', e), loc)
adam@1777 320 val e' = (EApp (e', pb), loc)
adam@1777 321 in
adam@1777 322 (EApp (e', ob), loc)
adam@1777 323 end
adam@1777 324
adamc@1 325 %%
adamc@244 326 %header (functor UrwebLrValsFn(structure Token : TOKEN))
adamc@1 327
adamc@1 328 %term
adamc@1 329 EOF
adamc@821 330 | STRING of string | INT of Int64.int | FLOAT of Real64.real | CHAR of char
adamc@1 331 | SYMBOL of string | CSYMBOL of string
adamc@1 332 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
adam@1306 333 | EQ | COMMA | COLON | DCOLON | DCOLONWILD | TCOLON | TCOLONWILD | DOT | HASH | UNDER | UNDERUNDER | BAR
adamc@403 334 | PLUS | MINUS | DIVIDE | DOTDOTDOT | MOD | AT
adamc@623 335 | CON | LTYPE | VAL | REC | AND | FUN | MAP | UNIT | KUNIT | CLASS
adamc@156 336 | DATATYPE | OF
adamc@7 337 | TYPE | NAME
adamc@629 338 | ARROW | LARROW | DARROW | STAR | SEMI | KARROW | DKARROW | BANG
adamc@674 339 | FN | PLUSPLUS | MINUSMINUS | MINUSMINUSMINUS | DOLLAR | TWIDDLE | CARET
adamc@446 340 | LET | IN
adam@1732 341 | STRUCTURE | SIGNATURE | STRUCT | SIG | END | FUNCTOR | WHERE | SQL | SELECT1
adamc@754 342 | INCLUDE | OPEN | CONSTRAINT | CONSTRAINTS | EXPORT | TABLE | SEQUENCE | VIEW
adamc@1199 343 | COOKIE | STYLE | TASK | POLICY
adamc@842 344 | CASE | IF | THEN | ELSE | ANDALSO | ORELSE
adamc@1 345
adamc@360 346 | XML_BEGIN of string | XML_END | XML_BEGIN_END of string
adamc@91 347 | NOTAGS of string
adamc@91 348 | BEGIN_TAG of string | END_TAG of string
adamc@91 349
adamc@993 350 | SELECT | DISTINCT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING
adamc@229 351 | UNION | INTERSECT | EXCEPT
adamc@232 352 | LIMIT | OFFSET | ALL
adamc@220 353 | TRUE | FALSE | CAND | OR | NOT
adam@1778 354 | COUNT | AVG | SUM | MIN | MAX | RANK | PARTITION | OVER
adam@1682 355 | ASC | DESC | RANDOM
kkallio@1607 356 | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS | COALESCE | LIKE
adamc@441 357 | CURRENT_TIMESTAMP
adamc@219 358 | NE | LT | LE | GT | GE
adamc@714 359 | CCONSTRAINT | UNIQUE | CHECK | PRIMARY | FOREIGN | KEY | ON | NO | ACTION | RESTRICT | CASCADE | REFERENCES
adamc@751 360 | JOIN | INNER | CROSS | OUTER | LEFT | RIGHT | FULL
kkallio@1572 361 | CIF | CTHEN | CELSE
adamc@204 362
adamc@30 363 %nonterm
adamc@1 364 file of decl list
adamc@1 365 | decls of decl list
adamc@325 366 | decl of decl list
adamc@123 367 | vali of string * con option * exp
adamc@123 368 | valis of (string * con option * exp) list
adamc@242 369 | copt of con option
adamc@1 370
adamc@191 371 | dargs of string list
adamc@156 372 | barOpt of unit
adamc@156 373 | dcons of (string * con option) list
adamc@805 374 | dtype of string * string list * (string * con option) list
adamc@805 375 | dtypes of (string * string list * (string * con option) list) list
adamc@156 376 | dcon of string * con option
adamc@156 377
adamc@707 378 | pkopt of exp
adam@1722 379 | pk of exp
adamc@707 380 | commaOpt of unit
adamc@707 381
adamc@704 382 | cst of exp
adamc@704 383 | csts of exp
adamc@704 384 | cstopt of exp
adamc@704 385
adamc@1001 386 | ckl of (string * kind option) list
adamc@1001 387
adamc@709 388 | pmode of prop_kind * exp
adamc@709 389 | pkind of prop_kind
adamc@709 390 | prule of exp
adamc@709 391 | pmodes of (prop_kind * exp) list
adamc@709 392
adamc@30 393 | sgn of sgn
adamc@42 394 | sgntm of sgn
adamc@30 395 | sgi of sgn_item
adamc@30 396 | sgis of sgn_item list
adamc@30 397
adamc@30 398 | str of str
adamc@30 399
adamc@1 400 | kind of kind
adamc@207 401 | ktuple of kind list
adamc@1 402 | kcolon of explicitness
adamc@240 403 | kopt of kind option
adamc@1 404
adamc@34 405 | path of string list * string
adamc@156 406 | cpath of string list * string
adamc@34 407 | spath of str
adamc@59 408 | mpath of string list
adamc@34 409
adamc@1 410 | cexp of con
adam@1577 411 | cexpO of con option
adamc@1 412 | capps of con
adamc@1 413 | cterm of con
adamc@195 414 | ctuple of con list
adamc@207 415 | ctuplev of con list
adamc@1 416 | ident of con
adamc@200 417 | idents of con list
adamc@1 418 | rcon of (con * con) list
adamc@83 419 | rconn of (con * con) list
adamc@1 420 | rcone of (con * con) list
adamc@239 421 | cargs of con * kind -> con * kind
adamc@239 422 | cargl of con * kind -> con * kind
adamc@240 423 | cargl2 of con * kind -> con * kind
adamc@239 424 | carg of con * kind -> con * kind
adamc@239 425 | cargp of con * kind -> con * kind
adamc@1 426
adamc@8 427 | eexp of exp
adamc@8 428 | eapps of exp
adamc@8 429 | eterm of exp
adamc@195 430 | etuple of exp list
adamc@12 431 | rexp of (con * exp) list
adamc@91 432 | xml of exp
adamc@91 433 | xmlOne of exp
adamc@1045 434 | xmlOpt of exp
adam@1643 435 | tag of (string * exp) * exp option * exp option * exp
adamc@141 436 | tagHead of string * exp
adamc@434 437 | bind of string * con option * exp
adamc@446 438 | edecl of edecl
adamc@446 439 | edecls of edecl list
adamc@8 440
adamc@241 441 | earg of exp * con -> exp * con
adamc@241 442 | eargp of exp * con -> exp * con
adamc@822 443 | earga of exp * con -> exp * con
adamc@241 444 | eargs of exp * con -> exp * con
adamc@241 445 | eargl of exp * con -> exp * con
adamc@242 446 | eargl2 of exp * con -> exp * con
adamc@241 447
adamc@170 448 | branch of pat * exp
adamc@170 449 | branchs of (pat * exp) list
adamc@170 450 | pat of pat
adamc@822 451 | patS of pat
adamc@170 452 | pterm of pat
adamc@174 453 | rpat of (string * pat) list * bool
adamc@195 454 | ptuple of pat list
adamc@170 455
adam@2008 456 | attrs of exp option * exp option * exp option * exp option * (string * exp) list * (con * exp) list
adamc@721 457 | attr of attr
adamc@104 458 | attrv of exp
adamc@104 459
adamc@204 460 | query of exp
adamc@226 461 | query1 of exp
adamc@993 462 | dopt of exp
adamc@748 463 | tables of con list * exp
adamc@749 464 | fitem of con list * exp
adamc@204 465 | tname of con
adamc@705 466 | tnameW of con * con
adamc@705 467 | tnames of (con * con) * (con * con) list
adamc@705 468 | tnames' of (con * con) * (con * con) list
adamc@204 469 | table of con * exp
adamc@748 470 | table' of con * exp
adamc@207 471 | tident of con
adamc@207 472 | fident of con
adamc@207 473 | seli of select_item
adamc@207 474 | selis of select_item list
adamc@207 475 | select of select
adamc@209 476 | sqlexp of exp
adam@1777 477 | window of (exp * exp) option
adam@1777 478 | pbopt of exp
adamc@209 479 | wopt of exp
adamc@226 480 | groupi of group_item
adamc@226 481 | groupis of group_item list
adamc@226 482 | gopt of group_item list option
adamc@227 483 | hopt of exp
adamc@230 484 | obopt of exp
adamc@268 485 | obitem of exp * exp
adamc@230 486 | obexps of exp
adam@1682 487 | popt of unit
adamc@268 488 | diropt of exp
adamc@231 489 | lopt of exp
adamc@232 490 | ofopt of exp
adamc@231 491 | sqlint of exp
adamc@236 492 | sqlagg of string
adamc@746 493 | fname of exp
adamc@207 494
adamc@302 495 | texp of exp
adamc@302 496 | fields of con list
adamc@302 497 | sqlexps of exp list
adamc@303 498 | fsets of (con * exp) list
adamc@310 499 | enterDml of unit
adamc@310 500 | leaveDml of unit
adamc@302 501
adamc@204 502
adamc@1 503 %verbose (* print summary of errors *)
adamc@1 504 %pos int (* positions *)
adamc@1 505 %start file
adamc@1 506 %pure
adamc@1 507 %eop EOF
adamc@1 508 %noshift EOF
adamc@1 509
adamc@244 510 %name Urweb
adamc@1 511
adamc@623 512 %right KARROW
adamc@623 513 %nonassoc DKARROW
adamc@243 514 %right SEMI
adamc@243 515 %nonassoc LARROW
adamc@195 516 %nonassoc IF THEN ELSE
adamc@843 517 %nonassoc DARROW
adamc@842 518 %left ANDALSO
adamc@842 519 %left ORELSE
adamc@1 520 %nonassoc COLON
adam@1306 521 %nonassoc DCOLON TCOLON DCOLONWILD TCOLONWILD
adam@1427 522 %left UNION INTERSECT EXCEPT ALL
adamc@1 523 %right COMMA
adamc@751 524 %right JOIN INNER CROSS OUTER LEFT RIGHT FULL
adamc@220 525 %right OR
adamc@220 526 %right CAND
adamc@470 527 %nonassoc EQ NE LT LE GT GE IS
adamc@243 528 %right ARROW
adamc@837 529 %right CARET PLUSPLUS
adamc@837 530 %left MINUSMINUS MINUSMINUSMINUS
adamc@389 531 %left PLUS MINUS
adamc@389 532 %left STAR DIVIDE MOD
adamc@220 533 %left NOT
adamc@84 534 %nonassoc TWIDDLE
adamc@1 535 %nonassoc DOLLAR
adamc@1 536 %left DOT
adamc@221 537 %nonassoc LBRACE RBRACE
adamc@1 538
adamc@1 539 %%
adamc@1 540
adamc@1 541 file : decls (decls)
adamc@54 542 | SIG sgis ([(DSgn ("?", (SgnConst sgis, s (SIGleft, sgisright))),
adamc@54 543 s (SIGleft, sgisright))])
adamc@1 544
adamc@1 545 decls : ([])
adamc@325 546 | decl decls (decl @ decls)
adamc@1 547
adamc@240 548 decl : CON SYMBOL cargl2 kopt EQ cexp (let
adamc@240 549 val loc = s (CONleft, cexpright)
adamc@240 550
adamc@240 551 val k = Option.getOpt (kopt, (KWild, loc))
adamc@240 552 val (c, k) = cargl2 (cexp, k)
adamc@240 553 in
adamc@325 554 [(DCon (SYMBOL, SOME k, c), loc)]
adamc@240 555 end)
adam@1654 556 | LTYPE SYMBOL cargl2 EQ cexp (let
adam@1654 557 val loc = s (LTYPEleft, cexpright)
adam@1654 558
adam@1654 559 val k = (KWild, loc)
adam@1654 560 val (c, k) = cargl2 (cexp, k)
adam@1654 561 in
adam@1654 562 [(DCon (SYMBOL, SOME k, c), loc)]
adam@1654 563 end)
adamc@805 564 | DATATYPE dtypes ([(DDatatype dtypes, s (DATATYPEleft, dtypesright))])
adamc@191 565 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
adamc@191 566 (case dargs of
adamc@325 567 [] => [(DDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))]
adamc@191 568 | _ => raise Fail "Arguments specified for imported datatype")
adamc@325 569 | VAL vali ([(DVal vali, s (VALleft, valiright))])
adamc@325 570 | VAL REC valis ([(DValRec valis, s (VALleft, valisright))])
adamc@325 571 | FUN valis ([(DValRec valis, s (FUNleft, valisright))])
adamc@1 572
adamc@325 573 | SIGNATURE CSYMBOL EQ sgn ([(DSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))])
adam@1868 574 | STRUCTURE CSYMBOL EQ str ([(DStr (CSYMBOL, NONE, NONE, str, false), s (STRUCTUREleft, strright))])
adam@1868 575 | STRUCTURE CSYMBOL COLON sgn EQ str ([(DStr (CSYMBOL, SOME sgn, NONE, str, false), s (STRUCTUREleft, strright))])
adamc@42 576 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN EQ str
adam@1732 577 ([(DStr (CSYMBOL1, NONE, NONE,
adam@1868 578 (StrFun (CSYMBOL2, sgn1, NONE, str), s (FUNCTORleft, strright)), false),
adamc@325 579 s (FUNCTORleft, strright))])
adamc@42 580 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn EQ str
adam@1732 581 ([(DStr (CSYMBOL1, NONE, NONE,
adam@1868 582 (StrFun (CSYMBOL2, sgn1, SOME sgn2, str), s (FUNCTORleft, strright)), false),
adamc@325 583 s (FUNCTORleft, strright))])
adamc@61 584 | OPEN mpath (case mpath of
adamc@61 585 [] => raise Fail "Impossible mpath parse [1]"
adamc@325 586 | m :: ms => [(DOpen (m, ms), s (OPENleft, mpathright))])
adamc@325 587 | OPEN mpath LPAREN str RPAREN (let
adamc@325 588 val loc = s (OPENleft, RPARENright)
adamc@325 589
adamc@325 590 val m = case mpath of
adamc@325 591 [] => raise Fail "Impossible mpath parse [4]"
adamc@325 592 | m :: ms =>
adamc@325 593 foldl (fn (m, str) => (StrProj (str, m), loc))
adamc@325 594 (StrVar m, loc) ms
adamc@325 595 in
adam@1868 596 [(DStr ("anon", NONE, NONE, (StrApp (m, str), loc), false), loc),
adamc@325 597 (DOpen ("anon", []), loc)]
adamc@325 598 end)
adamc@88 599 | OPEN CONSTRAINTS mpath (case mpath of
adamc@88 600 [] => raise Fail "Impossible mpath parse [3]"
adamc@325 601 | m :: ms => [(DOpenConstraints (m, ms), s (OPENleft, mpathright))])
adamc@325 602 | CONSTRAINT cterm TWIDDLE cterm ([(DConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))])
adamc@325 603 | EXPORT spath ([(DExport spath, s (EXPORTleft, spathright))])
adamc@707 604 | TABLE SYMBOL COLON cterm pkopt commaOpt cstopt([(DTable (SYMBOL, entable cterm, pkopt, cstopt),
adamc@707 605 s (TABLEleft, cstoptright))])
adamc@338 606 | SEQUENCE SYMBOL ([(DSequence SYMBOL, s (SEQUENCEleft, SYMBOLright))])
adamc@754 607 | VIEW SYMBOL EQ query ([(DView (SYMBOL, query),
adamc@754 608 s (VIEWleft, queryright))])
adamc@754 609 | VIEW SYMBOL EQ LBRACE eexp RBRACE ([(DView (SYMBOL, eexp),
adamc@754 610 s (VIEWleft, RBRACEright))])
adamc@459 611 | COOKIE SYMBOL COLON cexp ([(DCookie (SYMBOL, cexp), s (COOKIEleft, cexpright))])
adamc@720 612 | STYLE SYMBOL ([(DStyle SYMBOL, s (STYLEleft, SYMBOLright))])
adamc@1075 613 | TASK eapps EQ eexp ([(DTask (eapps, eexp), s (TASKleft, eexpright))])
adamc@1199 614 | POLICY eexp ([(DPolicy eexp, s (POLICYleft, eexpright))])
adamc@30 615
adamc@805 616 dtype : SYMBOL dargs EQ barOpt dcons (SYMBOL, dargs, dcons)
adamc@805 617
adamc@805 618 dtypes : dtype ([dtype])
adamc@805 619 | dtype AND dtypes (dtype :: dtypes)
adamc@805 620
adamc@240 621 kopt : (NONE)
adamc@240 622 | DCOLON kind (SOME kind)
adam@1302 623 | DCOLONWILD (SOME (KWild, s (DCOLONWILDleft, DCOLONWILDright)))
adamc@240 624
adamc@191 625 dargs : ([])
adamc@191 626 | SYMBOL dargs (SYMBOL :: dargs)
adamc@191 627
adamc@156 628 barOpt : ()
adamc@156 629 | BAR ()
adamc@156 630
adamc@156 631 dcons : dcon ([dcon])
adamc@156 632 | dcon BAR dcons (dcon :: dcons)
adamc@156 633
adamc@156 634 dcon : CSYMBOL (CSYMBOL, NONE)
adamc@156 635 | CSYMBOL OF cexp (CSYMBOL, SOME cexp)
adamc@156 636
adamc@242 637 vali : SYMBOL eargl2 copt EQ eexp (let
adamc@242 638 val loc = s (SYMBOLleft, eexpright)
adamc@242 639 val t = Option.getOpt (copt, (CWild (KType, loc), loc))
adamc@242 640
adamc@242 641 val (e, t) = eargl2 (eexp, t)
adamc@242 642 in
adamc@242 643 (SYMBOL, SOME t, e)
adamc@242 644 end)
adamc@242 645
adamc@242 646 copt : (NONE)
adamc@242 647 | COLON cexp (SOME cexp)
adamc@123 648
adamc@704 649 cstopt : (EVar (["Basis"], "no_constraint", Infer), dummy)
adamc@704 650 | csts (csts)
adamc@704 651
adamc@704 652 csts : CCONSTRAINT tname cst (let
adamc@704 653 val loc = s (CCONSTRAINTleft, cstright)
adamc@704 654
adamc@704 655 val e = (EVar (["Basis"], "one_constraint", Infer), loc)
adamc@704 656 val e = (ECApp (e, tname), loc)
adamc@704 657 in
adamc@704 658 (EApp (e, cst), loc)
adamc@704 659 end)
adamc@704 660 | csts COMMA csts (let
adamc@704 661 val loc = s (csts1left, csts2right)
adamc@704 662
adamc@704 663 val e = (EVar (["Basis"], "join_constraints", Infer), loc)
adamc@704 664 val e = (EApp (e, csts1), loc)
adamc@704 665 in
adamc@704 666 (EApp (e, csts2), loc)
adamc@704 667 end)
adamc@704 668 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
adamc@704 669
adamc@704 670 cst : UNIQUE tnames (let
adamc@704 671 val loc = s (UNIQUEleft, tnamesright)
adamc@704 672
adamc@704 673 val e = (EVar (["Basis"], "unique", Infer), loc)
adamc@705 674 val e = (ECApp (e, #1 (#1 tnames)), loc)
adamc@705 675 val e = (ECApp (e, (CRecord (#2 tnames), loc)), loc)
adamc@704 676 in
adamc@1093 677 e
adamc@704 678 end)
adamc@709 679
adamc@714 680 | CHECK sqlexp (let
adamc@714 681 val loc = s (CHECKleft, sqlexpright)
adamc@714 682 in
adamc@714 683 (EApp ((EVar (["Basis"], "check", Infer), loc),
adamc@714 684 sqlexp), loc)
adamc@714 685 end)
adamc@714 686
adamc@709 687 | FOREIGN KEY tnames REFERENCES texp LPAREN tnames' RPAREN pmodes
adamc@709 688 (let
adamc@709 689 val loc = s (FOREIGNleft, pmodesright)
adamc@709 690
adamc@709 691 val mat = ListPair.foldrEq
adamc@709 692 (fn ((nm1, _), (nm2, _), mat) =>
adamc@709 693 let
adamc@709 694 val e = (EVar (["Basis"], "mat_cons", Infer), loc)
adamc@709 695 val e = (ECApp (e, nm1), loc)
adamc@709 696 val e = (ECApp (e, nm2), loc)
adamc@709 697 in
adamc@709 698 (EApp (e, mat), loc)
adamc@709 699 end)
adamc@709 700 (EVar (["Basis"], "mat_nil", Infer), loc)
adamc@709 701 (#1 tnames :: #2 tnames, #1 tnames' :: #2 tnames')
adam@1401 702 handle ListPair.UnequalLengths =>
adam@1401 703 (ErrorMsg.errorAt loc ("Unequal foreign key list lengths ("
adam@1401 704 ^ Int.toString (1 + length (#2 tnames))
adam@1401 705 ^ " vs. "
adam@1401 706 ^ Int.toString (1 + length (#2 tnames'))
adam@1401 707 ^ ")");
adam@1401 708 (EVar (["Basis"], "mat_nil", Infer), loc))
adamc@709 709
adamc@709 710 fun findMode mode =
adamc@709 711 let
adamc@709 712 fun findMode' pmodes =
adamc@709 713 case pmodes of
adamc@709 714 [] => (EVar (["Basis"], "no_action", Infer), loc)
adamc@709 715 | (mode', rule) :: pmodes' =>
adamc@709 716 if mode' = mode then
adamc@709 717 (if List.exists (fn (mode', _) => mode' = mode)
adamc@709 718 pmodes' then
adamc@709 719 ErrorMsg.errorAt loc "Duplicate propagation rule"
adamc@709 720 else
adamc@709 721 ();
adamc@709 722 rule)
adamc@709 723 else
adamc@709 724 findMode' pmodes'
adamc@709 725 in
adamc@709 726 findMode' pmodes
adamc@709 727 end
adamc@709 728
adamc@709 729 val e = (EVar (["Basis"], "foreign_key", Infer), loc)
adamc@709 730 val e = (EApp (e, mat), loc)
adamc@709 731 val e = (EApp (e, texp), loc)
adamc@709 732 in
adamc@709 733 (EApp (e, (ERecord [((CName "OnDelete", loc),
adamc@709 734 findMode Delete),
adamc@709 735 ((CName "OnUpdate", loc),
adamc@709 736 findMode Update)], loc)), loc)
adamc@709 737 end)
adamc@709 738
adamc@704 739 | LBRACE eexp RBRACE (eexp)
adamc@704 740
adamc@704 741 tnameW : tname (let
adamc@704 742 val loc = s (tnameleft, tnameright)
adamc@704 743 in
adamc@704 744 (tname, (CWild (KType, loc), loc))
adamc@704 745 end)
adamc@704 746
adamc@705 747 tnames : tnameW (tnameW, [])
adamc@705 748 | LPAREN tnames' RPAREN (tnames')
adamc@704 749
adamc@705 750 tnames': tnameW (tnameW, [])
adamc@705 751 | tnameW COMMA tnames' (#1 tnames', tnameW :: #2 tnames')
adamc@704 752
adamc@709 753 pmode : ON pkind prule (pkind, prule)
adamc@709 754
adamc@709 755 pkind : DELETE (Delete)
adamc@709 756 | UPDATE (Update)
adamc@709 757
adamc@709 758 prule : NO ACTION (EVar (["Basis"], "no_action", Infer), s (NOleft, ACTIONright))
adamc@709 759 | RESTRICT (EVar (["Basis"], "restrict", Infer), s (RESTRICTleft, RESTRICTright))
adamc@709 760 | CASCADE (EVar (["Basis"], "cascade", Infer), s (CASCADEleft, CASCADEright))
adamc@709 761 | SET NULL (EVar (["Basis"], "set_null", Infer), s (SETleft, NULLright))
adamc@709 762
adamc@709 763 pmodes : ([])
adamc@709 764 | pmode pmodes (pmode :: pmodes)
adamc@709 765
adamc@707 766 commaOpt: ()
adamc@707 767 | COMMA ()
adamc@707 768
adam@1722 769 pk : LBRACE LBRACE eexp RBRACE RBRACE (eexp)
adam@1722 770 | tnames (let
adam@1722 771 val loc = s (tnamesleft, tnamesright)
adamc@707 772
adamc@1093 773 val e = (EVar (["Basis"], "primary_key", TypesOnly), loc)
adamc@707 774 val e = (ECApp (e, #1 (#1 tnames)), loc)
adamc@707 775 val e = (ECApp (e, (CRecord (#2 tnames), loc)), loc)
adamc@707 776 val e = (EDisjointApp e, loc)
adamc@707 777 val e = (EDisjointApp e, loc)
adamc@707 778
adamc@707 779 val witness = map (fn (c, _) =>
adamc@707 780 (c, (EWild, loc)))
adamc@707 781 (#1 tnames :: #2 tnames)
adamc@707 782 val witness = (ERecord witness, loc)
adamc@707 783 in
adamc@707 784 (EApp (e, witness), loc)
adamc@707 785 end)
adamc@707 786
adam@1722 787 pkopt : (EVar (["Basis"], "no_primary_key", Infer), dummy)
adam@1722 788 | PRIMARY KEY pk (pk)
adam@1722 789
adamc@123 790 valis : vali ([vali])
adamc@123 791 | vali AND valis (vali :: valis)
adamc@123 792
adamc@42 793 sgn : sgntm (sgntm)
adamc@40 794 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@40 795 (SgnFun (CSYMBOL, sgn1, sgn2), s (FUNCTORleft, sgn2right))
adamc@30 796
adamc@42 797 sgntm : SIG sgis END (SgnConst sgis, s (SIGleft, ENDright))
adamc@59 798 | mpath (case mpath of
adamc@61 799 [] => raise Fail "Impossible mpath parse [2]"
adamc@59 800 | [x] => SgnVar x
adamc@59 801 | m :: ms => SgnProj (m,
adamc@59 802 List.take (ms, length ms - 1),
adamc@59 803 List.nth (ms, length ms - 1)),
adamc@59 804 s (mpathleft, mpathright))
adam@1864 805 | sgntm WHERE CON path EQ cexp (SgnWhere (sgntm, #1 path, #2 path, cexp), s (sgntmleft, cexpright))
adam@1864 806 | sgntm WHERE LTYPE path EQ cexp (SgnWhere (sgntm, #1 path, #2 path, cexp), s (sgntmleft, cexpright))
adamc@42 807 | LPAREN sgn RPAREN (sgn)
adamc@42 808
adam@1577 809 cexpO : (NONE)
adam@1577 810 | EQ cexp (SOME cexp)
adam@1577 811
adam@1577 812 sgi : LTYPE SYMBOL ((SgiConAbs (SYMBOL, (KType, s (LTYPEleft, SYMBOLright))),
adamc@706 813 s (LTYPEleft, SYMBOLright)))
adam@1577 814 | CON SYMBOL cargl2 kopt cexpO (let
adam@1577 815 val loc = s (CONleft, cexpOright)
adam@1574 816
adam@1574 817 val k = Option.getOpt (kopt, (KWild, loc))
adam@1574 818 in
adam@1577 819 case cexpO of
adam@1577 820 NONE => (SgiConAbs (SYMBOL, k), loc)
adam@1577 821 | SOME cexp =>
adam@1577 822 let
adam@1577 823 val (c, k) = cargl2 (cexp, k)
adam@1577 824 in
adam@1577 825 (SgiCon (SYMBOL, SOME k, c), loc)
adam@1577 826 end
adam@1574 827 end)
adam@1654 828 | LTYPE SYMBOL cargl2 cexpO (let
adam@1654 829 val loc = s (LTYPEleft, cexpOright)
adam@1654 830
adam@1654 831 val k = (KWild, loc)
adam@1654 832 in
adam@1654 833 case cexpO of
adam@1654 834 NONE => (SgiConAbs (SYMBOL, k), loc)
adam@1654 835 | SOME cexp =>
adam@1654 836 let
adam@1654 837 val (c, k) = cargl2 (cexp, k)
adam@1654 838 in
adam@1654 839 (SgiCon (SYMBOL, SOME k, c), loc)
adam@1654 840 end
adam@1654 841 end)
adamc@805 842 | DATATYPE dtypes ((SgiDatatype dtypes, s (DATATYPEleft, dtypesright)))
adamc@191 843 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
adamc@191 844 (case dargs of
adamc@191 845 [] => (SgiDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
adamc@191 846 | _ => raise Fail "Arguments specified for imported datatype")
adamc@706 847 | VAL SYMBOL COLON cexp ((SgiVal (SYMBOL, cexp), s (VALleft, cexpright)))
adamc@30 848
adamc@706 849 | STRUCTURE CSYMBOL COLON sgn ((SgiStr (CSYMBOL, sgn), s (STRUCTUREleft, sgnright)))
adamc@706 850 | SIGNATURE CSYMBOL EQ sgn ((SgiSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright)))
adamc@42 851 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@706 852 ((SgiStr (CSYMBOL1,
adamc@706 853 (SgnFun (CSYMBOL2, sgn1, sgn2), s (FUNCTORleft, sgn2right))),
adamc@706 854 s (FUNCTORleft, sgn2right)))
adamc@706 855 | INCLUDE sgn ((SgiInclude sgn, s (INCLUDEleft, sgnright)))
adamc@706 856 | CONSTRAINT cterm TWIDDLE cterm ((SgiConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright)))
adamc@707 857 | TABLE SYMBOL COLON cterm pkopt commaOpt cstopt (let
adamc@707 858 val loc = s (TABLEleft, ctermright)
adamc@707 859 in
adamc@707 860 (SgiTable (SYMBOL, entable cterm, pkopt, cstopt), loc)
adamc@707 861 end)
adamc@460 862 | SEQUENCE SYMBOL (let
adamc@460 863 val loc = s (SEQUENCEleft, SYMBOLright)
adamc@460 864 val t = (CVar (["Basis"], "sql_sequence"), loc)
adamc@460 865 in
adamc@460 866 (SgiVal (SYMBOL, t), loc)
adamc@460 867 end)
adamc@754 868 | VIEW SYMBOL COLON cexp (let
adamc@754 869 val loc = s (VIEWleft, cexpright)
adamc@754 870 val t = (CVar (["Basis"], "sql_view"), loc)
adamc@1076 871 val t = (CApp (t, entable cexp), loc)
adamc@754 872 in
adamc@754 873 (SgiVal (SYMBOL, t), loc)
adamc@754 874 end)
adamc@563 875 | CLASS SYMBOL (let
adamc@563 876 val loc = s (CLASSleft, SYMBOLright)
adamc@711 877 val k = (KArrow ((KType, loc), (KType, loc)), loc)
adamc@563 878 in
adamc@711 879 (SgiClassAbs (SYMBOL, k), loc)
adamc@563 880 end)
adamc@563 881 | CLASS SYMBOL DCOLON kind (let
adamc@563 882 val loc = s (CLASSleft, kindright)
adamc@563 883 in
adamc@563 884 (SgiClassAbs (SYMBOL, kind), loc)
adamc@563 885 end)
adamc@563 886 | CLASS SYMBOL EQ cexp (let
adamc@563 887 val loc = s (CLASSleft, cexpright)
adamc@563 888 in
adamc@563 889 (SgiClass (SYMBOL, (KWild, loc), cexp), loc)
adamc@563 890 end)
adamc@563 891 | CLASS SYMBOL DCOLON kind EQ cexp (let
adamc@563 892 val loc = s (CLASSleft, cexpright)
adamc@563 893 in
adamc@563 894 (SgiClass (SYMBOL, kind, cexp), loc)
adamc@563 895 end)
adamc@211 896 | CLASS SYMBOL SYMBOL EQ cexp (let
adamc@211 897 val loc = s (CLASSleft, cexpright)
adamc@563 898 val k = (KWild, loc)
adamc@211 899 val c = (CAbs (SYMBOL2, SOME k, cexp), loc)
adamc@211 900 in
adamc@563 901 (SgiClass (SYMBOL1, k, c), s (CLASSleft, cexpright))
adamc@563 902 end)
adamc@563 903 | CLASS SYMBOL LPAREN SYMBOL DCOLON kind RPAREN EQ cexp (let
adamc@563 904 val loc = s (CLASSleft, cexpright)
adamc@563 905 val c = (CAbs (SYMBOL2, SOME kind, cexp), loc)
adamc@563 906 in
adamc@563 907 (SgiClass (SYMBOL1, kind, c), s (CLASSleft, cexpright))
adamc@211 908 end)
adamc@460 909 | COOKIE SYMBOL COLON cexp (let
adamc@460 910 val loc = s (COOKIEleft, cexpright)
adamc@460 911 val t = (CApp ((CVar (["Basis"], "http_cookie"), loc),
adamc@460 912 entable cexp), loc)
adamc@460 913 in
adamc@460 914 (SgiVal (SYMBOL, t), loc)
adamc@460 915 end)
adamc@720 916 | STYLE SYMBOL (let
adamc@720 917 val loc = s (STYLEleft, SYMBOLright)
adamc@720 918 val t = (CVar (["Basis"], "css_class"), loc)
adamc@718 919 in
adamc@718 920 (SgiVal (SYMBOL, t), loc)
adamc@718 921 end)
adamc@30 922
adamc@30 923 sgis : ([])
adamc@30 924 | sgi sgis (sgi :: sgis)
adamc@30 925
adamc@30 926 str : STRUCT decls END (StrConst decls, s (STRUCTleft, ENDright))
adamc@34 927 | spath (spath)
adamc@40 928 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN DARROW str
adamc@40 929 (StrFun (CSYMBOL, sgn, NONE, str), s (FUNCTORleft, strright))
adamc@40 930 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn DARROW str
adamc@40 931 (StrFun (CSYMBOL, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))
adamc@44 932 | spath LPAREN str RPAREN (StrApp (spath, str), s (spathleft, RPARENright))
adamc@34 933
adamc@34 934 spath : CSYMBOL (StrVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@34 935 | spath DOT CSYMBOL (StrProj (spath, CSYMBOL), s (spathleft, CSYMBOLright))
adamc@30 936
adamc@1 937 kind : TYPE (KType, s (TYPEleft, TYPEright))
adamc@1 938 | NAME (KName, s (NAMEleft, NAMEright))
adamc@1 939 | LBRACE kind RBRACE (KRecord kind, s (LBRACEleft, RBRACEright))
adamc@1 940 | kind ARROW kind (KArrow (kind1, kind2), s (kind1left, kind2right))
adamc@1 941 | LPAREN kind RPAREN (#1 kind, s (LPARENleft, RPARENright))
adamc@82 942 | KUNIT (KUnit, s (KUNITleft, KUNITright))
adamc@18 943 | UNDERUNDER (KWild, s (UNDERUNDERleft, UNDERUNDERright))
adamc@207 944 | LPAREN ktuple RPAREN (KTuple ktuple, s (LPARENleft, RPARENright))
adamc@623 945 | CSYMBOL (KVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@623 946 | CSYMBOL KARROW kind (KFun (CSYMBOL, kind), s (CSYMBOLleft, kindright))
adamc@207 947
adamc@207 948 ktuple : kind STAR kind ([kind1, kind2])
adamc@207 949 | kind STAR ktuple (kind :: ktuple)
adamc@1 950
adamc@1 951 capps : cterm (cterm)
adamc@1 952 | capps cterm (CApp (capps, cterm), s (cappsleft, ctermright))
adamc@1 953
adamc@1 954 cexp : capps (capps)
adamc@1 955 | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right))
adamc@15 956 | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright))
adamc@623 957 | CSYMBOL KARROW cexp (TKFun (CSYMBOL, cexp), s (CSYMBOLleft, cexpright))
adamc@1 958
adamc@1 959 | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right))
adamc@1 960
adamc@239 961 | FN cargs DARROW cexp (#1 (cargs (cexp, (KWild, s (FNleft, cexpright)))))
adamc@628 962 | LBRACK cexp TWIDDLE cexp RBRACK DARROW cexp (TDisjoint (cexp1, cexp2, cexp3), s (LBRACKleft, cexp3right))
adamc@623 963 | CSYMBOL DKARROW cexp (CKAbs (CSYMBOL, cexp), s (CSYMBOLleft, cexpright))
adamc@1 964
adamc@8 965 | LPAREN cexp RPAREN DCOLON kind (CAnnot (cexp, kind), s (LPARENleft, kindright))
adamc@6 966
adamc@18 967 | UNDER DCOLON kind (CWild kind, s (UNDERleft, UNDERright))
adamc@195 968 | ctuple (let
adamc@195 969 val loc = s (ctupleleft, ctupleright)
adamc@195 970 in
adamc@195 971 (TRecord (CRecord (ListUtil.mapi (fn (i, c) =>
adamc@195 972 ((CName (Int.toString (i + 1)), loc),
adamc@195 973 c)) ctuple),
adamc@195 974 loc), loc)
adamc@195 975 end)
adamc@18 976
adamc@1 977 kcolon : DCOLON (Explicit)
adamc@1 978 | TCOLON (Implicit)
adamc@1 979
adamc@239 980 cargs : carg (carg)
adamc@239 981 | cargl (cargl)
adamc@239 982
adamc@239 983 cargl : cargp cargp (cargp1 o cargp2)
adamc@239 984 | cargp cargl (cargp o cargl)
adamc@239 985
adamc@240 986 cargl2 : (fn x => x)
adamc@240 987 | cargp cargl2 (cargp o cargl2)
adamc@240 988
adamc@241 989 carg : SYMBOL DCOLON kind (fn (c, k) =>
adamc@239 990 let
adamc@239 991 val loc = s (SYMBOLleft, kindright)
adamc@239 992 in
adamc@239 993 ((CAbs (SYMBOL, SOME kind, c), loc),
adamc@239 994 (KArrow (kind, k), loc))
adamc@239 995 end)
adamc@329 996 | UNDER DCOLON kind (fn (c, k) =>
adamc@329 997 let
adamc@329 998 val loc = s (UNDERleft, kindright)
adamc@329 999 in
adamc@329 1000 ((CAbs ("_", SOME kind, c), loc),
adamc@329 1001 (KArrow (kind, k), loc))
adamc@329 1002 end)
adam@1302 1003 | SYMBOL DCOLONWILD (fn (c, k) =>
adam@1302 1004 let
adam@1302 1005 val loc = s (SYMBOLleft, DCOLONWILDright)
adam@1302 1006 val kind = (KWild, loc)
adam@1302 1007 in
adam@1302 1008 ((CAbs (SYMBOL, NONE, c), loc),
adam@1302 1009 (KArrow (kind, k), loc))
adam@1302 1010 end)
adam@1302 1011 | UNDER DCOLONWILD (fn (c, k) =>
adam@1302 1012 let
adam@1302 1013 val loc = s (UNDERleft, DCOLONWILDright)
adam@1302 1014 val kind = (KWild, loc)
adam@1302 1015 in
adam@1302 1016 ((CAbs ("_", NONE, c), loc),
adam@1302 1017 (KArrow (kind, k), loc))
adam@1302 1018 end)
adamc@241 1019 | cargp (cargp)
adamc@239 1020
adamc@239 1021 cargp : SYMBOL (fn (c, k) =>
adamc@239 1022 let
adamc@239 1023 val loc = s (SYMBOLleft, SYMBOLright)
adamc@239 1024 in
adamc@239 1025 ((CAbs (SYMBOL, NONE, c), loc),
adamc@239 1026 (KArrow ((KWild, loc), k), loc))
adamc@239 1027 end)
adamc@329 1028 | UNDER (fn (c, k) =>
adamc@329 1029 let
adamc@329 1030 val loc = s (UNDERleft, UNDERright)
adamc@329 1031 in
adamc@329 1032 ((CAbs ("_", NONE, c), loc),
adamc@329 1033 (KArrow ((KWild, loc), k), loc))
adamc@329 1034 end)
adamc@1001 1035 | LPAREN SYMBOL kopt ckl RPAREN (fn (c, k) =>
adamc@239 1036 let
adamc@239 1037 val loc = s (LPARENleft, RPARENright)
adamc@1001 1038 val ckl = (SYMBOL, kopt) :: ckl
adamc@1001 1039 val ckl = map (fn (x, ko) => (x, case ko of
adamc@1001 1040 NONE => (KWild, loc)
adamc@1001 1041 | SOME k => k)) ckl
adamc@239 1042 in
adamc@1001 1043 case ckl of
adamc@1001 1044 [(x, k')] => ((CAbs (SYMBOL, SOME k', c), loc),
adamc@1001 1045 (KArrow (k', k), loc))
adamc@1001 1046 | _ =>
adamc@1001 1047 let
adamc@1001 1048 val k' = (KTuple (map #2 ckl), loc)
adamc@1001 1049
adamc@1001 1050 val c = foldr (fn ((x, k), c) =>
adamc@1001 1051 (CAbs (x, SOME k, c), loc)) c ckl
adamc@1001 1052 val v = (CVar ([], "$x"), loc)
adamc@1001 1053 val c = ListUtil.foldli (fn (i, _, c) =>
adamc@1001 1054 (CApp (c, (CProj (v, i + 1), loc)),
adamc@1001 1055 loc)) c ckl
adamc@1001 1056 in
adamc@1001 1057 ((CAbs ("$x", SOME k', c), loc),
adamc@1001 1058 (KArrow (k', k), loc))
adamc@1001 1059 end
adamc@239 1060 end)
adamc@628 1061
adamc@1001 1062 ckl : ([])
adamc@1001 1063 | COMMA SYMBOL kopt ckl ((SYMBOL, kopt) :: ckl)
adamc@239 1064
adamc@34 1065 path : SYMBOL ([], SYMBOL)
adamc@34 1066 | CSYMBOL DOT path (let val (ms, x) = path in (CSYMBOL :: ms, x) end)
adamc@34 1067
adamc@156 1068 cpath : CSYMBOL ([], CSYMBOL)
adamc@156 1069 | CSYMBOL DOT cpath (let val (ms, x) = cpath in (CSYMBOL :: ms, x) end)
adamc@156 1070
adamc@59 1071 mpath : CSYMBOL ([CSYMBOL])
adamc@59 1072 | CSYMBOL DOT mpath (CSYMBOL :: mpath)
adamc@59 1073
adamc@1 1074 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright))
adamc@1 1075 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright))
adamc@83 1076 | LBRACK rconn RBRACK (CRecord rconn, s (LBRACKleft, RBRACKright))
adamc@1 1077 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)),
adamc@1 1078 s (LBRACEleft, RBRACEright))
adamc@1 1079 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright))
adamc@1 1080 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright))
adamc@195 1081 | HASH INT (CName (Int64.toString INT), s (HASHleft, INTright))
adamc@1 1082
adamc@34 1083 | path (CVar path, s (pathleft, pathright))
adamc@207 1084 | path DOT INT (CProj ((CVar path, s (pathleft, pathright)), Int64.toInt INT),
adamc@207 1085 s (pathleft, INTright))
adamc@18 1086 | UNDER (CWild (KWild, s (UNDERleft, UNDERright)), s (UNDERleft, UNDERright))
adamc@621 1087 | MAP (CMap, s (MAPleft, MAPright))
adamc@82 1088 | UNIT (CUnit, s (UNITleft, UNITright))
adamc@207 1089 | LPAREN ctuplev RPAREN (CTuple ctuplev, s (LPARENleft, RPARENright))
adamc@207 1090
adamc@207 1091 ctuplev: cexp COMMA cexp ([cexp1, cexp2])
adamc@207 1092 | cexp COMMA ctuplev (cexp :: ctuplev)
adamc@1 1093
adamc@196 1094 ctuple : capps STAR capps ([capps1, capps2])
adamc@196 1095 | capps STAR ctuple (capps :: ctuple)
adamc@195 1096
adamc@1 1097 rcon : ([])
adamc@1 1098 | ident EQ cexp ([(ident, cexp)])
adamc@1 1099 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon)
adamc@1 1100
adamc@83 1101 rconn : ident ([(ident, (CUnit, s (identleft, identright)))])
adamc@83 1102 | ident COMMA rconn ((ident, (CUnit, s (identleft, identright))) :: rconn)
adamc@83 1103
adamc@1 1104 rcone : ([])
adamc@1 1105 | ident COLON cexp ([(ident, cexp)])
adamc@1 1106 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone)
adamc@1 1107
adamc@1 1108 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@195 1109 | INT (CName (Int64.toString INT), s (INTleft, INTright))
adamc@200 1110 | SYMBOL (CVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@8 1111
adamc@8 1112 eapps : eterm (eterm)
adamc@8 1113 | eapps eterm (EApp (eapps, eterm), s (eappsleft, etermright))
adamc@8 1114 | eapps LBRACK cexp RBRACK (ECApp (eapps, cexp), s (eappsleft, RBRACKright))
adamc@629 1115 | eapps BANG (EDisjointApp eapps, s (eappsleft, BANGright))
adamc@8 1116
adam@1751 1117 eexp : eapps (case #1 eapps of
adam@1751 1118 EApp ((EVar ([], "CLASS", _), _), (EPrim (Prim.String s), loc)) => parseClass s loc
adam@1751 1119 | EApp ((EVar ([], "STYLE", _), _), (EPrim (Prim.String s), loc)) => parseStyle s loc
adam@1751 1120 | _ => eapps)
adamc@241 1121 | FN eargs DARROW eexp (let
adamc@93 1122 val loc = s (FNleft, eexpright)
adamc@93 1123 in
adamc@241 1124 #1 (eargs (eexp, (CWild (KType, loc), loc)))
adamc@93 1125 end)
adamc@623 1126 | CSYMBOL DKARROW eexp (EKAbs (CSYMBOL, eexp), s (CSYMBOLleft, eexpright))
adamc@196 1127 | eexp COLON cexp (EAnnot (eexp, cexp), s (eexpleft, cexpright))
adamc@149 1128 | eexp MINUSMINUS cexp (ECut (eexp, cexp), s (eexpleft, cexpright))
adamc@493 1129 | eexp MINUSMINUSMINUS cexp (ECutMulti (eexp, cexp), s (eexpleft, cexpright))
adamc@170 1130 | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
adamc@190 1131 | IF eexp THEN eexp ELSE eexp (let
adamc@190 1132 val loc = s (IFleft, eexp3right)
adamc@190 1133 in
adamc@190 1134 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc), eexp2),
adamc@190 1135 ((PCon (["Basis"], "False", NONE), loc), eexp3)]), loc)
adamc@190 1136 end)
adamc@434 1137 | bind SEMI eexp (let
adamc@434 1138 val loc = s (bindleft, eexpright)
adamc@434 1139 val (v, to, e1) = bind
adamc@403 1140 val e = (EVar (["Basis"], "bind", Infer), loc)
adamc@434 1141 val e = (EApp (e, e1), loc)
adamc@243 1142 in
adamc@434 1143 (EApp (e, (EAbs (v, to, eexp), loc)), loc)
adamc@299 1144 end)
adamc@256 1145 | eexp EQ eexp (native_op ("eq", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@257 1146 | eexp NE eexp (native_op ("ne", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 1147 | MINUS eterm (native_unop ("neg", eterm, s (MINUSleft, etermright)))
adamc@389 1148 | eexp PLUS eexp (native_op ("plus", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 1149 | eexp MINUS eexp (native_op ("minus", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@1116 1150 | eapps STAR eexp (native_op ("times", eapps, eexp, s (eappsleft, eexpright)))
adamc@964 1151 | eexp DIVIDE eexp (native_op ("divide", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@389 1152 | eexp MOD eexp (native_op ("mod", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1153
adamc@391 1154 | eexp LT eexp (native_op ("lt", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1155 | eexp LE eexp (native_op ("le", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1156 | eexp GT eexp (native_op ("gt", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1157 | eexp GE eexp (native_op ("ge", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@391 1158
adamc@842 1159 | eexp ANDALSO eexp (let
adamc@842 1160 val loc = s (eexp1left, eexp2right)
adamc@842 1161 in
adamc@842 1162 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc),
adamc@842 1163 eexp2),
adamc@842 1164 ((PCon (["Basis"], "False", NONE), loc),
adamc@842 1165 (EVar (["Basis"], "False", Infer), loc))]), loc)
adamc@842 1166 end)
adamc@842 1167 | eexp ORELSE eexp (let
adamc@842 1168 val loc = s (eexp1left, eexp2right)
adamc@842 1169 in
adamc@842 1170 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc),
adamc@842 1171 (EVar (["Basis"], "True", Infer), loc)),
adamc@842 1172 ((PCon (["Basis"], "False", NONE), loc),
adamc@842 1173 eexp2)]), loc)
adamc@842 1174 end)
adamc@842 1175
adamc@445 1176 | eexp PLUSPLUS eexp (EConcat (eexp1, eexp2), s (eexp1left, eexp2right))
adamc@8 1177
adamc@674 1178 | eexp CARET eexp (native_op ("strcat", eexp1, eexp2, s (eexp1left, eexp2right)))
adamc@674 1179
adamc@794 1180 | eapps DCOLON eexp (let
adamc@794 1181 val loc = s (eappsleft, eexpright)
adamc@762 1182 in
adamc@762 1183 (EApp ((EVar (["Basis"], "Cons", Infer), loc),
adamc@762 1184 (ERecord [((CName "1", loc),
adamc@794 1185 eapps),
adamc@762 1186 ((CName "2", loc),
adamc@762 1187 eexp)], loc)), loc)
adamc@762 1188 end)
adamc@762 1189
adamc@434 1190 bind : SYMBOL LARROW eapps (SYMBOL, NONE, eapps)
adamc@434 1191 | eapps (let
adamc@434 1192 val loc = s (eappsleft, eappsright)
adamc@434 1193 in
adamc@434 1194 ("_", SOME (TRecord (CRecord [], loc), loc), eapps)
adamc@434 1195 end)
adamc@434 1196
adamc@241 1197 eargs : earg (earg)
adamc@241 1198 | eargl (eargl)
adamc@241 1199
adamc@241 1200 eargl : eargp eargp (eargp1 o eargp2)
adamc@241 1201 | eargp eargl (eargp o eargl)
adamc@241 1202
adamc@242 1203 eargl2 : (fn x => x)
adamc@242 1204 | eargp eargl2 (eargp o eargl2)
adamc@242 1205
adamc@822 1206 earg : patS (fn (e, t) =>
adamc@241 1207 let
adamc@822 1208 val loc = s (patSleft, patSright)
adamc@822 1209 val pt = patType loc patS
adamc@822 1210
adamc@822 1211 val e' = case #1 patS of
adamc@822 1212 PVar x => (EAbs (x, NONE, e), loc)
adamc@823 1213 | PAnnot ((PVar x, _), t) => (EAbs (x, SOME t, e), loc)
adamc@822 1214 | _ => (EAbs ("$x", SOME pt,
adamc@822 1215 (ECase ((EVar ([], "$x", DontInfer),
adamc@822 1216 loc),
adamc@822 1217 [(patS, e)]), loc)), loc)
adamc@241 1218 in
adamc@822 1219 (e', (TFun (pt, t), loc))
adamc@241 1220 end)
adamc@822 1221 | earga (earga)
adamc@822 1222
adamc@822 1223 eargp : pterm (fn (e, t) =>
adamc@241 1224 let
adamc@822 1225 val loc = s (ptermleft, ptermright)
adamc@822 1226 val pt = patType loc pterm
adamc@822 1227
adamc@822 1228 val e' = case #1 pterm of
adamc@822 1229 PVar x => (EAbs (x, NONE, e), loc)
adamc@823 1230 | PAnnot ((PVar x, _), t) => (EAbs (x, SOME t, e), loc)
adamc@822 1231 | _ => (EAbs ("$x", SOME pt,
adamc@822 1232 (ECase ((EVar ([], "$x", DontInfer),
adamc@822 1233 loc),
adamc@822 1234 [(pterm, e)]), loc)), loc)
adamc@241 1235 in
adamc@822 1236 (e', (TFun (pt, t), loc))
adamc@241 1237 end)
adamc@822 1238 | earga (earga)
adamc@241 1239
adamc@822 1240 earga : LBRACK SYMBOL RBRACK (fn (e, t) =>
adamc@241 1241 let
adamc@822 1242 val loc = s (LBRACKleft, RBRACKright)
adamc@822 1243 val kind = (KWild, loc)
adamc@822 1244 in
adamc@822 1245 ((ECAbs (Implicit, SYMBOL, kind, e), loc),
adamc@822 1246 (TCFun (Implicit, SYMBOL, kind, t), loc))
adamc@822 1247 end)
adam@1302 1248 | LBRACK SYMBOL DCOLONWILD RBRACK (fn (e, t) =>
adam@1302 1249 let
adam@1302 1250 val loc = s (LBRACKleft, RBRACKright)
adam@1302 1251 val kind = (KWild, loc)
adam@1302 1252 in
adam@1302 1253 ((ECAbs (Explicit, SYMBOL, kind, e), loc),
adam@1302 1254 (TCFun (Explicit, SYMBOL, kind, t), loc))
adam@1302 1255 end)
adamc@822 1256 | LBRACK SYMBOL kcolon kind RBRACK(fn (e, t) =>
adamc@822 1257 let
adamc@822 1258 val loc = s (LBRACKleft, RBRACKright)
adamc@241 1259 in
adamc@241 1260 ((ECAbs (kcolon, SYMBOL, kind, e), loc),
adamc@241 1261 (TCFun (kcolon, SYMBOL, kind, t), loc))
adamc@241 1262 end)
adam@1306 1263 | LBRACK SYMBOL TCOLONWILD RBRACK (fn (e, t) =>
adam@1306 1264 let
adam@1306 1265 val loc = s (LBRACKleft, RBRACKright)
adam@1306 1266 val kind = (KWild, loc)
adam@1306 1267 in
adam@1306 1268 ((ECAbs (Implicit, SYMBOL, kind, e), loc),
adam@1306 1269 (TCFun (Implicit, SYMBOL, kind, t), loc))
adam@1306 1270 end)
adamc@478 1271 | LBRACK cexp TWIDDLE cexp RBRACK(fn (e, t) =>
adamc@356 1272 let
adamc@356 1273 val loc = s (LBRACKleft, RBRACKright)
adamc@356 1274 in
adamc@478 1275 ((EDisjoint (cexp1, cexp2, e), loc),
adamc@628 1276 (TDisjoint (cexp1, cexp2, t), loc))
adamc@356 1277 end)
adamc@822 1278 | LBRACK CSYMBOL RBRACK (fn (e, t) =>
adamc@623 1279 let
adamc@623 1280 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@623 1281 in
adamc@623 1282 ((EKAbs (CSYMBOL, e), loc),
adamc@623 1283 (TKFun (CSYMBOL, t), loc))
adamc@623 1284 end)
adamc@241 1285
adamc@8 1286 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
adamc@195 1287 | LPAREN etuple RPAREN (let
adamc@195 1288 val loc = s (LPARENleft, RPARENright)
adamc@195 1289 in
adamc@195 1290 (ERecord (ListUtil.mapi (fn (i, e) =>
adamc@195 1291 ((CName (Int.toString (i + 1)), loc),
adamc@195 1292 e)) etuple), loc)
adamc@195 1293 end)
adamc@8 1294
adamc@403 1295 | path (EVar (#1 path, #2 path, Infer), s (pathleft, pathright))
adamc@403 1296 | cpath (EVar (#1 cpath, #2 cpath, Infer), s (cpathleft, cpathright))
adamc@403 1297 | AT path (EVar (#1 path, #2 path, TypesOnly), s (ATleft, pathright))
adamc@403 1298 | AT AT path (EVar (#1 path, #2 path, DontInfer), s (AT1left, pathright))
adamc@403 1299 | AT cpath (EVar (#1 cpath, #2 cpath, TypesOnly), s (ATleft, cpathright))
adamc@403 1300 | AT AT cpath (EVar (#1 cpath, #2 cpath, DontInfer), s (AT1left, cpathright))
adamc@12 1301 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
adamc@110 1302 | UNIT (ERecord [], s (UNITleft, UNITright))
adamc@12 1303
adamc@14 1304 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@14 1305 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@14 1306 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@821 1307 | CHAR (EPrim (Prim.Char CHAR), s (CHARleft, CHARright))
adamc@14 1308
adamc@200 1309 | path DOT idents (let
adamc@200 1310 val loc = s (pathleft, identsright)
adamc@200 1311 in
adamc@200 1312 foldl (fn (ident, e) =>
adamc@200 1313 (EField (e, ident), loc))
adamc@403 1314 (EVar (#1 path, #2 path, Infer), s (pathleft, pathright)) idents
adamc@403 1315 end)
adamc@910 1316 | LPAREN eexp RPAREN DOT idents (let
adamc@910 1317 val loc = s (LPARENleft, identsright)
adamc@910 1318 in
adamc@910 1319 foldl (fn (ident, e) =>
adamc@910 1320 (EField (e, ident), loc))
adamc@910 1321 eexp idents
adamc@910 1322 end)
adamc@403 1323 | AT path DOT idents (let
adamc@403 1324 val loc = s (ATleft, identsright)
adamc@403 1325 in
adamc@403 1326 foldl (fn (ident, e) =>
adamc@403 1327 (EField (e, ident), loc))
adamc@403 1328 (EVar (#1 path, #2 path, TypesOnly), s (pathleft, pathright)) idents
adamc@403 1329 end)
adamc@403 1330 | AT AT path DOT idents (let
adamc@403 1331 val loc = s (AT1left, identsright)
adamc@403 1332 in
adamc@403 1333 foldl (fn (ident, e) =>
adamc@403 1334 (EField (e, ident), loc))
adamc@403 1335 (EVar (#1 path, #2 path, DontInfer), s (pathleft, pathright)) idents
adamc@200 1336 end)
adamc@71 1337
adamc@360 1338 | XML_BEGIN xml XML_END (let
adamc@360 1339 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 1340 in
adamc@360 1341 if XML_BEGIN = "xml" then
adamc@360 1342 ()
adamc@360 1343 else
adamc@360 1344 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@360 1345 xml
adamc@360 1346 end)
adamc@360 1347 | XML_BEGIN XML_END (let
adamc@360 1348 val loc = s (XML_BEGINleft, XML_ENDright)
adamc@360 1349 in
adamc@360 1350 if XML_BEGIN = "xml" then
adamc@360 1351 ()
adamc@360 1352 else
adamc@360 1353 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@403 1354 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
adamc@360 1355 (EPrim (Prim.String ""), loc)),
adamc@360 1356 loc)
adamc@360 1357 end)
adamc@360 1358 | XML_BEGIN_END (let
adamc@360 1359 val loc = s (XML_BEGIN_ENDleft, XML_BEGIN_ENDright)
adamc@360 1360 in
adamc@360 1361 if XML_BEGIN_END = "xml" then
adamc@360 1362 ()
adamc@360 1363 else
adamc@360 1364 ErrorMsg.errorAt loc "Initial XML tag pair aren't both tagged \"xml\".";
adamc@403 1365 (EApp ((EVar (["Basis"], "cdata", Infer), loc),
adamc@360 1366 (EPrim (Prim.String ""), loc)),
adamc@360 1367 loc)
adamc@360 1368 end)
adamc@302 1369
adamc@204 1370 | LPAREN query RPAREN (query)
adamc@300 1371 | LPAREN CWHERE sqlexp RPAREN (sqlexp)
adamc@339 1372 | LPAREN SQL sqlexp RPAREN (sqlexp)
adamc@1070 1373 | LPAREN FROM tables RPAREN (#2 tables)
adamc@1071 1374 | LPAREN SELECT1 query1 RPAREN (query1)
adamc@302 1375
adamc@302 1376 | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN
adamc@302 1377 (let
adamc@302 1378 val loc = s (LPAREN1left, RPAREN3right)
adamc@302 1379
adamc@403 1380 val e = (EVar (["Basis"], "insert", Infer), loc)
adamc@302 1381 val e = (EApp (e, texp), loc)
adamc@302 1382 in
adamc@302 1383 if length fields <> length sqlexps then
adam@1360 1384 ErrorMsg.errorAt loc ("Length mismatch in INSERT field specification ("
adam@1360 1385 ^ Int.toString (length fields)
adam@1360 1386 ^ " vs. " ^ Int.toString (length sqlexps) ^ ")")
adamc@302 1387 else
adamc@302 1388 ();
adamc@302 1389 (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc)
adamc@302 1390 end)
adamc@310 1391 | LPAREN enterDml UPDATE texp SET fsets CWHERE sqlexp leaveDml RPAREN
adamc@303 1392 (let
adamc@303 1393 val loc = s (LPARENleft, RPARENright)
adamc@303 1394
adamc@403 1395 val e = (EVar (["Basis"], "update", Infer), loc)
adamc@342 1396 val e = (ECApp (e, (CWild (KRecord (KType, loc), loc), loc)), loc)
adamc@306 1397 val e = (EApp (e, (ERecord fsets, loc)), loc)
adamc@305 1398 val e = (EApp (e, texp), loc)
adamc@303 1399 in
adamc@303 1400 (EApp (e, sqlexp), loc)
adamc@303 1401 end)
adamc@310 1402 | LPAREN enterDml DELETE FROM texp CWHERE sqlexp leaveDml RPAREN
adamc@304 1403 (let
adamc@304 1404 val loc = s (LPARENleft, RPARENright)
adamc@304 1405
adamc@403 1406 val e = (EVar (["Basis"], "delete", Infer), loc)
adamc@304 1407 val e = (EApp (e, texp), loc)
adamc@304 1408 in
adamc@304 1409 (EApp (e, sqlexp), loc)
adamc@304 1410 end)
adamc@302 1411
adamc@211 1412 | UNDER (EWild, s (UNDERleft, UNDERright))
adamc@91 1413
adamc@446 1414 | LET edecls IN eexp END (ELet (edecls, eexp), s (LETleft, ENDright))
adamc@446 1415
adamc@762 1416 | LBRACK RBRACK (EVar (["Basis"], "Nil", Infer), s (LBRACKleft, RBRACKright))
adamc@762 1417
adamc@446 1418 edecls : ([])
adamc@446 1419 | edecl edecls (edecl :: edecls)
adamc@446 1420
adamc@825 1421 edecl : VAL pat EQ eexp ((EDVal (pat, eexp), s (VALleft, eexpright)))
adamc@446 1422 | VAL REC valis ((EDValRec valis, s (VALleft, valisright)))
adamc@446 1423 | FUN valis ((EDValRec valis, s (FUNleft, valisright)))
adamc@446 1424
adamc@310 1425 enterDml : (inDml := true)
adamc@310 1426 leaveDml : (inDml := false)
adamc@310 1427
adamc@403 1428 texp : SYMBOL (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
adamc@302 1429 | LBRACE LBRACE eexp RBRACE RBRACE (eexp)
adamc@302 1430
adamc@302 1431 fields : fident ([fident])
adamc@302 1432 | fident COMMA fields (fident :: fields)
adamc@302 1433
adamc@302 1434 sqlexps: sqlexp ([sqlexp])
adamc@302 1435 | sqlexp COMMA sqlexps (sqlexp :: sqlexps)
adamc@302 1436
adamc@303 1437 fsets : fident EQ sqlexp ([(fident, sqlexp)])
adamc@303 1438 | fident EQ sqlexp COMMA fsets ((fident, sqlexp) :: fsets)
adamc@303 1439
adamc@200 1440 idents : ident ([ident])
adamc@200 1441 | ident DOT idents (ident :: idents)
adamc@200 1442
adamc@195 1443 etuple : eexp COMMA eexp ([eexp1, eexp2])
adamc@195 1444 | eexp COMMA etuple (eexp :: etuple)
adamc@195 1445
adamc@170 1446 branch : pat DARROW eexp (pat, eexp)
adamc@170 1447
adamc@170 1448 branchs: ([])
adamc@170 1449 | BAR branch branchs (branch :: branchs)
adamc@170 1450
adamc@822 1451 patS : pterm (pterm)
adamc@822 1452 | pterm DCOLON patS (let
adamc@822 1453 val loc = s (ptermleft, patSright)
adamc@762 1454 in
adamc@762 1455 (PCon (["Basis"], "Cons", SOME (PRecord ([("1", pterm),
adamc@822 1456 ("2", patS)], false), loc)),
adamc@762 1457 loc)
adamc@762 1458 end)
adamc@822 1459 | patS COLON cexp (PAnnot (patS, cexp), s (patSleft, cexpright))
adamc@822 1460
adamc@822 1461 pat : patS (patS)
adamc@822 1462 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
adamc@170 1463
adamc@170 1464 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
adamc@170 1465 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
adamc@170 1466 | UNDER (PWild, s (UNDERleft, UNDERright))
adamc@173 1467 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
adam@1420 1468 | MINUS INT (PPrim (Prim.Int (~INT)), s (MINUSleft, INTright))
adamc@173 1469 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@821 1470 | CHAR (PPrim (Prim.Char CHAR), s (CHARleft, CHARright))
adamc@170 1471 | LPAREN pat RPAREN (pat)
adamc@174 1472 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
adamc@174 1473 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
adamc@174 1474 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
adamc@195 1475 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
adamc@195 1476 false),
adamc@195 1477 s (LPARENleft, RPARENright))
adamc@762 1478 | LBRACK RBRACK (PCon (["Basis"], "Nil", NONE), s (LBRACKleft, RBRACKright))
adamc@174 1479
adamc@175 1480 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
adamc@243 1481 | INT EQ pat ([(Int64.toString INT, pat)], false)
adamc@174 1482 | DOTDOTDOT ([], true)
adamc@175 1483 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
adamc@243 1484 | INT EQ pat COMMA rpat ((Int64.toString INT, pat) :: #1 rpat, #2 rpat)
adamc@170 1485
adamc@195 1486 ptuple : pat COMMA pat ([pat1, pat2])
adamc@195 1487 | pat COMMA ptuple (pat :: ptuple)
adamc@195 1488
adamc@12 1489 rexp : ([])
adamc@12 1490 | ident EQ eexp ([(ident, eexp)])
adamc@12 1491 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
adamc@91 1492
adamc@141 1493 xml : xmlOne xml (let
adamc@141 1494 val pos = s (xmlOneleft, xmlright)
adamc@141 1495 in
adamc@720 1496 (EApp ((EApp (
adamc@720 1497 (EVar (["Basis"], "join", Infer), pos),
adamc@720 1498 xmlOne), pos),
adamc@720 1499 xml), pos)
adamc@141 1500 end)
adamc@141 1501 | xmlOne (xmlOne)
adamc@91 1502
adamc@1045 1503 xmlOpt : xml (xml)
adamc@1045 1504 | (EApp ((EVar (["Basis"], "cdata", Infer), dummy),
adamc@1045 1505 (EPrim (Prim.String ""), dummy)),
adamc@1045 1506 dummy)
adamc@1045 1507
adamc@403 1508 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata", Infer), s (NOTAGSleft, NOTAGSright)),
adamc@141 1509 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
adamc@141 1510 s (NOTAGSleft, NOTAGSright))
adamc@141 1511 | tag DIVIDE GT (let
adamc@141 1512 val pos = s (tagleft, GTright)
adamc@710 1513
adamc@710 1514 val cdata =
adamc@756 1515 if #1 (#1 tag) = "submit" orelse #1 (#1 tag) = "dyn" then
adamc@710 1516 let
adamc@710 1517 val e = (EVar (["Basis"], "cdata", DontInfer), pos)
adamc@710 1518 val e = (ECApp (e, (CWild (KWild, pos), pos)), pos)
adamc@710 1519 in
adamc@710 1520 (ECApp (e, (CRecord [], pos)), pos)
adamc@710 1521 end
adamc@710 1522 else
adamc@710 1523 (EVar (["Basis"], "cdata", Infer), pos)
adamc@710 1524
adamc@710 1525 val cdata = (EApp (cdata,
adamc@710 1526 (EPrim (Prim.String ""), pos)),
adamc@710 1527 pos)
adamc@141 1528 in
adam@1643 1529 (EApp (#4 tag, cdata), pos)
adamc@141 1530 end)
adamc@141 1531
adamc@1045 1532 | tag GT xmlOpt END_TAG (let
adam@1563 1533 fun tagOut s =
adam@1563 1534 case s of
adam@1563 1535 "tabl" => "table"
adam@1563 1536 | _ => s
adam@1563 1537
adamc@141 1538 val pos = s (tagleft, GTright)
adamc@325 1539 val et = tagIn END_TAG
adamc@141 1540 in
adamc@756 1541 if #1 (#1 tag) = et then
adamc@361 1542 if et = "form" then
adam@1412 1543 let
adam@1412 1544 val e = (EVar (["Basis"], "form", Infer), pos)
adam@1412 1545 val e = (EApp (e, case #2 tag of
adam@1412 1546 NONE => (EVar (["Basis"], "None", Infer), pos)
adam@1412 1547 | SOME c => (EApp ((EVar (["Basis"], "Some", Infer), pos), c), pos)), pos)
adam@1412 1548 in
adam@1651 1549 case #3 tag of
adam@1651 1550 NONE => ()
adam@1651 1551 | SOME _ => ErrorMsg.errorAt pos "<form> does not support 'dynClass' attribute";
adam@1412 1552 (EApp (e, xmlOpt), pos)
adam@1412 1553 end
adamc@1093 1554 else if et = "subform" orelse et = "subforms" then
adamc@1093 1555 (EApp (#2 (#1 tag),
adamc@1045 1556 xmlOpt), pos)
adamc@758 1557 else if et = "entry" then
adamc@758 1558 (EApp ((EVar (["Basis"], "entry", Infer), pos),
adamc@1045 1559 xmlOpt), pos)
adamc@141 1560 else
adam@1643 1561 (EApp (#4 tag, xmlOpt), pos)
adamc@141 1562 else
adamc@325 1563 (if ErrorMsg.anyErrors () then
adamc@325 1564 ()
adamc@325 1565 else
adamc@1189 1566 ErrorMsg.errorAt pos ("Begin tag <"
adam@1563 1567 ^ tagOut (#1 (#1 tag))
adamc@1189 1568 ^ "> and end tag </"
adam@1563 1569 ^ tagOut et
adamc@1189 1570 ^ "> don't match.");
adamc@623 1571 (EWild, pos))
adamc@141 1572 end)
adamc@141 1573 | LBRACE eexp RBRACE (eexp)
adamc@391 1574 | LBRACE LBRACK eexp RBRACK RBRACE (let
adamc@391 1575 val loc = s (LBRACEleft, RBRACEright)
adamc@403 1576 val e = (EVar (["Top"], "txt", Infer), loc)
adamc@391 1577 in
adamc@391 1578 (EApp (e, eexp), loc)
adamc@391 1579 end)
adamc@92 1580
adamc@141 1581 tag : tagHead attrs (let
adamc@141 1582 val pos = s (tagHeadleft, attrsright)
adamc@721 1583
adamc@721 1584 val e = (EVar (["Basis"], "tag", Infer), pos)
adamc@721 1585 val eo = case #1 attrs of
adam@1749 1586 NONE => (EVar (["Basis"], "null", Infer), pos)
adam@1749 1587 | SOME (EPrim (Prim.String s), pos) => parseClass s pos
adam@1749 1588 | SOME e => e
adamc@721 1589 val e = (EApp (e, eo), pos)
adam@1643 1590 val eo = case #2 attrs of
adam@1643 1591 NONE => (EVar (["Basis"], "None", Infer), pos)
adam@1643 1592 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos),
adam@1643 1593 e), pos)
adam@1643 1594 val e = (EApp (e, eo), pos)
adam@1750 1595 val eo = case #3 attrs of
adam@1750 1596 NONE => (EVar (["Basis"], "noStyle", Infer), pos)
adam@1750 1597 | SOME (EPrim (Prim.String s), pos) => parseStyle s pos
adam@1750 1598 | SOME e => e
adam@1750 1599 val e = (EApp (e, eo), pos)
adam@1751 1600 val eo = case #4 attrs of
adam@1751 1601 NONE => (EVar (["Basis"], "None", Infer), pos)
adam@1751 1602 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos),
adam@1751 1603 e), pos)
adam@1751 1604 val e = (EApp (e, eo), pos)
adam@2008 1605
adam@2008 1606 val atts = case #5 attrs of
adam@2008 1607 [] => #6 attrs
adam@2008 1608 | data :: datas =>
adam@2008 1609 let
adam@2008 1610 fun doOne (name, value) =
adam@2008 1611 let
adam@2008 1612 val e = (EVar (["Basis"], "data_attr", Infer), pos)
adam@2008 1613 val e = (EApp (e, (EPrim (Prim.String name), pos)), pos)
adam@2008 1614 in
adam@2008 1615 (EApp (e, value), pos)
adam@2008 1616 end
adam@2008 1617
adam@2008 1618 val datas' = foldl (fn (nv, acc) =>
adam@2008 1619 let
adam@2008 1620 val e = (EVar (["Basis"], "data_attrs", Infer), pos)
adam@2008 1621 val e = (EApp (e, acc), pos)
adam@2008 1622 in
adam@2008 1623 (EApp (e, doOne nv), pos)
adam@2008 1624 end) (doOne data) datas
adam@2008 1625 in
adam@2008 1626 ((CName "Data", pos), datas') :: #6 attrs
adam@2008 1627 end
adam@2008 1628
adam@2008 1629 val e = (EApp (e, (ERecord atts, pos)), pos)
adamc@721 1630 val e = (EApp (e, (EApp (#2 tagHead,
adamc@721 1631 (ERecord [], pos)), pos)), pos)
adamc@141 1632 in
adam@1643 1633 (tagHead, #1 attrs, #2 attrs, e)
adamc@141 1634 end)
adamc@141 1635
adamc@141 1636 tagHead: BEGIN_TAG (let
adamc@325 1637 val bt = tagIn BEGIN_TAG
adamc@141 1638 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
adamc@141 1639 in
adamc@325 1640 (bt,
adam@1833 1641 (EVar ([], bt, Infer), pos))
adamc@141 1642 end)
adamc@141 1643 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
adamc@92 1644
adam@2008 1645 attrs : (NONE, NONE, NONE, NONE, [], [])
adamc@721 1646 | attr attrs (let
adamc@721 1647 val loc = s (attrleft, attrsright)
adamc@721 1648 in
adamc@721 1649 case attr of
adamc@721 1650 Class e =>
adamc@721 1651 (case #1 attrs of
adamc@721 1652 NONE => ()
adamc@721 1653 | SOME _ => ErrorMsg.errorAt loc "Multiple classes specified for tag";
adam@2008 1654 (SOME e, #2 attrs, #3 attrs, #4 attrs, #5 attrs, #6 attrs))
adam@1643 1655 | DynClass e =>
adam@1643 1656 (case #2 attrs of
adam@1643 1657 NONE => ()
adam@1643 1658 | SOME _ => ErrorMsg.errorAt loc "Multiple dynamic classes specified for tag";
adam@2008 1659 (#1 attrs, SOME e, #3 attrs, #4 attrs, #5 attrs, #6 attrs))
adam@1750 1660 | Style e =>
adam@1750 1661 (case #3 attrs of
adam@1750 1662 NONE => ()
adam@1750 1663 | SOME _ => ErrorMsg.errorAt loc "Multiple styles specified for tag";
adam@2008 1664 (#1 attrs, #2 attrs, SOME e, #4 attrs, #5 attrs, #6 attrs))
adam@1751 1665 | DynStyle e =>
adam@1751 1666 (case #4 attrs of
adam@1751 1667 NONE => ()
adam@1751 1668 | SOME _ => ErrorMsg.errorAt loc "Multiple dynamic classes specified for tag";
adam@2008 1669 (#1 attrs, #2 attrs, #3 attrs, SOME e, #5 attrs, #6 attrs))
adam@2008 1670 | Data xe =>
adam@2008 1671 (#1 attrs, #2 attrs, #3 attrs, #4 attrs, xe :: #5 attrs, #6 attrs)
adamc@721 1672 | Normal xe =>
adam@2008 1673 (#1 attrs, #2 attrs, #3 attrs, #4 attrs, #5 attrs, xe :: #6 attrs)
adamc@721 1674 end)
adamc@104 1675
adam@1643 1676 attr : SYMBOL EQ attrv (case SYMBOL of
adam@1643 1677 "class" => Class attrv
adam@1643 1678 | "dynClass" => DynClass attrv
adam@1750 1679 | "style" => Style attrv
adam@1751 1680 | "dynStyle" => DynStyle attrv
adam@1643 1681 | _ =>
adam@2008 1682 if String.isPrefix "data-" SYMBOL then
adam@2008 1683 Data (String.extract (SYMBOL, 5, NONE), attrv)
adam@2008 1684 else
adam@2008 1685 let
adam@2008 1686 val sym = makeAttr SYMBOL
adam@2008 1687 in
adam@2008 1688 Normal ((CName sym, s (SYMBOLleft, SYMBOLright)),
adam@2008 1689 if (sym = "Href" orelse sym = "Src")
adam@2008 1690 andalso (case #1 attrv of
adam@2008 1691 EPrim _ => true
adam@2008 1692 | _ => false) then
adam@2008 1693 let
adam@2008 1694 val loc = s (attrvleft, attrvright)
adam@2008 1695 in
adam@2008 1696 (EApp ((EVar (["Basis"], "bless", Infer), loc),
adam@2008 1697 attrv), loc)
adam@2008 1698 end
adam@2008 1699 else
adam@2008 1700 attrv)
adam@2008 1701 end)
adamc@204 1702
adamc@104 1703 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@104 1704 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@104 1705 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@110 1706 | LBRACE eexp RBRACE (eexp)
adamc@226 1707
adamc@232 1708 query : query1 obopt lopt ofopt (let
adamc@229 1709 val loc = s (query1left, query1right)
adamc@230 1710
adamc@230 1711 val re = (ERecord [((CName "Rows", loc),
adamc@230 1712 query1),
adamc@230 1713 ((CName "OrderBy", loc),
adamc@231 1714 obopt),
adamc@231 1715 ((CName "Limit", loc),
adamc@232 1716 lopt),
adamc@232 1717 ((CName "Offset", loc),
adamc@232 1718 ofopt)], loc)
adamc@229 1719 in
adamc@403 1720 (EApp ((EVar (["Basis"], "sql_query", Infer), loc), re), loc)
adamc@229 1721 end)
adamc@993 1722
adamc@993 1723 dopt : (EVar (["Basis"], "False", Infer), dummy)
adamc@993 1724 | DISTINCT (EVar (["Basis"], "True", Infer),
adamc@993 1725 s (DISTINCTleft, DISTINCTright))
adamc@993 1726
adamc@993 1727 query1 : SELECT dopt select FROM tables wopt gopt hopt
adamc@209 1728 (let
adamc@204 1729 val loc = s (SELECTleft, tablesright)
adamc@207 1730
adamc@1070 1731 val (empties, sel, exps) =
adamc@207 1732 case select of
adamc@1070 1733 Star => ([],
adamc@1070 1734 map (fn nm =>
adamc@233 1735 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
adamc@233 1736 loc),
adamc@233 1737 (CRecord [], loc)],
adamc@748 1738 loc))) (#1 tables),
adamc@233 1739 [])
adamc@207 1740 | Items sis =>
adamc@207 1741 let
adam@1627 1742 val tabs = map (fn nm => (nm, Unknown)) (#1 tables)
adamc@1194 1743 val (_, tabs, exps) = foldl (amend_select loc)
adamc@1194 1744 (1, tabs, []) sis
adam@1627 1745 val empties = List.mapPartial (fn (nm, c) =>
adam@1627 1746 case c of
adam@1627 1747 Unknown => SOME nm
adam@1627 1748 | Selective (CRecord [], _) => SOME nm
adam@1627 1749 | _ => NONE) tabs
adamc@207 1750 in
adamc@1070 1751 (empties,
adamc@1070 1752 map (fn (nm, c) => (nm,
adam@1627 1753 case c of
adam@1627 1754 Everything =>
adam@1627 1755 (CTuple [(CWild (KRecord (KType, loc), loc), loc),
adam@1627 1756 (CRecord [], loc)], loc)
adam@1627 1757 | _ =>
adam@1627 1758 let
adam@1627 1759 val c = case c of
adam@1627 1760 Selective c => c
adam@1627 1761 | _ => (CRecord [], loc)
adam@1627 1762 in
adam@1627 1763 (CTuple [c,
adam@1627 1764 (CWild (KRecord (KType, loc), loc),
adam@1627 1765 loc)], loc)
adam@1627 1766 end)) tabs,
adamc@233 1767 exps)
adamc@207 1768 end
adamc@207 1769
adam@1778 1770 val exps = map (fn (c, e) => (c, (EApp ((EVar (["Basis"], "sql_window", Infer), loc), e), loc))) exps
adam@1778 1771
adamc@207 1772 val sel = (CRecord sel, loc)
adamc@207 1773
adamc@226 1774 val grp = case gopt of
adamc@403 1775 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all",
adamc@403 1776 Infer), loc),
adamc@226 1777 (CWild (KRecord (KRecord (KType, loc), loc),
adamc@226 1778 loc), loc)), loc)
adamc@226 1779 | SOME gis =>
adamc@226 1780 let
adamc@748 1781 val tabs = map (fn nm =>
adamc@748 1782 (nm, (CRecord [], loc))) (#1 tables)
adamc@226 1783 val tabs = foldl (amend_group loc) tabs gis
adamc@226 1784
adamc@226 1785 val tabs = map (fn (nm, c) =>
adamc@226 1786 (nm,
adamc@226 1787 (CTuple [c,
adamc@226 1788 (CWild (KRecord (KType, loc),
adamc@226 1789 loc),
adamc@226 1790 loc)], loc))) tabs
adamc@226 1791 in
adamc@403 1792 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@226 1793 (CRecord tabs, loc)), loc)
adamc@226 1794 end
adamc@226 1795
adamc@403 1796 val e = (EVar (["Basis"], "sql_query1", Infer), loc)
adamc@1070 1797 val e = (ECApp (e, (CRecord (map (fn nm => (nm, (CUnit, loc))) empties),
adamc@1070 1798 loc)), loc)
adamc@993 1799 val re = (ERecord [((CName "Distinct", loc),
adamc@993 1800 dopt),
adamc@993 1801 ((CName "From", loc),
adamc@748 1802 #2 tables),
adamc@209 1803 ((CName "Where", loc),
adamc@223 1804 wopt),
adamc@224 1805 ((CName "GroupBy", loc),
adamc@226 1806 grp),
adamc@224 1807 ((CName "Having", loc),
adamc@224 1808 hopt),
adamc@223 1809 ((CName "SelectFields", loc),
adamc@403 1810 (ECApp ((EVar (["Basis"], "sql_subset", Infer), loc),
adamc@233 1811 sel), loc)),
adamc@233 1812 ((CName "SelectExps", loc),
adamc@233 1813 (ERecord exps, loc))], loc)
adamc@223 1814
adamc@209 1815 val e = (EApp (e, re), loc)
adamc@204 1816 in
adamc@207 1817 e
adamc@204 1818 end)
adam@1427 1819 | query1 UNION query1 (sql_relop ("union", false, query11, query12, s (query11left, query12right)))
adam@1427 1820 | query1 INTERSECT query1 (sql_relop ("intersect", false, query11, query12, s (query11left, query12right)))
adam@1427 1821 | query1 EXCEPT query1 (sql_relop ("except", false, query11, query12, s (query11left, query12right)))
adam@1427 1822 | query1 UNION ALL query1 (sql_relop ("union", true, query11, query12, s (query11left, query12right)))
adam@1427 1823 | query1 INTERSECT ALL query1 (sql_relop ("intersect", true, query11, query12, s (query11left, query12right)))
adam@1427 1824 | query1 EXCEPT ALL query1 (sql_relop ("except", true, query11, query12, s (query11left, query12right)))
adamc@1070 1825 | LBRACE LBRACE LBRACE eexp RBRACE RBRACE RBRACE (eexp)
adamc@204 1826
adamc@749 1827 tables : fitem (fitem)
adamc@749 1828 | fitem COMMA tables (let
adamc@749 1829 val loc = s (fitemleft, tablesright)
adamc@748 1830
adamc@748 1831 val e = (EVar (["Basis"], "sql_from_comma", Infer), loc)
adamc@749 1832 val e = (EApp (e, #2 fitem), loc)
adamc@748 1833 in
adamc@749 1834 (#1 fitem @ #1 tables,
adamc@748 1835 (EApp (e, #2 tables), loc))
adamc@748 1836 end)
adamc@204 1837
adamc@749 1838 fitem : table' ([#1 table'], #2 table')
adamc@1265 1839 | LBRACE LBRACE eexp RBRACE RBRACE (tnamesOf eexp, eexp)
adamc@749 1840 | fitem JOIN fitem ON sqlexp (let
adamc@749 1841 val loc = s (fitem1left, sqlexpright)
adamc@749 1842
adamc@749 1843 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1844 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1845 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1846 in
adamc@749 1847 (#1 fitem1 @ #1 fitem2,
adamc@749 1848 (EApp (e, sqlexp), loc))
adamc@749 1849 end)
adamc@749 1850 | fitem INNER JOIN fitem ON sqlexp (let
adamc@749 1851 val loc = s (fitem1left, sqlexpright)
adamc@749 1852
adamc@749 1853 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1854 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1855 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1856 in
adamc@749 1857 (#1 fitem1 @ #1 fitem2,
adamc@749 1858 (EApp (e, sqlexp), loc))
adamc@749 1859 end)
adamc@749 1860 | fitem CROSS JOIN fitem (let
adamc@749 1861 val loc = s (fitem1left, fitem2right)
adamc@749 1862
adamc@749 1863 val e = (EVar (["Basis"], "sql_inner_join", Infer), loc)
adamc@749 1864 val e = (EApp (e, #2 fitem1), loc)
adamc@749 1865 val e = (EApp (e, #2 fitem2), loc)
adamc@749 1866 val tru = sql_inject (EVar (["Basis"], "True", Infer), loc)
adamc@749 1867 in
adamc@749 1868 (#1 fitem1 @ #1 fitem2,
adamc@749 1869 (EApp (e, tru), loc))
adamc@749 1870 end)
adamc@750 1871 | fitem LEFT JOIN fitem ON sqlexp (let
adamc@750 1872 val loc = s (fitem1left, sqlexpright)
adamc@750 1873
adamc@750 1874 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
adamc@750 1875 val e = (EApp (e, #2 fitem1), loc)
adamc@750 1876 val e = (EApp (e, #2 fitem2), loc)
adamc@750 1877 in
adamc@750 1878 (#1 fitem1 @ #1 fitem2,
adamc@750 1879 (EApp (e, sqlexp), loc))
adamc@750 1880 end)
adamc@751 1881 | fitem LEFT OUTER JOIN fitem ON sqlexp (let
adamc@751 1882 val loc = s (fitem1left, sqlexpright)
adamc@751 1883
adamc@751 1884 val e = (EVar (["Basis"], "sql_left_join", Infer), loc)
adamc@751 1885 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1886 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1887 in
adamc@751 1888 (#1 fitem1 @ #1 fitem2,
adamc@751 1889 (EApp (e, sqlexp), loc))
adamc@751 1890 end)
adamc@751 1891 | fitem RIGHT JOIN fitem ON sqlexp (let
adamc@751 1892 val loc = s (fitem1left, sqlexpright)
adamc@751 1893
adamc@751 1894 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
adamc@751 1895 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1896 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1897 in
adamc@751 1898 (#1 fitem1 @ #1 fitem2,
adamc@751 1899 (EApp (e, sqlexp), loc))
adamc@751 1900 end)
adamc@751 1901 | fitem RIGHT OUTER JOIN fitem ON sqlexp (let
adamc@751 1902 val loc = s (fitem1left, sqlexpright)
adamc@751 1903
adamc@751 1904 val e = (EVar (["Basis"], "sql_right_join", Infer), loc)
adamc@751 1905 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1906 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1907 in
adamc@751 1908 (#1 fitem1 @ #1 fitem2,
adamc@751 1909 (EApp (e, sqlexp), loc))
adamc@751 1910 end)
adamc@751 1911 | fitem FULL JOIN fitem ON sqlexp (let
adamc@751 1912 val loc = s (fitem1left, sqlexpright)
adamc@751 1913
adamc@751 1914 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
adamc@751 1915 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1916 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1917 in
adamc@751 1918 (#1 fitem1 @ #1 fitem2,
adamc@751 1919 (EApp (e, sqlexp), loc))
adamc@751 1920 end)
adamc@751 1921 | fitem FULL OUTER JOIN fitem ON sqlexp (let
adamc@751 1922 val loc = s (fitem1left, sqlexpright)
adamc@751 1923
adamc@751 1924 val e = (EVar (["Basis"], "sql_full_join", Infer), loc)
adamc@751 1925 val e = (EApp (e, #2 fitem1), loc)
adamc@751 1926 val e = (EApp (e, #2 fitem2), loc)
adamc@751 1927 in
adamc@751 1928 (#1 fitem1 @ #1 fitem2,
adamc@751 1929 (EApp (e, sqlexp), loc))
adamc@751 1930 end)
adamc@1192 1931 | LPAREN query RPAREN AS tname (let
adamc@1192 1932 val loc = s (LPARENleft, RPARENright)
adamc@1192 1933
adamc@1192 1934 val e = (EVar (["Basis"], "sql_from_query", Infer), loc)
adamc@1192 1935 val e = (ECApp (e, tname), loc)
adamc@1192 1936 in
adamc@1192 1937 ([tname], (EApp (e, query), loc))
adamc@1192 1938 end)
adam@2006 1939 | LPAREN fitem RPAREN (fitem)
adamc@749 1940
adamc@204 1941 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@204 1942 | LBRACE cexp RBRACE (cexp)
adamc@204 1943
adamc@243 1944 table : SYMBOL ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)),
adamc@403 1945 (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@403 1946 | SYMBOL AS tname (tname, (EVar ([], SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)))
adamc@221 1947 | LBRACE LBRACE eexp RBRACE RBRACE AS tname (tname, eexp)
adamc@207 1948
adamc@748 1949 table' : table (let
adamc@748 1950 val loc = s (tableleft, tableright)
adamc@748 1951 val e = (EVar (["Basis"], "sql_from_table", Infer), loc)
adamc@748 1952 val e = (ECApp (e, #1 table), loc)
adamc@748 1953 in
adamc@748 1954 (#1 table, (EApp (e, #2 table), loc))
adamc@748 1955 end)
adamc@748 1956
adamc@243 1957 tident : SYMBOL (CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@207 1958 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@221 1959 | LBRACE LBRACE cexp RBRACE RBRACE (cexp)
adamc@207 1960
adamc@207 1961 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@207 1962 | LBRACE cexp RBRACE (cexp)
adamc@207 1963
adamc@207 1964 seli : tident DOT fident (Field (tident, fident))
adamc@1194 1965 | sqlexp (Exp (NONE, sqlexp))
adamc@1194 1966 | sqlexp AS fident (Exp (SOME fident, sqlexp))
adamc@341 1967 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (Fields (tident, cexp))
adam@1627 1968 | tident DOT STAR (StarFields tident)
adamc@207 1969
adamc@207 1970 selis : seli ([seli])
adamc@207 1971 | seli COMMA selis (seli :: selis)
adamc@207 1972
adamc@207 1973 select : STAR (Star)
adamc@207 1974 | selis (Items selis)
adamc@209 1975
adamc@403 1976 sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", Infer),
adamc@209 1977 s (TRUEleft, TRUEright)))
adamc@403 1978 | FALSE (sql_inject (EVar (["Basis"], "False", Infer),
adamc@209 1979 s (FALSEleft, FALSEright)))
adamc@209 1980
adamc@222 1981 | INT (sql_inject (EPrim (Prim.Int INT),
adamc@222 1982 s (INTleft, INTright)))
adamc@222 1983 | FLOAT (sql_inject (EPrim (Prim.Float FLOAT),
adamc@222 1984 s (FLOATleft, FLOATright)))
adamc@229 1985 | STRING (sql_inject (EPrim (Prim.String STRING),
adamc@229 1986 s (STRINGleft, STRINGright)))
adamc@441 1987 | CURRENT_TIMESTAMP (sql_nfunc ("current_timestamp",
adamc@441 1988 s (CURRENT_TIMESTAMPleft, CURRENT_TIMESTAMPright)))
adamc@222 1989
adamc@221 1990 | tident DOT fident (let
adamc@221 1991 val loc = s (tidentleft, fidentright)
adamc@403 1992 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@221 1993 val e = (ECApp (e, tident), loc)
adamc@221 1994 in
adamc@221 1995 (ECApp (e, fident), loc)
adamc@221 1996 end)
adamc@234 1997 | CSYMBOL (let
adamc@234 1998 val loc = s (CSYMBOLleft, CSYMBOLright)
adamc@310 1999 in
adamc@310 2000 if !inDml then
adamc@310 2001 let
adamc@403 2002 val e = (EVar (["Basis"], "sql_field", Infer), loc)
adamc@310 2003 val e = (ECApp (e, (CName "T", loc)), loc)
adamc@310 2004 in
adamc@310 2005 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 2006 end
adamc@310 2007 else
adamc@310 2008 let
adamc@403 2009 val e = (EVar (["Basis"], "sql_exp", Infer), loc)
adamc@310 2010 in
adamc@310 2011 (ECApp (e, (CName CSYMBOL, loc)), loc)
adamc@310 2012 end
adamc@310 2013 end)
adamc@221 2014
adamc@471 2015 | LBRACE eexp RBRACE (eexp)
adamc@470 2016
adamc@559 2017 | sqlexp EQ sqlexp (sql_binary ("eq", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 2018 | sqlexp NE sqlexp (sql_binary ("ne", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 2019 | sqlexp LT sqlexp (sql_binary ("lt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 2020 | sqlexp LE sqlexp (sql_binary ("le", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 2021 | sqlexp GT sqlexp (sql_binary ("gt", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 2022 | sqlexp GE sqlexp (sql_binary ("ge", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 2023
adamc@559 2024 | sqlexp PLUS sqlexp (sql_binary ("plus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 2025 | sqlexp MINUS sqlexp (sql_binary ("minus", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 2026 | sqlexp STAR sqlexp (sql_binary ("times", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 2027 | sqlexp DIVIDE sqlexp (sql_binary ("div", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 2028 | sqlexp MOD sqlexp (sql_binary ("mod", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@219 2029
adamc@220 2030 | sqlexp CAND sqlexp (sql_binary ("and", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@220 2031 | sqlexp OR sqlexp (sql_binary ("or", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
adamc@559 2032
kkallio@1607 2033 | sqlexp LIKE sqlexp (sql_binary ("like", sqlexp1, sqlexp2, s (sqlexp1left, sqlexp2right)))
kkallio@1607 2034
adamc@220 2035 | NOT sqlexp (sql_unary ("not", sqlexp, s (NOTleft, sqlexpright)))
adamc@559 2036 | MINUS sqlexp (sql_unary ("neg", sqlexp, s (MINUSleft, sqlexpright)))
adamc@220 2037
adamc@470 2038 | sqlexp IS NULL (let
adamc@470 2039 val loc = s (sqlexpleft, NULLright)
adamc@470 2040 in
adamc@470 2041 (EApp ((EVar (["Basis"], "sql_is_null", Infer), loc),
adamc@470 2042 sqlexp), loc)
adamc@470 2043 end)
adamc@470 2044
kkallio@1572 2045 | CIF sqlexp CTHEN sqlexp CELSE sqlexp (let
kkallio@1572 2046 val loc = s (CIFleft, sqlexp3right)
kkallio@1572 2047 val e = (EVar (["Basis"], "sql_if_then_else", Infer), loc)
kkallio@1572 2048 in
kkallio@1572 2049 (EApp ((EApp ((EApp (e, sqlexp1), loc), sqlexp2), loc), sqlexp3), loc)
kkallio@1572 2050 end)
kkallio@1572 2051
adamc@471 2052 | LBRACE LBRACK eexp RBRACK RBRACE (sql_inject (#1 eexp,
adamc@471 2053 s (LBRACEleft, RBRACEright)))
adamc@220 2054 | LPAREN sqlexp RPAREN (sqlexp)
adamc@210 2055
adamc@467 2056 | NULL (sql_inject ((EVar (["Basis"], "None", Infer),
adamc@467 2057 s (NULLleft, NULLright))))
adamc@467 2058
adam@1778 2059 | COUNT LPAREN STAR RPAREN window(let
adam@1778 2060 val loc = s (COUNTleft, windowright)
adam@1778 2061 in
adam@1778 2062 case window of
adam@1778 2063 NONE => (EVar (["Basis"], "sql_count", Infer), loc)
adam@1778 2064 | SOME _ => applyWindow loc (EVar (["Basis"], "sql_window_count", Infer), loc) window
adam@1778 2065 end)
adam@1778 2066 | COUNT LPAREN sqlexp RPAREN window(let
adam@1778 2067 val loc = s (COUNTleft, RPARENright)
adam@1778 2068 val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
adam@1778 2069 in
adam@1778 2070 case window of
adam@1778 2071 NONE =>
adam@1778 2072 let
adam@1778 2073 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
adam@1778 2074 e), loc)
adam@1778 2075 in
adam@1778 2076 (EApp (e, sqlexp), loc)
adam@1778 2077 end
adam@1778 2078 | SOME _ =>
adam@1778 2079 let
adam@1778 2080 val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
adam@1778 2081 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc),
adam@1778 2082 e), loc)
adam@1778 2083 in
adam@1778 2084 applyWindow loc (EApp (e, sqlexp), loc) window
adam@1778 2085 end
adam@1778 2086 end)
adam@1776 2087 | sqlagg LPAREN sqlexp RPAREN window (let
adam@1778 2088 val loc = s (sqlaggleft, RPARENright)
adam@1778 2089
adam@1776 2090 val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
adam@1776 2091 in
adam@1776 2092 case window of
adam@1776 2093 NONE =>
adam@1776 2094 let
adam@1776 2095 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
adam@1776 2096 e), loc)
adam@1776 2097 in
adam@1776 2098 (EApp (e, sqlexp), loc)
adam@1776 2099 end
adam@1776 2100 | SOME _ =>
adam@1776 2101 let
adam@1776 2102 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc),
adam@1776 2103 e), loc)
adam@1776 2104 in
adam@1778 2105 applyWindow loc (EApp (e, sqlexp), loc) window
adam@1776 2106 end
adam@1776 2107 end)
adam@1778 2108 | RANK UNIT window (let
adam@1778 2109 val loc = s (RANKleft, windowright)
adam@1778 2110 in
adam@1778 2111 applyWindow loc (EVar (["Basis"], "sql_rank", Infer), loc) window
adam@1778 2112 end)
adam@1602 2113 | COALESCE LPAREN sqlexp COMMA sqlexp RPAREN
adam@1602 2114 (let
adam@1602 2115 val loc = s (COALESCEright, sqlexp2right)
adam@1602 2116 val e = (EVar (["Basis"], "sql_coalesce", Infer), loc)
adam@1602 2117 val e = (EApp (e, sqlexp1), loc)
adam@1602 2118 in
adam@1602 2119 (EApp (e, sqlexp2), loc)
adam@1602 2120 end)
adamc@746 2121 | fname LPAREN sqlexp RPAREN (let
adamc@746 2122 val loc = s (fnameleft, RPARENright)
adamc@746 2123
adamc@746 2124 val e = (EVar (["Basis"], "sql_ufunc", Infer), loc)
adamc@746 2125 val e = (EApp (e, fname), loc)
adamc@746 2126 in
adamc@746 2127 (EApp (e, sqlexp), loc)
adamc@746 2128 end)
adamc@1191 2129 | LPAREN query RPAREN (let
adamc@1191 2130 val loc = s (LPARENleft, RPARENright)
adamc@1191 2131
adamc@1191 2132 val e = (EVar (["Basis"], "sql_subquery", Infer), loc)
adamc@1191 2133 in
adamc@1191 2134 (EApp (e, query), loc)
adamc@1191 2135 end)
adamc@746 2136
adam@1776 2137 window : (NONE)
adam@1777 2138 | OVER LPAREN pbopt obopt RPAREN (SOME (pbopt, obopt))
adam@1777 2139
adam@1777 2140 pbopt : ((EVar (["Basis"], "sql_no_partition", Infer), dummy))
adam@1777 2141 | PARTITION BY sqlexp (let
adam@1777 2142 val loc = s (PARTITIONleft, sqlexpright)
adam@1777 2143
adam@1777 2144 val e = (EVar (["Basis"], "sql_partition", Infer), loc)
adam@1777 2145 in
adam@1777 2146 (EApp (e, sqlexp), loc)
adam@1777 2147 end)
adam@1776 2148
adamc@746 2149 fname : SYMBOL (EVar (["Basis"], "sql_" ^ SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
adamc@746 2150 | LBRACE eexp RBRACE (eexp)
adamc@235 2151
adamc@403 2152 wopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 2153 dummy))
adamc@209 2154 | CWHERE sqlexp (sqlexp)
adamc@226 2155
adamc@226 2156 groupi : tident DOT fident (GField (tident, fident))
adam@1425 2157 | tident DOT LBRACE LBRACE cexp RBRACE RBRACE (GFields (tident, cexp))
adamc@226 2158
adamc@226 2159 groupis: groupi ([groupi])
adamc@226 2160 | groupi COMMA groupis (groupi :: groupis)
adamc@226 2161
adamc@226 2162 gopt : (NONE)
adamc@226 2163 | GROUP BY groupis (SOME groupis)
adamc@227 2164
adamc@403 2165 hopt : (sql_inject (EVar (["Basis"], "True", Infer),
adamc@230 2166 dummy))
adamc@227 2167 | HAVING sqlexp (sqlexp)
adamc@230 2168
adamc@403 2169 obopt : (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
adamc@234 2170 (CWild (KRecord (KType, dummy), dummy), dummy)),
adamc@230 2171 dummy)
adamc@230 2172 | ORDER BY obexps (obexps)
adamc@230 2173
adamc@268 2174 obitem : sqlexp diropt (sqlexp, diropt)
adamc@268 2175
adamc@268 2176 obexps : obitem (let
adamc@268 2177 val loc = s (obitemleft, obitemright)
adamc@230 2178
adamc@403 2179 val e' = (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), loc),
adamc@234 2180 (CWild (KRecord (KType, loc), loc), loc)),
adamc@230 2181 loc)
adamc@403 2182 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 2183 #1 obitem), loc)
adamc@268 2184 val e = (EApp (e, #2 obitem), loc)
adamc@230 2185 in
adamc@230 2186 (EApp (e, e'), loc)
adamc@230 2187 end)
adamc@268 2188 | obitem COMMA obexps (let
adamc@268 2189 val loc = s (obitemleft, obexpsright)
adamc@230 2190
adamc@403 2191 val e = (EApp ((EVar (["Basis"], "sql_order_by_Cons", Infer), loc),
adamc@268 2192 #1 obitem), loc)
adamc@268 2193 val e = (EApp (e, #2 obitem), loc)
adamc@230 2194 in
adamc@230 2195 (EApp (e, obexps), loc)
adamc@230 2196 end)
adam@1682 2197 | RANDOM popt (EVar (["Basis"], "sql_order_by_random", Infer), s (RANDOMleft, poptright))
adam@1682 2198
adam@1682 2199 popt : ()
adam@1682 2200 | LPAREN RPAREN ()
adam@1684 2201 | UNIT ()
adamc@231 2202
adamc@403 2203 diropt : (EVar (["Basis"], "sql_asc", Infer), dummy)
adamc@403 2204 | ASC (EVar (["Basis"], "sql_asc", Infer), s (ASCleft, ASCright))
adamc@403 2205 | DESC (EVar (["Basis"], "sql_desc", Infer), s (DESCleft, DESCright))
adam@1543 2206 | LBRACE eexp RBRACE (eexp)
adamc@268 2207
adamc@403 2208 lopt : (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@403 2209 | LIMIT ALL (EVar (["Basis"], "sql_no_limit", Infer), dummy)
adamc@231 2210 | LIMIT sqlint (let
adamc@231 2211 val loc = s (LIMITleft, sqlintright)
adamc@231 2212 in
adamc@403 2213 (EApp ((EVar (["Basis"], "sql_limit", Infer), loc), sqlint), loc)
adamc@231 2214 end)
adamc@231 2215
adamc@403 2216 ofopt : (EVar (["Basis"], "sql_no_offset", Infer), dummy)
adamc@232 2217 | OFFSET sqlint (let
adamc@232 2218 val loc = s (OFFSETleft, sqlintright)
adamc@232 2219 in
adamc@403 2220 (EApp ((EVar (["Basis"], "sql_offset", Infer), loc), sqlint), loc)
adamc@232 2221 end)
adamc@232 2222
adamc@231 2223 sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@231 2224 | LBRACE eexp RBRACE (eexp)
adamc@236 2225
adamc@236 2226 sqlagg : AVG ("avg")
adamc@236 2227 | SUM ("sum")
adamc@236 2228 | MIN ("min")
adamc@236 2229 | MAX ("max")