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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2377 - (download) (annotate)
Mon Jun 3 19:41:56 2013 UTC (8 years, 5 months ago) by jhr
File size: 1187 byte(s)
  Create new branch for Charisee's Einstein stuff
(* rules-parser.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure RulesParser : sig

    val parse : (Error.err_stream * TextIO.instream) -> ParseTree.specification option

  end = struct

  (* Put together lexer and parser *)
    structure DP = RulesParseFn(RulesLex)

  (* error function for lexers *)
    fun lexErr errStrm (pos, msg) = Error.errorAt(errStrm, (pos, pos), msg)

  (* map tokens to strings *)
    fun tokToString (RulesTokens.ID x) = Atom.toString x
      | tokToString (RulesTokens.OPER x) = Atom.toString x
      | tokToString tok = RulesTokens.toString tok

  (* error function for parsers *)
    val parseErr = Error.parseError tokToString

  (* parse a file, returning a parse tree *)
    fun parse (errStrm, inStrm) = let
	  fun get () = TextIO.input inStrm
	  val lexer = RulesLex.lex (Error.sourceMap errStrm) (lexErr errStrm)
	  in
	    case DP.parse lexer (RulesLex.streamify get)
	     of (SOME pt, _, []) => (TextIO.closeIn inStrm; SOME pt)
	      | (_, _, errs) => (
		  TextIO.closeIn inStrm;
		  List.app (parseErr errStrm) errs;
		  NONE)
	    (* end case *)
	  end

  end

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