SCM Repository
Annotation of /branches/vis12/src/compiler/parser/parser.sml
Parent Directory
|
Revision Log
Revision 1116 -
(view)
(download)
Original Path: trunk/src/compiler/parser/parser.sml
1 : | jhr | 14 | (* parser.sml |
2 : | * | ||
3 : | jhr | 435 | * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu) |
4 : | jhr | 14 | * 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 : | jhr | 1116 | (* map tokens to strings *) |
23 : | fun tokToString (DiderotTokens.ID x) = Atom.toString x | ||
24 : | | tokToString (DiderotTokens.STRING s) = concat["\"", String.toCString s, "\""] | ||
25 : | | tokToString (DiderotTokens.FLOAT f) = FloatLit.toString f | ||
26 : | | tokToString (DiderotTokens.INT i) = IntInf.toString i | ||
27 : | | tokToString tok = DiderotTokens.toString tok | ||
28 : | |||
29 : | jhr | 14 | (* error function for parsers *) |
30 : | jhr | 1116 | val parseErr = Error.parseError tokToString |
31 : | jhr | 14 | |
32 : | (* parse a file, returning a parse tree *) | ||
33 : | fun parseFile (errStrm, file) = let | ||
34 : | fun get () = TextIO.input file | ||
35 : | val lexer = DiderotLex.lex (Error.sourceMap errStrm) (lexErr errStrm) | ||
36 : | in | ||
37 : | case DiderotParser.parse lexer (DiderotLex.streamify get) | ||
38 : | of (SOME pt, _, []) => (TextIO.closeIn file; SOME pt) | ||
39 : | | (_, _, errs) => ( | ||
40 : | TextIO.closeIn file; | ||
41 : | List.app (parseErr errStrm) errs; | ||
42 : | NONE) | ||
43 : | (* end case *) | ||
44 : | end | ||
45 : | |||
46 : | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |