comparison src/demo.sml @ 384:2a7e7bd7b29f

Building combined demo app
author Adam Chlipala <adamc@hcoop.net>
date Sun, 19 Oct 2008 15:19:41 -0400
parents 49c95753bf3b
children 1195f6e4d208
comparison
equal deleted inserted replaced
383:49c95753bf3b 384:2a7e7bd7b29f
31 let 31 let
32 val prose = OS.Path.joinDirFile {dir = dirname, 32 val prose = OS.Path.joinDirFile {dir = dirname,
33 file = "prose"} 33 file = "prose"}
34 val inf = TextIO.openIn prose 34 val inf = TextIO.openIn prose
35 35
36 val demo_urp = OS.Path.joinDirFile {dir = dirname,
37 file = "demo.urp"}
38
39 val outDir = OS.Path.concat (dirname, "out") 36 val outDir = OS.Path.concat (dirname, "out")
40 37
41 val () = if OS.FileSys.access (outDir, []) then 38 val () = if OS.FileSys.access (outDir, []) then
42 () 39 ()
43 else 40 else
57 file = "demos.html"} 54 file = "demos.html"}
58 55
59 val demosOut = TextIO.openOut fname 56 val demosOut = TextIO.openOut fname
60 val () = (TextIO.output (demosOut, "<html><body>\n\n"); 57 val () = (TextIO.output (demosOut, "<html><body>\n\n");
61 TextIO.output (demosOut, "<li> <a target=\"staging\" href=\"intro.html\">Intro</a></li>\n\n")) 58 TextIO.output (demosOut, "<li> <a target=\"staging\" href=\"intro.html\">Intro</a></li>\n\n"))
59
60 val fname = OS.Path.joinDirFile {dir = dirname,
61 file = "demo.urs"}
62 val ursOut = TextIO.openOut fname
63 val () = (TextIO.output (ursOut, "val main : unit -> transaction page\n");
64 TextIO.closeOut ursOut)
65
66 val fname = OS.Path.joinDirFile {dir = dirname,
67 file = "demo.ur"}
68 val urOut = TextIO.openOut fname
69 val () = TextIO.output (urOut, "fun main () = return <xml><body>\n")
62 70
63 fun mergeWith f (o1, o2) = 71 fun mergeWith f (o1, o2) =
64 case (o1, o2) of 72 case (o1, o2) of
65 (NONE, _) => o2 73 (NONE, _) => o2
66 | (_, NONE) => o1 74 | (_, NONE) => o1
100 val () = (TextIO.output (demosOut, "<li> <a target=\"staging\" href=\""); 108 val () = (TextIO.output (demosOut, "<li> <a target=\"staging\" href=\"");
101 TextIO.output (demosOut, base); 109 TextIO.output (demosOut, base);
102 TextIO.output (demosOut, ".html\">"); 110 TextIO.output (demosOut, ".html\">");
103 TextIO.output (demosOut, name); 111 TextIO.output (demosOut, name);
104 TextIO.output (demosOut, "</a></li>\n")) 112 TextIO.output (demosOut, "</a></li>\n"))
113
114 val () = (TextIO.output (urOut, " <li> <a link={");
115 TextIO.output (urOut, name);
116 TextIO.output (urOut, ".main ()}>");
117 TextIO.output (urOut, name);
118 TextIO.output (urOut, "</a></li>\n"))
105 119
106 val urp_file = OS.Path.joinDirFile {dir = dirname, 120 val urp_file = OS.Path.joinDirFile {dir = dirname,
107 file = urp} 121 file = urp}
108 122
109 val out = OS.Path.joinBaseExt {base = base, 123 val out = OS.Path.joinBaseExt {base = base,
183 let 197 let
184 fun finished () = endUrp out 198 fun finished () = endUrp out
185 199
186 fun readUrp' () = 200 fun readUrp' () =
187 case TextIO.inputLine inf of 201 case TextIO.inputLine inf of
188 NONE => finished () 202 NONE => (finished ();
203 combined)
189 | SOME line => 204 | SOME line =>
190 if String.isSuffix ".urp\n" line then 205 if String.isSuffix ".urp\n" line then
191 let 206 let
192 val urp = String.substring (line, 0, size line - 1) 207 val urp = String.substring (line, 0, size line - 1)
193 val (urpData, out) = startUrp urp 208 val (urpData, out) = startUrp urp
214 let 229 let
215 fun finished () = (TextIO.output (out, "\n</body></html>\n"); 230 fun finished () = (TextIO.output (out, "\n</body></html>\n");
216 TextIO.closeOut out) 231 TextIO.closeOut out)
217 in 232 in
218 case TextIO.inputLine inf of 233 case TextIO.inputLine inf of
219 NONE => finished () 234 NONE => (finished ();
235 NONE)
220 | SOME line => 236 | SOME line =>
221 if String.isSuffix ".urp\n" line then 237 if String.isSuffix ".urp\n" line then
222 let 238 let
223 val urp = String.substring (line, 0, size line - 1) 239 val urp = String.substring (line, 0, size line - 1)
224 val (urpData, out) = startUrp urp 240 val (urpData, out) = startUrp urp
225 in 241 in
226 finished (); 242 finished ();
227 243
228 readUrp (urpData, 244 SOME (readUrp (urpData,
229 out) 245 out))
230 end 246 end
231 else 247 else
232 (TextIO.output (out, line); 248 (TextIO.output (out, line);
233 readIndex ()) 249 readIndex ())
234 end 250 end
272 in 288 in
273 print (">>> " ^ cmd ^ "\n"); 289 print (">>> " ^ cmd ^ "\n");
274 ignore (OS.Process.system cmd) 290 ignore (OS.Process.system cmd)
275 end) 291 end)
276 in 292 in
277 case OS.Path.ext file of 293 if OS.Path.base file = "demo" then
278 SOME "urp" => 294 ()
279 doit (fn (src, html) => 295 else case OS.Path.ext file of
280 let 296 SOME "urp" =>
281 val inf = TextIO.openIn src 297 doit (fn (src, html) =>
282 val out = TextIO.openOut html 298 let
283 299 val inf = TextIO.openIn src
284 fun loop () = 300 val out = TextIO.openOut html
285 case TextIO.inputLine inf of 301
286 NONE => () 302 fun loop () =
287 | SOME line => (TextIO.output (out, line); 303 case TextIO.inputLine inf of
288 loop ()) 304 NONE => ()
289 in 305 | SOME line => (TextIO.output (out, line);
290 TextIO.output (out, "<html><body>\n\n<pre>"); 306 loop ())
291 loop (); 307 in
292 TextIO.output (out, "</pre>\n\n</body></html>"); 308 TextIO.output (out, "<html><body>\n\n<pre>");
293 309 loop ();
294 TextIO.closeIn inf; 310 TextIO.output (out, "</pre>\n\n</body></html>");
295 TextIO.closeOut out 311
296 end) 312 TextIO.closeIn inf;
297 | SOME "urs" => highlight () 313 TextIO.closeOut out
298 | SOME "ur" => highlight () 314 end)
299 | _ => (); 315 | SOME "urs" => highlight ()
316 | SOME "ur" => highlight ()
317 | _ => ();
300 loop () 318 loop ()
301 end 319 end
302 in 320 in
303 loop () 321 loop ()
304 end 322 end
305 in 323 in
306 readIndex (); 324 case readIndex () of
325 NONE => raise Fail "No demo applications!"
326 | SOME combined =>
327 let
328 val () = (TextIO.output (urOut, "</body></xml>\n");
329 TextIO.closeOut urOut)
330
331 val fname = OS.Path.joinDirFile {dir = dirname,
332 file = "demo.urp"}
333 val outf = TextIO.openOut fname
334 in
335 Option.app (fn db => (TextIO.output (outf, "database ");
336 TextIO.output (outf, db);
337 TextIO.output (outf, "\n")))
338 (#database combined);
339 TextIO.output (outf, "sql demo.sql\n");
340 TextIO.output (outf, "\n");
341
342 app (fn s =>
343 let
344 val s = OS.Path.mkAbsolute {relativeTo = OS.FileSys.getDir (),
345 path = s}
346 in
347 TextIO.output (outf, s);
348 TextIO.output (outf, "\n")
349 end)
350 (#sources combined);
351 TextIO.output (outf, "\n");
352 TextIO.output (outf, "demo\n");
353
354 TextIO.closeOut outf;
355
356 Compiler.compile (OS.Path.base fname)
357 end;
307 358
308 TextIO.output (demosOut, "\n</body></html>\n"); 359 TextIO.output (demosOut, "\n</body></html>\n");
309 TextIO.closeOut demosOut; 360 TextIO.closeOut demosOut;
310 361
311 prettyPrint () 362 prettyPrint ()