annotate src/lacweb.grm @ 207:cc68da3801bc

Non-star SELECT
author Adam Chlipala <adamc@hcoop.net>
date Thu, 14 Aug 2008 18:35:08 -0400
parents 241c9a0e3397
children 1487c712eb12
rev   line source
adamc@1 1 (* Copyright (c) 2008, 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@1 15 * THIS SOFTWARE 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@1 28 (* Grammar for Laconic/Web programs *)
adamc@1 29
adamc@4 30 open Source
adamc@1 31
adamc@1 32 val s = ErrorMsg.spanOf
adamc@1 33
adamc@204 34 fun capitalize "" = ""
adamc@204 35 | capitalize s = str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE)
adamc@104 36
adamc@203 37 fun entable t =
adamc@203 38 case #1 t of
adamc@203 39 TRecord c => c
adamc@203 40 | _ => t
adamc@203 41
adamc@207 42 datatype select_item =
adamc@207 43 Field of con * con
adamc@207 44
adamc@207 45 datatype select =
adamc@207 46 Star
adamc@207 47 | Items of select_item list
adamc@207 48
adamc@207 49 fun eqTnames ((c1, _), (c2, _)) =
adamc@207 50 case (c1, c2) of
adamc@207 51 (CVar (ms1, x1), CVar (ms2, x2)) => ms1 = ms2 andalso x1 = x2
adamc@207 52 | (CName x1, CName x2) => x1 = x2
adamc@207 53 | _ => false
adamc@207 54
adamc@207 55 fun amend_select loc (si, tabs) =
adamc@207 56 let
adamc@207 57 val (tx, c) = case si of
adamc@207 58 Field (tx, fx) => (tx, (CRecord ([(fx, (CWild (KType, loc), loc))]), loc))
adamc@207 59
adamc@207 60 val (tabs, found) = ListUtil.foldlMap (fn ((tx', c'), found) =>
adamc@207 61 if eqTnames (tx, tx') then
adamc@207 62 ((tx', (CConcat (c, c'), loc)), true)
adamc@207 63 else
adamc@207 64 ((tx', c'), found))
adamc@207 65 false tabs
adamc@207 66 in
adamc@207 67 if found then
adamc@207 68 ()
adamc@207 69 else
adamc@207 70 ErrorMsg.errorAt loc "Select of field from unbound table";
adamc@207 71
adamc@207 72 tabs
adamc@207 73 end
adamc@207 74
adamc@1 75 %%
adamc@1 76 %header (functor LacwebLrValsFn(structure Token : TOKEN))
adamc@1 77
adamc@1 78 %term
adamc@1 79 EOF
adamc@14 80 | STRING of string | INT of Int64.int | FLOAT of Real64.real
adamc@1 81 | SYMBOL of string | CSYMBOL of string
adamc@1 82 | LPAREN | RPAREN | LBRACK | RBRACK | LBRACE | RBRACE
adamc@156 83 | EQ | COMMA | COLON | DCOLON | TCOLON | DOT | HASH | UNDER | UNDERUNDER | BAR
adamc@174 84 | DIVIDE | GT | DOTDOTDOT
adamc@123 85 | CON | LTYPE | VAL | REC | AND | FOLD | UNIT | KUNIT
adamc@156 86 | DATATYPE | OF
adamc@7 87 | TYPE | NAME
adamc@195 88 | ARROW | LARROW | DARROW | STAR
adamc@149 89 | FN | PLUSPLUS | MINUSMINUS | DOLLAR | TWIDDLE
adamc@88 90 | STRUCTURE | SIGNATURE | STRUCT | SIG | END | FUNCTOR | WHERE | EXTERN
adamc@203 91 | INCLUDE | OPEN | CONSTRAINT | CONSTRAINTS | EXPORT | TABLE
adamc@190 92 | CASE | IF | THEN | ELSE
adamc@1 93
adamc@91 94 | XML_BEGIN of string | XML_END
adamc@91 95 | NOTAGS of string
adamc@91 96 | BEGIN_TAG of string | END_TAG of string
adamc@91 97
adamc@204 98 | SELECT | FROM | AS
adamc@204 99
adamc@30 100 %nonterm
adamc@1 101 file of decl list
adamc@1 102 | decls of decl list
adamc@1 103 | decl of decl
adamc@123 104 | vali of string * con option * exp
adamc@123 105 | valis of (string * con option * exp) list
adamc@1 106
adamc@191 107 | dargs of string list
adamc@156 108 | barOpt of unit
adamc@156 109 | dcons of (string * con option) list
adamc@156 110 | dcon of string * con option
adamc@156 111
adamc@30 112 | sgn of sgn
adamc@42 113 | sgntm of sgn
adamc@30 114 | sgi of sgn_item
adamc@30 115 | sgis of sgn_item list
adamc@30 116
adamc@30 117 | str of str
adamc@30 118
adamc@1 119 | kind of kind
adamc@207 120 | ktuple of kind list
adamc@1 121 | kcolon of explicitness
adamc@1 122
adamc@34 123 | path of string list * string
adamc@156 124 | cpath of string list * string
adamc@34 125 | spath of str
adamc@59 126 | mpath of string list
adamc@34 127
adamc@1 128 | cexp of con
adamc@1 129 | capps of con
adamc@1 130 | cterm of con
adamc@195 131 | ctuple of con list
adamc@207 132 | ctuplev of con list
adamc@1 133 | ident of con
adamc@200 134 | idents of con list
adamc@1 135 | rcon of (con * con) list
adamc@83 136 | rconn of (con * con) list
adamc@1 137 | rcone of (con * con) list
adamc@1 138
adamc@8 139 | eexp of exp
adamc@8 140 | eapps of exp
adamc@8 141 | eterm of exp
adamc@195 142 | etuple of exp list
adamc@12 143 | rexp of (con * exp) list
adamc@91 144 | xml of exp
adamc@91 145 | xmlOne of exp
adamc@141 146 | tag of string * exp
adamc@141 147 | tagHead of string * exp
adamc@8 148
adamc@170 149 | branch of pat * exp
adamc@170 150 | branchs of (pat * exp) list
adamc@170 151 | pat of pat
adamc@170 152 | pterm of pat
adamc@174 153 | rpat of (string * pat) list * bool
adamc@195 154 | ptuple of pat list
adamc@170 155
adamc@104 156 | attrs of (con * exp) list
adamc@104 157 | attr of con * exp
adamc@104 158 | attrv of exp
adamc@104 159
adamc@204 160 | query of exp
adamc@204 161 | tables of (con * exp) list
adamc@204 162 | tname of con
adamc@204 163 | table of con * exp
adamc@207 164 | tident of con
adamc@207 165 | fident of con
adamc@207 166 | seli of select_item
adamc@207 167 | selis of select_item list
adamc@207 168 | select of select
adamc@207 169
adamc@204 170
adamc@1 171 %verbose (* print summary of errors *)
adamc@1 172 %pos int (* positions *)
adamc@1 173 %start file
adamc@1 174 %pure
adamc@1 175 %eop EOF
adamc@1 176 %noshift EOF
adamc@1 177
adamc@1 178 %name Lacweb
adamc@1 179
adamc@195 180 %nonassoc IF THEN ELSE
adamc@1 181 %nonassoc DARROW
adamc@1 182 %nonassoc COLON
adamc@6 183 %nonassoc DCOLON TCOLON
adamc@1 184 %right COMMA
adamc@1 185 %right ARROW LARROW
adamc@149 186 %right PLUSPLUS MINUSMINUS
adamc@195 187 %right STAR
adamc@84 188 %nonassoc TWIDDLE
adamc@1 189 %nonassoc DOLLAR
adamc@1 190 %left DOT
adamc@1 191
adamc@1 192 %%
adamc@1 193
adamc@1 194 file : decls (decls)
adamc@54 195 | SIG sgis ([(DSgn ("?", (SgnConst sgis, s (SIGleft, sgisright))),
adamc@54 196 s (SIGleft, sgisright))])
adamc@1 197
adamc@1 198 decls : ([])
adamc@1 199 | decl decls (decl :: decls)
adamc@1 200
adamc@1 201 decl : CON SYMBOL EQ cexp (DCon (SYMBOL, NONE, cexp), s (CONleft, cexpright))
adamc@1 202 | CON SYMBOL DCOLON kind EQ cexp (DCon (SYMBOL, SOME kind, cexp), s (CONleft, cexpright))
adamc@7 203 | LTYPE SYMBOL EQ cexp (DCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
adamc@7 204 s (LTYPEleft, cexpright))
adamc@191 205 | DATATYPE SYMBOL dargs EQ barOpt dcons(DDatatype (SYMBOL, dargs, dcons), s (DATATYPEleft, dconsright))
adamc@191 206 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
adamc@191 207 (case dargs of
adamc@191 208 [] => (DDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
adamc@191 209 | _ => raise Fail "Arguments specified for imported datatype")
adamc@123 210 | VAL vali (DVal vali, s (VALleft, valiright))
adamc@123 211 | VAL REC valis (DValRec valis, s (VALleft, valisright))
adamc@1 212
adamc@30 213 | SIGNATURE CSYMBOL EQ sgn (DSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))
adamc@30 214 | STRUCTURE CSYMBOL EQ str (DStr (CSYMBOL, NONE, str), s (STRUCTUREleft, strright))
adamc@30 215 | STRUCTURE CSYMBOL COLON sgn EQ str (DStr (CSYMBOL, SOME sgn, str), s (STRUCTUREleft, strright))
adamc@42 216 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN EQ str
adamc@42 217 (DStr (CSYMBOL1, NONE,
adamc@42 218 (StrFun (CSYMBOL2, sgn1, NONE, str), s (FUNCTORleft, strright))),
adamc@42 219 s (FUNCTORleft, strright))
adamc@42 220 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn EQ str
adamc@42 221 (DStr (CSYMBOL1, NONE,
adamc@42 222 (StrFun (CSYMBOL2, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))),
adamc@42 223 s (FUNCTORleft, strright))
adamc@48 224 | EXTERN STRUCTURE CSYMBOL COLON sgn (DFfiStr (CSYMBOL, sgn), s (EXTERNleft, sgnright))
adamc@61 225 | OPEN mpath (case mpath of
adamc@61 226 [] => raise Fail "Impossible mpath parse [1]"
adamc@61 227 | m :: ms => (DOpen (m, ms), s (OPENleft, mpathright)))
adamc@88 228 | OPEN CONSTRAINTS mpath (case mpath of
adamc@88 229 [] => raise Fail "Impossible mpath parse [3]"
adamc@88 230 | m :: ms => (DOpenConstraints (m, ms), s (OPENleft, mpathright)))
adamc@88 231 | CONSTRAINT cterm TWIDDLE cterm (DConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))
adamc@109 232 | EXPORT spath (DExport spath, s (EXPORTleft, spathright))
adamc@203 233 | TABLE SYMBOL COLON cexp (DTable (SYMBOL, entable cexp), s (TABLEleft, cexpright))
adamc@30 234
adamc@191 235 dargs : ([])
adamc@191 236 | SYMBOL dargs (SYMBOL :: dargs)
adamc@191 237
adamc@156 238 barOpt : ()
adamc@156 239 | BAR ()
adamc@156 240
adamc@156 241 dcons : dcon ([dcon])
adamc@156 242 | dcon BAR dcons (dcon :: dcons)
adamc@156 243
adamc@156 244 dcon : CSYMBOL (CSYMBOL, NONE)
adamc@156 245 | CSYMBOL OF cexp (CSYMBOL, SOME cexp)
adamc@156 246
adamc@123 247 vali : SYMBOL EQ eexp (SYMBOL, NONE, eexp)
adamc@123 248 | SYMBOL COLON cexp EQ eexp (SYMBOL, SOME cexp, eexp)
adamc@123 249
adamc@123 250 valis : vali ([vali])
adamc@123 251 | vali AND valis (vali :: valis)
adamc@123 252
adamc@42 253 sgn : sgntm (sgntm)
adamc@40 254 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@40 255 (SgnFun (CSYMBOL, sgn1, sgn2), s (FUNCTORleft, sgn2right))
adamc@30 256
adamc@42 257 sgntm : SIG sgis END (SgnConst sgis, s (SIGleft, ENDright))
adamc@59 258 | mpath (case mpath of
adamc@61 259 [] => raise Fail "Impossible mpath parse [2]"
adamc@59 260 | [x] => SgnVar x
adamc@59 261 | m :: ms => SgnProj (m,
adamc@59 262 List.take (ms, length ms - 1),
adamc@59 263 List.nth (ms, length ms - 1)),
adamc@59 264 s (mpathleft, mpathright))
adamc@42 265 | sgntm WHERE CON SYMBOL EQ cexp (SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
adamc@42 266 | sgntm WHERE LTYPE SYMBOL EQ cexp(SgnWhere (sgntm, SYMBOL, cexp), s (sgntmleft, cexpright))
adamc@42 267 | LPAREN sgn RPAREN (sgn)
adamc@42 268
adamc@30 269 sgi : CON SYMBOL DCOLON kind (SgiConAbs (SYMBOL, kind), s (CONleft, kindright))
adamc@30 270 | LTYPE SYMBOL (SgiConAbs (SYMBOL, (KType, s (LTYPEleft, SYMBOLright))),
adamc@30 271 s (LTYPEleft, SYMBOLright))
adamc@30 272 | CON SYMBOL EQ cexp (SgiCon (SYMBOL, NONE, cexp), s (CONleft, cexpright))
adamc@30 273 | CON SYMBOL DCOLON kind EQ cexp (SgiCon (SYMBOL, SOME kind, cexp), s (CONleft, cexpright))
adamc@30 274 | LTYPE SYMBOL EQ cexp (SgiCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp),
adamc@30 275 s (LTYPEleft, cexpright))
adamc@191 276 | DATATYPE SYMBOL dargs EQ barOpt dcons(SgiDatatype (SYMBOL, dargs, dcons), s (DATATYPEleft, dconsright))
adamc@191 277 | DATATYPE SYMBOL dargs EQ DATATYPE CSYMBOL DOT path
adamc@191 278 (case dargs of
adamc@191 279 [] => (SgiDatatypeImp (SYMBOL, CSYMBOL :: #1 path, #2 path), s (DATATYPEleft, pathright))
adamc@191 280 | _ => raise Fail "Arguments specified for imported datatype")
adamc@30 281 | VAL SYMBOL COLON cexp (SgiVal (SYMBOL, cexp), s (VALleft, cexpright))
adamc@30 282
adamc@30 283 | STRUCTURE CSYMBOL COLON sgn (SgiStr (CSYMBOL, sgn), s (STRUCTUREleft, sgnright))
adamc@59 284 | SIGNATURE CSYMBOL EQ sgn (SgiSgn (CSYMBOL, sgn), s (SIGNATUREleft, sgnright))
adamc@42 285 | FUNCTOR CSYMBOL LPAREN CSYMBOL COLON sgn RPAREN COLON sgn
adamc@42 286 (SgiStr (CSYMBOL1,
adamc@42 287 (SgnFun (CSYMBOL2, sgn1, sgn2), s (FUNCTORleft, sgn2right))),
adamc@42 288 s (FUNCTORleft, sgn2right))
adamc@58 289 | INCLUDE sgn (SgiInclude sgn, s (INCLUDEleft, sgnright))
adamc@88 290 | CONSTRAINT cterm TWIDDLE cterm (SgiConstraint (cterm1, cterm2), s (CONSTRAINTleft, ctermright))
adamc@203 291 | TABLE SYMBOL COLON cexp (SgiTable (SYMBOL, entable cexp), s (TABLEleft, cexpright))
adamc@30 292
adamc@30 293 sgis : ([])
adamc@30 294 | sgi sgis (sgi :: sgis)
adamc@30 295
adamc@30 296 str : STRUCT decls END (StrConst decls, s (STRUCTleft, ENDright))
adamc@34 297 | spath (spath)
adamc@40 298 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN DARROW str
adamc@40 299 (StrFun (CSYMBOL, sgn, NONE, str), s (FUNCTORleft, strright))
adamc@40 300 | FUNCTOR LPAREN CSYMBOL COLON sgn RPAREN COLON sgn DARROW str
adamc@40 301 (StrFun (CSYMBOL, sgn1, SOME sgn2, str), s (FUNCTORleft, strright))
adamc@44 302 | spath LPAREN str RPAREN (StrApp (spath, str), s (spathleft, RPARENright))
adamc@34 303
adamc@34 304 spath : CSYMBOL (StrVar CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@34 305 | spath DOT CSYMBOL (StrProj (spath, CSYMBOL), s (spathleft, CSYMBOLright))
adamc@30 306
adamc@1 307 kind : TYPE (KType, s (TYPEleft, TYPEright))
adamc@1 308 | NAME (KName, s (NAMEleft, NAMEright))
adamc@1 309 | LBRACE kind RBRACE (KRecord kind, s (LBRACEleft, RBRACEright))
adamc@1 310 | kind ARROW kind (KArrow (kind1, kind2), s (kind1left, kind2right))
adamc@1 311 | LPAREN kind RPAREN (#1 kind, s (LPARENleft, RPARENright))
adamc@82 312 | KUNIT (KUnit, s (KUNITleft, KUNITright))
adamc@18 313 | UNDERUNDER (KWild, s (UNDERUNDERleft, UNDERUNDERright))
adamc@207 314 | LPAREN ktuple RPAREN (KTuple ktuple, s (LPARENleft, RPARENright))
adamc@207 315
adamc@207 316 ktuple : kind STAR kind ([kind1, kind2])
adamc@207 317 | kind STAR ktuple (kind :: ktuple)
adamc@1 318
adamc@1 319 capps : cterm (cterm)
adamc@1 320 | capps cterm (CApp (capps, cterm), s (cappsleft, ctermright))
adamc@1 321
adamc@1 322 cexp : capps (capps)
adamc@1 323 | cexp ARROW cexp (TFun (cexp1, cexp2), s (cexp1left, cexp2right))
adamc@15 324 | SYMBOL kcolon kind ARROW cexp (TCFun (kcolon, SYMBOL, kind, cexp), s (SYMBOLleft, cexpright))
adamc@1 325
adamc@1 326 | cexp PLUSPLUS cexp (CConcat (cexp1, cexp2), s (cexp1left, cexp1right))
adamc@1 327
adamc@67 328 | FN SYMBOL DARROW cexp (CAbs (SYMBOL, NONE, cexp), s (FNleft, cexpright))
adamc@67 329 | FN SYMBOL DCOLON kind DARROW cexp (CAbs (SYMBOL, SOME kind, cexp), s (FNleft, cexpright))
adamc@84 330 | cterm TWIDDLE cterm DARROW cexp(CDisjoint (cterm1, cterm2, cexp), s (cterm1left, cexpright))
adamc@85 331 | cterm TWIDDLE cterm ARROW cexp (TDisjoint (cterm1, cterm2, cexp), s (cterm1left, cexpright))
adamc@1 332
adamc@8 333 | LPAREN cexp RPAREN DCOLON kind (CAnnot (cexp, kind), s (LPARENleft, kindright))
adamc@6 334
adamc@18 335 | UNDER DCOLON kind (CWild kind, s (UNDERleft, UNDERright))
adamc@195 336 | ctuple (let
adamc@195 337 val loc = s (ctupleleft, ctupleright)
adamc@195 338 in
adamc@195 339 (TRecord (CRecord (ListUtil.mapi (fn (i, c) =>
adamc@195 340 ((CName (Int.toString (i + 1)), loc),
adamc@195 341 c)) ctuple),
adamc@195 342 loc), loc)
adamc@195 343 end)
adamc@18 344
adamc@1 345 kcolon : DCOLON (Explicit)
adamc@1 346 | TCOLON (Implicit)
adamc@1 347
adamc@34 348 path : SYMBOL ([], SYMBOL)
adamc@34 349 | CSYMBOL DOT path (let val (ms, x) = path in (CSYMBOL :: ms, x) end)
adamc@34 350
adamc@156 351 cpath : CSYMBOL ([], CSYMBOL)
adamc@156 352 | CSYMBOL DOT cpath (let val (ms, x) = cpath in (CSYMBOL :: ms, x) end)
adamc@156 353
adamc@59 354 mpath : CSYMBOL ([CSYMBOL])
adamc@59 355 | CSYMBOL DOT mpath (CSYMBOL :: mpath)
adamc@59 356
adamc@1 357 cterm : LPAREN cexp RPAREN (#1 cexp, s (LPARENleft, RPARENright))
adamc@1 358 | LBRACK rcon RBRACK (CRecord rcon, s (LBRACKleft, RBRACKright))
adamc@83 359 | LBRACK rconn RBRACK (CRecord rconn, s (LBRACKleft, RBRACKright))
adamc@1 360 | LBRACE rcone RBRACE (TRecord (CRecord rcone, s (LBRACEleft, RBRACEright)),
adamc@1 361 s (LBRACEleft, RBRACEright))
adamc@1 362 | DOLLAR cterm (TRecord cterm, s (DOLLARleft, ctermright))
adamc@1 363 | HASH CSYMBOL (CName CSYMBOL, s (HASHleft, CSYMBOLright))
adamc@195 364 | HASH INT (CName (Int64.toString INT), s (HASHleft, INTright))
adamc@1 365
adamc@34 366 | path (CVar path, s (pathleft, pathright))
adamc@207 367 | path DOT INT (CProj ((CVar path, s (pathleft, pathright)), Int64.toInt INT),
adamc@207 368 s (pathleft, INTright))
adamc@18 369 | UNDER (CWild (KWild, s (UNDERleft, UNDERright)), s (UNDERleft, UNDERright))
adamc@67 370 | FOLD (CFold, s (FOLDleft, FOLDright))
adamc@82 371 | UNIT (CUnit, s (UNITleft, UNITright))
adamc@207 372 | LPAREN ctuplev RPAREN (CTuple ctuplev, s (LPARENleft, RPARENright))
adamc@207 373
adamc@207 374 ctuplev: cexp COMMA cexp ([cexp1, cexp2])
adamc@207 375 | cexp COMMA ctuplev (cexp :: ctuplev)
adamc@1 376
adamc@196 377 ctuple : capps STAR capps ([capps1, capps2])
adamc@196 378 | capps STAR ctuple (capps :: ctuple)
adamc@195 379
adamc@1 380 rcon : ([])
adamc@1 381 | ident EQ cexp ([(ident, cexp)])
adamc@1 382 | ident EQ cexp COMMA rcon ((ident, cexp) :: rcon)
adamc@1 383
adamc@83 384 rconn : ident ([(ident, (CUnit, s (identleft, identright)))])
adamc@83 385 | ident COMMA rconn ((ident, (CUnit, s (identleft, identright))) :: rconn)
adamc@83 386
adamc@1 387 rcone : ([])
adamc@1 388 | ident COLON cexp ([(ident, cexp)])
adamc@1 389 | ident COLON cexp COMMA rcone ((ident, cexp) :: rcone)
adamc@1 390
adamc@1 391 ident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@195 392 | INT (CName (Int64.toString INT), s (INTleft, INTright))
adamc@200 393 | SYMBOL (CVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright))
adamc@8 394
adamc@8 395 eapps : eterm (eterm)
adamc@8 396 | eapps eterm (EApp (eapps, eterm), s (eappsleft, etermright))
adamc@8 397 | eapps LBRACK cexp RBRACK (ECApp (eapps, cexp), s (eappsleft, RBRACKright))
adamc@8 398
adamc@8 399 eexp : eapps (eapps)
adamc@8 400 | FN SYMBOL kcolon kind DARROW eexp (ECAbs (kcolon, SYMBOL, kind, eexp), s (FNleft, eexpright))
adamc@8 401 | FN SYMBOL COLON cexp DARROW eexp (EAbs (SYMBOL, SOME cexp, eexp), s (FNleft, eexpright))
adamc@8 402 | FN SYMBOL DARROW eexp (EAbs (SYMBOL, NONE, eexp), s (FNleft, eexpright))
adamc@93 403 | LBRACK cterm TWIDDLE cterm RBRACK DARROW eexp(EDisjoint (cterm1, cterm2, eexp), s (LBRACKleft, RBRACKright))
adamc@93 404 | FN UNIT DARROW eexp (let
adamc@93 405 val loc = s (FNleft, eexpright)
adamc@93 406 in
adamc@93 407 (EAbs ("_", SOME (TRecord (CRecord [], loc), loc), eexp), loc)
adamc@93 408 end)
adamc@8 409
adamc@196 410 | eexp COLON cexp (EAnnot (eexp, cexp), s (eexpleft, cexpright))
adamc@149 411 | eexp MINUSMINUS cexp (ECut (eexp, cexp), s (eexpleft, cexpright))
adamc@170 412 | CASE eexp OF barOpt branch branchs (ECase (eexp, branch :: branchs), s (CASEleft, branchsright))
adamc@190 413 | IF eexp THEN eexp ELSE eexp (let
adamc@190 414 val loc = s (IFleft, eexp3right)
adamc@190 415 in
adamc@190 416 (ECase (eexp1, [((PCon (["Basis"], "True", NONE), loc), eexp2),
adamc@190 417 ((PCon (["Basis"], "False", NONE), loc), eexp3)]), loc)
adamc@190 418 end)
adamc@8 419
adamc@8 420 eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright))
adamc@195 421 | LPAREN etuple RPAREN (let
adamc@195 422 val loc = s (LPARENleft, RPARENright)
adamc@195 423 in
adamc@195 424 (ERecord (ListUtil.mapi (fn (i, e) =>
adamc@195 425 ((CName (Int.toString (i + 1)), loc),
adamc@195 426 e)) etuple), loc)
adamc@195 427 end)
adamc@8 428
adamc@34 429 | path (EVar path, s (pathleft, pathright))
adamc@156 430 | cpath (EVar cpath, s (cpathleft, cpathright))
adamc@12 431 | LBRACE rexp RBRACE (ERecord rexp, s (LBRACEleft, RBRACEright))
adamc@110 432 | UNIT (ERecord [], s (UNITleft, UNITright))
adamc@12 433
adamc@14 434 | INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@14 435 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@14 436 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@14 437
adamc@200 438 | path DOT idents (let
adamc@200 439 val loc = s (pathleft, identsright)
adamc@200 440 in
adamc@200 441 foldl (fn (ident, e) =>
adamc@200 442 (EField (e, ident), loc))
adamc@200 443 (EVar path, s (pathleft, pathright)) idents
adamc@200 444 end)
adamc@71 445 | FOLD (EFold, s (FOLDleft, FOLDright))
adamc@71 446
adamc@91 447 | XML_BEGIN xml XML_END (xml)
adamc@91 448 | XML_BEGIN XML_END (EApp ((EVar (["Basis"], "cdata"), s (XML_BEGINleft, XML_ENDright)),
adamc@91 449 (EPrim (Prim.String ""), s (XML_BEGINleft, XML_ENDright))),
adamc@91 450 s (XML_BEGINleft, XML_ENDright))
adamc@204 451 | LPAREN query RPAREN (query)
adamc@91 452
adamc@200 453 idents : ident ([ident])
adamc@200 454 | ident DOT idents (ident :: idents)
adamc@200 455
adamc@195 456 etuple : eexp COMMA eexp ([eexp1, eexp2])
adamc@195 457 | eexp COMMA etuple (eexp :: etuple)
adamc@195 458
adamc@170 459 branch : pat DARROW eexp (pat, eexp)
adamc@170 460
adamc@170 461 branchs: ([])
adamc@170 462 | BAR branch branchs (branch :: branchs)
adamc@170 463
adamc@170 464 pat : pterm (pterm)
adamc@170 465 | cpath pterm (PCon (#1 cpath, #2 cpath, SOME pterm), s (cpathleft, ptermright))
adamc@170 466
adamc@170 467 pterm : SYMBOL (PVar SYMBOL, s (SYMBOLleft, SYMBOLright))
adamc@170 468 | cpath (PCon (#1 cpath, #2 cpath, NONE), s (cpathleft, cpathright))
adamc@170 469 | UNDER (PWild, s (UNDERleft, UNDERright))
adamc@173 470 | INT (PPrim (Prim.Int INT), s (INTleft, INTright))
adamc@173 471 | STRING (PPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@170 472 | LPAREN pat RPAREN (pat)
adamc@174 473 | LBRACE RBRACE (PRecord ([], false), s (LBRACEleft, RBRACEright))
adamc@174 474 | UNIT (PRecord ([], false), s (UNITleft, UNITright))
adamc@174 475 | LBRACE rpat RBRACE (PRecord rpat, s (LBRACEleft, RBRACEright))
adamc@195 476 | LPAREN ptuple RPAREN (PRecord (ListUtil.mapi (fn (i, p) => (Int.toString (i + 1), p)) ptuple,
adamc@195 477 false),
adamc@195 478 s (LPARENleft, RPARENright))
adamc@174 479
adamc@175 480 rpat : CSYMBOL EQ pat ([(CSYMBOL, pat)], false)
adamc@174 481 | DOTDOTDOT ([], true)
adamc@175 482 | CSYMBOL EQ pat COMMA rpat ((CSYMBOL, pat) :: #1 rpat, #2 rpat)
adamc@170 483
adamc@195 484 ptuple : pat COMMA pat ([pat1, pat2])
adamc@195 485 | pat COMMA ptuple (pat :: ptuple)
adamc@195 486
adamc@12 487 rexp : ([])
adamc@12 488 | ident EQ eexp ([(ident, eexp)])
adamc@12 489 | ident EQ eexp COMMA rexp ((ident, eexp) :: rexp)
adamc@91 490
adamc@141 491 xml : xmlOne xml (let
adamc@141 492 val pos = s (xmlOneleft, xmlright)
adamc@141 493 in
adamc@141 494 (EApp ((EApp (
adamc@141 495 (EVar (["Basis"], "join"), pos),
adamc@91 496 xmlOne), pos),
adamc@141 497 xml), pos)
adamc@141 498 end)
adamc@141 499 | xmlOne (xmlOne)
adamc@91 500
adamc@141 501 xmlOne : NOTAGS (EApp ((EVar (["Basis"], "cdata"), s (NOTAGSleft, NOTAGSright)),
adamc@141 502 (EPrim (Prim.String NOTAGS), s (NOTAGSleft, NOTAGSright))),
adamc@141 503 s (NOTAGSleft, NOTAGSright))
adamc@141 504 | tag DIVIDE GT (let
adamc@141 505 val pos = s (tagleft, GTright)
adamc@141 506 in
adamc@141 507 (EApp (#2 tag,
adamc@141 508 (EApp ((EVar (["Basis"], "cdata"), pos),
adamc@141 509 (EPrim (Prim.String ""), pos)),
adamc@141 510 pos)), pos)
adamc@141 511 end)
adamc@141 512
adamc@141 513 | tag GT xml END_TAG (let
adamc@141 514 val pos = s (tagleft, GTright)
adamc@141 515 in
adamc@141 516 if #1 tag = END_TAG then
adamc@141 517 if END_TAG = "lform" then
adamc@141 518 (EApp ((EVar (["Basis"], "lform"), pos),
adamc@141 519 xml), pos)
adamc@141 520 else
adamc@141 521 (EApp (#2 tag, xml), pos)
adamc@141 522 else
adamc@141 523 (ErrorMsg.errorAt pos "Begin and end tags don't match.";
adamc@141 524 (EFold, pos))
adamc@141 525 end)
adamc@141 526 | LBRACE eexp RBRACE (eexp)
adamc@92 527
adamc@141 528 tag : tagHead attrs (let
adamc@141 529 val pos = s (tagHeadleft, attrsright)
adamc@141 530 in
adamc@141 531 (#1 tagHead,
adamc@141 532 (EApp ((EApp ((EVar (["Basis"], "tag"), pos),
adamc@141 533 (ERecord attrs, pos)), pos),
adamc@141 534 (EApp (#2 tagHead,
adamc@141 535 (ERecord [], pos)), pos)),
adamc@141 536 pos))
adamc@141 537 end)
adamc@141 538
adamc@141 539 tagHead: BEGIN_TAG (let
adamc@141 540 val pos = s (BEGIN_TAGleft, BEGIN_TAGright)
adamc@141 541 in
adamc@141 542 (BEGIN_TAG,
adamc@141 543 (EVar ([], BEGIN_TAG), pos))
adamc@141 544 end)
adamc@141 545 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
adamc@92 546
adamc@104 547 attrs : ([])
adamc@104 548 | attr attrs (attr :: attrs)
adamc@104 549
adamc@204 550 attr : SYMBOL EQ attrv ((CName (capitalize SYMBOL), s (SYMBOLleft, SYMBOLright)), attrv)
adamc@204 551
adamc@104 552 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
adamc@104 553 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
adamc@104 554 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
adamc@110 555 | LBRACE eexp RBRACE (eexp)
adamc@204 556
adamc@207 557 query : SELECT select FROM tables (let
adamc@204 558 val loc = s (SELECTleft, tablesright)
adamc@207 559
adamc@207 560 val sel =
adamc@207 561 case select of
adamc@207 562 Star => map (fn (nm, _) =>
adamc@207 563 (nm, (CTuple [(CWild (KRecord (KType, loc), loc),
adamc@207 564 loc),
adamc@207 565 (CRecord [], loc)],
adamc@207 566 loc))) tables
adamc@207 567 | Items sis =>
adamc@207 568 let
adamc@207 569 val tabs = map (fn (nm, _) => (nm, (CRecord [], loc))) tables
adamc@207 570 val tabs = foldl (amend_select loc) tabs sis
adamc@207 571 in
adamc@207 572 map (fn (nm, c) => (nm,
adamc@207 573 (CTuple [c,
adamc@207 574 (CWild (KRecord (KType, loc), loc),
adamc@207 575 loc)], loc))) tabs
adamc@207 576 end
adamc@207 577
adamc@207 578 val sel = (CRecord sel, loc)
adamc@207 579
adamc@207 580 val e = (EVar (["Basis"], "sql_query"), loc)
adamc@207 581 val e = (ECApp (e, sel), loc)
adamc@207 582 val e = (EApp (e, (ERecord tables, loc)), loc)
adamc@204 583 in
adamc@207 584 e
adamc@204 585 end)
adamc@204 586
adamc@204 587 tables : table ([table])
adamc@204 588 | table COMMA tables (table :: tables)
adamc@204 589
adamc@204 590 tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@204 591 | LBRACE cexp RBRACE (cexp)
adamc@204 592
adamc@207 593 table : SYMBOL ((CName SYMBOL, s (SYMBOLleft, SYMBOLright)),
adamc@204 594 (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright)))
adamc@204 595 | SYMBOL AS tname (tname, (EVar ([], SYMBOL), s (SYMBOLleft, SYMBOLright)))
adamc@204 596 | LBRACE eexp RBRACE AS tname (tname, eexp)
adamc@207 597
adamc@207 598 tident : SYMBOL (CName SYMBOL, s (SYMBOLleft, SYMBOLright))
adamc@207 599 | CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@207 600 | LBRACE cexp RBRACE (cexp)
adamc@207 601
adamc@207 602 fident : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright))
adamc@207 603 | LBRACE cexp RBRACE (cexp)
adamc@207 604
adamc@207 605 seli : tident DOT fident (Field (tident, fident))
adamc@207 606
adamc@207 607 selis : seli ([seli])
adamc@207 608 | seli COMMA selis (seli :: selis)
adamc@207 609
adamc@207 610 select : STAR (Star)
adamc@207 611 | selis (Items selis)