CVS: sml-dist/src/lexgen/src/BackEnds expand-file.sml,NONE,1.1 lex-output-spec.sml,NONE,1.1 output-sig.sml,NONE,1.1

Matthias Blume <[email protected]>
Newsgroups gmane.comp.lang.sml.smlnj.commits
Message-ID <[email protected]>
Update of /cvsroot/smlnj/sml-dist/src/lexgen/src/BackEnds
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30700/src/lexgen/src/BackEnds

Added Files:
	expand-file.sml lex-output-spec.sml output-sig.sml 
Log Message:
ml-flex -> lexgen

--- NEW FILE: expand-file.sml ---
(* expand-file.sml
 *
 * COPYRIGHT (c) 1999 Bell Labs, Lucent Technologies.
 * (Used with permission)
 *
 * Copy a template file to an output file while expanding placeholders.
 * Placeholders are denoted by @id@ on a line by themselves.
 *)

structure ExpandFile : sig

    type hook = TextIO.outstream -> unit

    val expand : {src : string list, dst : string, hooks : (string * hook) list} -> unit

  end = struct

    structure TIO = TextIO
    structure SS = Substring
(*
    structure RE = RegExpFn (
      structure P = AwkSyntax
      structure E = BackTrackEngine)
    structure M = MatchTree
*)

    type hook = TextIO.outstream -> unit

(*
    val placeholderRE = RE.compileString "[\\t ]*@([a-zA-Z][-a-zA-Z0-9_]* )@[\\t ]*"
    val prefixPlaceholder = RE.prefix placeholderRE SS.getc

    fun findPlaceholder s = (case prefixPlaceholder(SS.full s)
	   of SOME(M.Match(_, [M.Match(SOME{pos, len}, _)]), _) =>
		SOME(SS.string(SS.slice(pos, 0, SOME len)))
	    | _ => NONE
	  (* end case *))
*)

    fun findPlaceholder s = let
          val trim = SS.dropr Char.isSpace (SS.dropl Char.isSpace (SS.full s))
	  val size = SS.size trim
          in if size > 2 andalso
		SS.isPrefix "@" trim andalso
		SS.isSuffix "@" trim then
	       SOME (SS.string (SS.slice (trim, 1, SOME (size - 2))))
	     else
	       NONE
          end

  (* copy from inStrm to outStrm expanding placeholders *)
    fun copy (inStrm, outStrm, hooks) = let
	  fun lp [] = ()
	    | lp (s::ss) = (
	        case findPlaceholder s
		 of NONE => TIO.output (outStrm, s)
		  | (SOME id) => (
		      case (List.find (fn (id', h) => id = id') hooks)
		       of (SOME(_, h)) => h outStrm
			| NONE => raise Fail "bogus placeholder"
		      (* end case *))
	        (* end case *);
		lp(ss))
		
	  in
	    lp(inStrm)
	  end

    exception OpenOut

    fun expand {src, dst, hooks} = (let
	  val dstStrm = TIO.openOut dst
		handle ex => (
		  TIO.output(TIO.stdOut, concat[
		      "Warning: unable to open output file \"",
		      dst, "\"\n"
		    ]);
		  raise OpenOut)
	  fun done () = (TIO.closeOut dstStrm)
	  in
	    copy (src, dstStrm, hooks) handle ex => (done(); raise ex);
	    done()
	  end
	    handle OpenOut => ())

  end

--- NEW FILE: lex-output-spec.sml ---
(* lex-output-spec.sml
 *
 * COPYRIGHT (c) 2005 
 * John Reppy (http://www.cs.uchicago.edu/~jhr)
 * Aaron Turon ([email protected])
 * All rights reserved.
 *
 * Specification produced by LexGen
 *)

structure LexOutputSpec = 
  struct

    datatype dfa_state
      = State of {
	  id : int,
	  label : RegExp.re Vector.vector,
	  final : int list,	(* action vector indices *)
	  next :  (RegExp.sym_set * dfa_state) list ref
	}

    type action = string

    datatype spec = Spec of {
	decls : string,
	header : string,
	arg : string,
	actions : action vector,
	dfa : dfa_state list,
	startStates : (string * dfa_state) list
      }

  end

--- NEW FILE: output-sig.sml ---
(* output-sig.sml
 *
 * COPYRIGHT (c) 2005 
 * John Reppy (http://www.cs.uchicago.edu/~jhr)
 * Aaron Turon ([email protected])
 * All rights reserved.
 *
 * The expected signature for any "output" (backend) module.
 *)

signature OUTPUT = 
  sig

    val output : LexOutputSpec.spec * string -> unit

  end


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.