annotate src/urweb.grm @ 2077:3cd2bd4b1de0

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