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