Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/charisee/src/compiler/gen/opt/rules-parser.sml
ViewVC logotype

Annotation of /branches/charisee/src/compiler/gen/opt/rules-parser.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1484 - (view) (download)
Original Path: trunk/src/compiler/gen/opt/rules-parser.sml

1 : jhr 1484 (* rules-parser.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure RulesParser : sig
8 :    
9 :     val parse : (Error.err_stream * TextIO.instream) -> ParseTree.specification option
10 :    
11 :     end = struct
12 :    
13 :     (* Put together lexer and parser *)
14 :     structure DP = RulesParseFn(RulesLex)
15 :    
16 :     (* error function for lexers *)
17 :     fun lexErr errStrm (pos, msg) = Error.errorAt(errStrm, (pos, pos), msg)
18 :    
19 :     (* map tokens to strings *)
20 :     fun tokToString (RulesTokens.ID x) = Atom.toString x
21 :     | tokToString (RulesTokens.OPER x) = Atom.toString x
22 :     | tokToString tok = RulesTokens.toString tok
23 :    
24 :     (* error function for parsers *)
25 :     val parseErr = Error.parseError tokToString
26 :    
27 :     (* parse a file, returning a parse tree *)
28 :     fun parse (errStrm, inStrm) = let
29 :     fun get () = TextIO.input inStrm
30 :     val lexer = RulesLex.lex (Error.sourceMap errStrm) (lexErr errStrm)
31 :     in
32 :     case DP.parse lexer (RulesLex.streamify get)
33 :     of (SOME pt, _, []) => (TextIO.closeIn inStrm; SOME pt)
34 :     | (_, _, errs) => (
35 :     TextIO.closeIn inStrm;
36 :     List.app (parseErr errStrm) errs;
37 :     NONE)
38 :     (* end case *)
39 :     end
40 :    
41 :     end

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