SCM Repository
Annotation of /branches/vis12/src/compiler/parser/parser.sml
Parent Directory
|
Revision Log
Revision 110 -
(view)
(download)
Original Path: trunk/src/compiler/parser/parser.sml
1 : | jhr | 14 | (* parser.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | * | ||
6 : | * Parser glue. | ||
7 : | *) | ||
8 : | |||
9 : | structure Parser : sig | ||
10 : | |||
11 : | (* parse a file; return NONE if there are syntax errors *) | ||
12 : | val parseFile : (Error.err_stream * TextIO.instream) -> ParseTree.program option | ||
13 : | |||
14 : | end = struct | ||
15 : | |||
16 : | (* glue together the lexer and parser *) | ||
17 : | structure DiderotParser = DiderotParseFn(DiderotLex) | ||
18 : | |||
19 : | (* error function for lexers *) | ||
20 : | fun lexErr errStrm (pos, msg) = Error.errorAt(errStrm, (pos, pos), msg) | ||
21 : | |||
22 : | (* error function for parsers *) | ||
23 : | val parseErr = Error.parseError DiderotTokens.toString | ||
24 : | |||
25 : | (* parse a file, returning a parse tree *) | ||
26 : | fun parseFile (errStrm, file) = let | ||
27 : | fun get () = TextIO.input file | ||
28 : | val lexer = DiderotLex.lex (Error.sourceMap errStrm) (lexErr errStrm) | ||
29 : | in | ||
30 : | case DiderotParser.parse lexer (DiderotLex.streamify get) | ||
31 : | of (SOME pt, _, []) => (TextIO.closeIn file; SOME pt) | ||
32 : | | (_, _, errs) => ( | ||
33 : | TextIO.closeIn file; | ||
34 : | List.app (parseErr errStrm) errs; | ||
35 : | NONE) | ||
36 : | (* end case *) | ||
37 : | end | ||
38 : | |||
39 : | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |