Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /smlnj-lib/trunk/HTML/html-parser-fn.sml
ViewVC logotype

Annotation of /smlnj-lib/trunk/HTML/html-parser-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download)
Original Path: sml/trunk/src/smlnj-lib/HTML/html-parser-fn.sml

1 : monnier 2 (* html-parser-fn.sml
2 :     *
3 :     * COPYRIGHT (c) 1996 AT&T REsearch.
4 :     *
5 :     * This glues the lexer and parser together.
6 :     *)
7 :    
8 :     functor HTMLParserFn (Err : HTML_ERROR) : sig
9 :    
10 :     val parseFile : string -> HTML.html
11 :    
12 :     end = struct
13 :    
14 :     structure TIO = TextIO
15 :    
16 :     structure HTMLAttrs = HTMLAttrsFn(Err)
17 :     structure HTMLLrVals = HTMLLrValsFn(
18 :     structure Token = LrParser.Token
19 :     structure HTMLAttrs = HTMLAttrs)
20 :     structure Lex = HTMLLexFn(
21 :     structure Err = Err
22 :     structure Tokens = HTMLLrVals.Tokens
23 :     structure HTMLAttrs = HTMLAttrs)
24 :     structure Parser = JoinWithArg(
25 :     structure Lex= Lex
26 :     structure LrParser = LrParser
27 :     structure ParserData = HTMLLrVals.ParserData)
28 :     structure CheckHTML = CheckHTMLFn(Err)
29 :    
30 :     fun parseFile fname = let
31 :     (* build a context to hand to the HTMLAttrs build functions. *)
32 :     fun ctx lnum = {file = SOME fname, line=lnum}
33 :     fun lexError (msg, lnum, _) =
34 :     Err.lexError {file = SOME fname, line = lnum} msg
35 :     fun syntaxError (msg, lnum, _) =
36 :     Err.syntaxError {file = SOME fname, line = lnum} msg
37 :     val inStrm = TIO.openIn fname
38 :     fun close () = TIO.closeIn inStrm
39 :     val lexer = Parser.makeLexer (fn n => TIO.inputN(inStrm, n))
40 :     (lexError, SOME fname)
41 :     val (result, _) = Parser.parse (
42 :     15, (* lookahead *)
43 :     lexer,
44 :     syntaxError,
45 :     ctx)
46 :     in
47 :     CheckHTML.check (ctx 0) result
48 :     handle ex => (close(); raise ex)
49 :     close();
50 :     result
51 :     end
52 :    
53 :     end;

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0