annotate src/lacweb.grm @ 167:2be573fec9a6

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