File: html4-test.sml

package info (click to toggle)
smlnj 110.79-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 82,552 kB
  • sloc: ansic: 32,532; asm: 6,314; sh: 2,303; makefile: 1,821; perl: 1,170; pascal: 295; yacc: 190; cs: 78; python: 77; lisp: 19
file content (74 lines) | stat: -rw-r--r-- 2,397 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(* html4-test.sml
 *
 * COPYRIGHT (c) 2014 The Fellowship of SML/NJ (http://www.smlnj.org)
 * All rights reserved.
 *)

structure Test =
  struct

    val parsetreeStreamToString =
	  HTML4Utils.mkParsetreeStreamToString HTML4Tokens.toString

    fun handleFile outS fileName = let
	  val inStream = TextIO.openIn fileName
	  val concrete_pt_opt = HTML4Parser.parseStream inStream
	  val pt_visit_strm = (case concrete_pt_opt
		 of SOME concrete_pt => HTML4Utils.parsetreeToVisitationStream concrete_pt
		  | NONE => HTML4Utils.StreamNil
		(* end case *))
	  val (_, htmlOpt) = HTML4Parser.htmlFromParseStream pt_visit_strm
	      handle HTML4Parser.IllFormedHTMLParseStream (strm, SOME msg) =>
		     (HTML4Parser.printVisitationStream strm;
		      print (msg ^ "\n\n"); (strm, NONE))
	  in
	    TextIO.closeIn inStream;
	    TextIO.output(outS, concat["<!-- ******************** start ", fileName, " ******************** -->\n"]);
	    case htmlOpt
	     of SOME html => HTML4Print.prHTML {
		    putc = fn c => TextIO.output1(outS, c),
		    puts = fn s => TextIO.output(outS, s)
		  } html
	      | NONE => TextIO.output (outS, parsetreeStreamToString pt_visit_strm)
	    (* end case *);
	    TextIO.output(outS, concat["<!-- ******************** end ", fileName, " ******************** -->\n"])
	  end

    fun main (_, args) = let
	  val outS = TextIO.openOut "html4-test.out"
	  in
	    (List.app (handleFile outS) args; TextIO.closeOut outS; OS.Process.success)
	      handle ex => (
		  TextIO.closeOut outS;
		  print(concat["uncaught exception: ", exnMessage ex, "\n"]);
		  List.app (fn s => print(concat["  ", s, "\n"])) (SMLofNJ.exnHistory ex);
		  OS.Process.failure)
	  end

    val tests = [
	    "tests/abbr.html",
	    "tests/dir.html",
	    "tests/edit.html",
	    "tests/elements.html",
	    "tests/entities.html",
	    "tests/forms.html",
	    "tests/framebody.html",
	    "tests/frames.html",
	    "tests/id.html",
	    "tests/objaudio.html",
	    "tests/objects.html",
	    "tests/objvideo.html",
	    "tests/quote.html",
	    "tests/scripts.html",
	    "tests/spchars.html",
	    "tests/tables.html",
	    "tests/template.html",
	    "tests/test001.html",
	    "tests/test002.html"
	  ]

  end

(* ______________________________________________________________________
   End of html4-test.sml
   ______________________________________________________________________ *)