annotate src/lacweb.grm @ 198:ab86aa858e6c

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