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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1484 - (download) (annotate)
Sun Sep 4 14:35:20 2011 UTC (9 years ago) by jhr
File size: 1187 byte(s)
  Created a compiler/gen directory to hold code for the generation tools.  Moved
  compiler/IL/gen to compiler/gen/il and created compiler/gen/opt for Charisee's tool.
(* 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