annotate src/urweb.grm @ 2106:18ef1db770f6

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