annotate src/urweb.grm @ 2243:da7d026d1a94

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