annotate src/lacweb.grm @ 191:aa54250f58ac

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