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 3349 - (view) (download)

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

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