Updated for SML/NJ 110.46+
[bpt/mlt.git] / src / config.sml
index d021359..45253ac 100644 (file)
@@ -32,7 +32,11 @@ struct
                        sml : string, (* Path to sml program *)
                         printFn : string StringMap.map, (* Map from SML type names to text for functions to print
                                                         * their values *)
-                       cm : string list (* List of extra SML/CM files to use with this project *)}
+                       cm : string list, (* List of extra SML/CM files to use with this project *)
+                       beforeT : string option, (* Template to run before every template execution *)
+                       afterT : string option, (* Template to run after every successful template execution *)
+                       exnT : string option (* Template to run after every template execution
+                                             * ending in an uncaught exception *)}
 
     fun inPath (CONFIG {inPath, ...}) = inPath
     fun outPath (CONFIG {outPath, ...}) = outPath
@@ -40,6 +44,9 @@ struct
     fun lib (CONFIG {lib, ...}) = lib
     fun sml (CONFIG {sml, ...}) = sml
     fun compiler (CONFIG {compiler, ...}) = compiler
+    fun beforeT (CONFIG {beforeT, ...}) = beforeT
+    fun afterT (CONFIG {afterT, ...}) = afterT
+    fun exnT (CONFIG {exnT, ...}) = exnT
     fun cm (CONFIG {cm, ...}) = cm
     fun printFn (CONFIG {printFn, ...}) s = StringMap.find (printFn, s)
 
@@ -53,30 +60,48 @@ struct
        let
            val inf = TextIO.openIn fname
 
-           fun read (fields as {inPath, outPath, pubPath, lib, compiler, cm, sml, printFn}) =
+           fun read (fields as {inPath, outPath, pubPath, lib, compiler, cm, sml, printFn, beforeT, afterT, exnT}) =
                (case TextIO.inputLine inf of
-                    "" => CONFIG fields
-                  | line =>
+                    NONE => CONFIG fields
+                  | SOME line =>
                     (case String.tokens Char.isSpace line of
                          [] => read fields
                        | ["in", inPath] => read {inPath = expandPath inPath, outPath = outPath, pubPath = pubPath,
                                                  lib = lib, compiler = compiler, printFn = printFn,
-                                                 cm = cm, sml = sml}
+                                                 cm = cm, sml = sml,
+                                                 beforeT = beforeT, afterT = afterT, exnT = exnT}
                        | ["out", outPath] => read {inPath = inPath, outPath = expandPath outPath, pubPath = pubPath,
                                                    lib = lib, compiler = compiler, printFn = printFn,
-                                                   cm = cm, sml = sml}
+                                                   cm = cm, sml = sml,
+                                                   beforeT = beforeT, afterT = afterT, exnT = exnT}
                        | ["pub", pubPath] => read {inPath = inPath, outPath = outPath, pubPath = expandPath pubPath,
                                                    lib = lib, compiler = compiler, printFn = printFn,
-                                                   cm = cm, sml = sml}
+                                                   cm = cm, sml = sml,
+                                                   beforeT = beforeT, afterT = afterT, exnT = exnT}
                        | ["lib", lib] => read {inPath = inPath, outPath = outPath, pubPath = pubPath,
                                                lib = lib, compiler = compiler, printFn = printFn,
-                                               cm = cm, sml = sml}
+                                               cm = cm, sml = sml,
+                                               beforeT = beforeT, afterT = afterT, exnT = exnT}
                        | ["compiler", compiler] => read {inPath = inPath, outPath = outPath, pubPath = pubPath,
                                                          lib = lib, compiler = compiler, printFn = printFn,
-                                                         cm = cm, sml = sml}
+                                                         cm = cm, sml = sml,
+                                                         beforeT = beforeT, afterT = afterT, exnT = exnT}
                        | ["sml", sml] => read {inPath = inPath, outPath = outPath, pubPath = pubPath,
                                                lib = lib, compiler = compiler, printFn = printFn,
-                                               cm = cm, sml = sml}
+                                               cm = cm, sml = sml,
+                                               beforeT = beforeT, afterT = afterT, exnT = exnT}
+                       | ["before", beforeT] => read {inPath = inPath, outPath = expandPath outPath, pubPath = pubPath,
+                                                      lib = lib, compiler = compiler, printFn = printFn,
+                                                      cm = cm, sml = sml,
+                                                      beforeT = SOME beforeT, afterT = afterT, exnT = exnT}
+                       | ["after", afterT] => read {inPath = inPath, outPath = outPath, pubPath = expandPath pubPath,
+                                                    lib = lib, compiler = compiler, printFn = printFn,
+                                                    cm = cm, sml = sml,
+                                                    beforeT = beforeT, afterT = SOME afterT, exnT = exnT}
+                       | ["exn", exnT] => read {inPath = inPath, outPath = outPath, pubPath = pubPath,
+                                                lib = lib, compiler = compiler, printFn = printFn,
+                                                cm = cm, sml = sml,
+                                                beforeT = beforeT, afterT = afterT, exnT = SOME exnT}
                        | "print"::rest =>
                          let
                              fun split ([], _) = (print "Bad printFn directive\n";
@@ -90,7 +115,8 @@ struct
                                  in
                                      read {inPath = inPath, outPath = outPath, pubPath = pubPath,
                                            lib = lib, compiler = compiler, printFn = printFn,
-                                           cm = cm, sml = sml}
+                                           cm = cm, sml = sml,
+                                           beforeT = beforeT, afterT = afterT, exnT = exnT}
                                  end
                                | split (h::after, befor) = split (after, h::befor)
                          in
@@ -98,7 +124,8 @@ struct
                          end
                        | ["cm", fname] => read {inPath = inPath, outPath = outPath, pubPath = pubPath,
                                                 lib = lib, compiler = compiler, printFn = printFn,
-                                                cm = fname::cm, sml = sml}
+                                                cm = fname::cm, sml = sml,
+                                                beforeT = beforeT, afterT = afterT, exnT = exnT}
                        | _ => (print "Unknown config directive\n";
                                read fields)))
        in
@@ -111,13 +138,16 @@ struct
            val cwd = OS.FileSys.getDir ()
        
            val base = CONFIG {lib = "/usr/local/share/mlt/src/lib/sources.cm",
-                   compiler = "/usr/local/share/mlt/src/sources.cm",
-                   sml = "/usr/local/sml/bin",
-                   inPath = cwd,
-                   outPath = cwd,
-                   pubPath = cwd,
-                   printFn = StringMap.empty,
-                   cm = []}
+                              compiler = "/usr/local/share/mlt/src/sources.cm",
+                              sml = "/usr/local/sml/bin",
+                              inPath = cwd,
+                              outPath = cwd,
+                              pubPath = cwd,
+                              printFn = StringMap.empty,
+                              cm = [],
+                              beforeT = NONE,
+                              afterT = NONE,
+                              exnT = NONE}
        in
            read defaultFile base
        end