annotate src/urweb.grm @ 2079:e1879ded8095

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