Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /gen/parser.sml
ViewVC logotype

View of /gen/parser.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 243 - (download) (annotate)
Wed Sep 24 08:12:22 2008 UTC (11 years, 3 months ago) by jhr
File size: 1466 byte(s)
  Working on generator tool
(* parser.sml
 *
 * COPYRIGHT (c) 2008 John Reppy (http://cs.uchicago.edu/~jhr)
 * All rights reserved.
 *)

structure Parser : sig

    val parseFile : string -> Extensions.group list

  end = struct

    structure GLSpecParser = GLSpecParseFn(GLSpecLex)

  (* global flag to record the existance of errors *)
    val anyErrors = ref false

  (* the current input file *)
    val sourceFile = ref ""

  (* the current sourcemap *)
    val sourceMap = ref(AntlrStreamPos.mkSourcemap())

  (* print an error message and record the fact that there was an error *)
    fun say l = (
          anyErrors := true;
          TextIO.output(TextIO.stdErr, String.concat l);
          TextIO.output1(TextIO.stdErr, #"\n"))

  (* error function for parsers *)
    fun parseErr (filename, srcMap) = let
          val errToStr = AntlrRepair.repairToString GLSpecTokens.toString srcMap
          in
            fn err => say ["Error [", filename, "] ", errToStr err]
          end

    fun parseFile filename = let
	  val inS = TextIO.openIn filename
	  fun get () = TextIO.input inS
	  val srcMap = AntlrStreamPos.mkSourcemap()
          val _ = sourceMap := srcMap
	  val lexer = GLSpecLex.lex srcMap
	  in
	    case GLSpecParser.parse lexer (GLSpecLex.streamify get)
	     of (SOME pt, _, []) => (TextIO.closeIn inS; pt)
	      | (_, _, errs) => (
                  List.app (parseErr (filename, srcMap)) errs;
		  raise Fail "parse error")
	    (* end case *)
	  end

  end


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