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