annotate src/lacweb.grm @ 203:dd82457fda82

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