CVS: sml-dist/src/ml-flex/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/ml-flex/src/BackEnds
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27912/src/ml-flex/src/BackEnds
Added Files:
expand-file.sml lex-output-spec.sml output-sig.sml
Log Message:
sources for ml-flex added; integration partially done
--- 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 *))
(* 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, (* rule vector indices *)
next : (RegExp.sym_set * dfa_state) list ref
}
(* a "machine" corresponds to a start state: each
* start state will end up with its own DFA
*)
datatype machine = Machine of {
label : string,
(* re * action vector index *)
rules : (RegExp.re * int) vector,
states : dfa_state list
}
type action = string
datatype spec = Spec of {
decls : string,
header : string,
arg : string,
actions : action vector,
machines : machine 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