annotate src/lacweb.grm @ 201:f2cac0dba9bf

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