annotate src/urweb.grm @ 2009:799be3911ce3

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