Template language overhaul & misc. improvements
[bpt/mlt.git] / src / compiler.sml
index 6ef2807..e87cb57 100644 (file)
@@ -90,6 +90,7 @@ struct
                    str (toUpper (String.sub (name, 0))) ^ String.extract (name, 1, NONE)
                else
                    raise Error
+           val name = name ^ "_"
        in
            (name, Mlt.trans (config, env, templates, name, Parse.parse path))
        end
@@ -110,9 +111,9 @@ struct
                          "mlt" => loop (smls, (path ^ "/" ^ fname) :: mlts)
                        | ("sml"|"sig") =>
                          let
-                             val mltName = removeExt fname ^ ".mlt"
+                             val fname = getFname fname
                          in
-                             if getFname fname = "_main.sml" orelse Posix.FileSys.access (mltName, []) then
+                             if String.sub (fname, 0) = #"_" then
                                  loop (smls, mlts)
                              else
                                  loop ((path ^ "/" ^ fname) :: smls, mlts)
@@ -133,6 +134,7 @@ struct
            val _ = TextIO.closeOut outf
            
            val outf = TextIO.openOut (outPath ^ "/.build.sml")
+           val _ = TextIO.output (outf, "Control.quotation := true;\n")
            fun printMlts [] = ()
              | printMlts (h::t) =
                (TextIO.output (outf, "\"" ^ h ^ "\"");
@@ -140,7 +142,7 @@ struct
 
            val libList = foldl (fn (l, s) => s ^ "if CM.make \"" ^ l ^ "\" then () else OS.Process.exit OS.Process.failure;\n") "" (Config.cm config)
        in
-           TextIO.output (outf, "if CM.make \"" ^ outPath ^ "/libs.cm\" then () else OS.Process.exit OS.Process.failure;\nif CM.make \"" ^ Config.compiler config ^ "\" then () else OS.Process.exit OS.Process.failure;\n");
+           TextIO.output (outf, "if CM.make \"" ^ outPath ^ "/libs.cm\" then () else OS.Process.exit OS.Process.failure;\nif CM.make \"" ^ Config.compiler config ^ "\" then () else OS.Process.exit OS.Process.failure;\nif CM.make \"" ^ Config.lib config ^ "\" then () else OS.Process.exit OS.Process.failure;\n");
            TextIO.output (outf, libList);
            TextIO.output (outf, "Compiler.compileTemplates (Config.read \"mlt.conf\" (Config.default ())) ([");
            printMlts mlts;
@@ -153,6 +155,7 @@ struct
        
     fun compileTemplates config (mlts, smls) =
        let
+           val err_flag = ref false
            val _ = ErrorMsg.reset ()
 
            val path = Config.inPath config
@@ -180,8 +183,9 @@ struct
                let
                    val _ = print ("Compiling " ^ fname ^ "....\n")
                    val (name, output) = compileTemplate (config, env, templates) fname
+                   val _ = err_flag := (!err_flag orelse !ErrorMsg.anyErrors)
                    val scriptName = removeExt (getFname fname)
-                   val outName = scriptName ^ ".sml"
+                   val outName = "__" ^ scriptName ^ ".sml"
                    val outf = TextIO.openOut (outPath ^ "/" ^ outName)
                in
                    TextIO.output (outf, output);
@@ -217,7 +221,7 @@ struct
                    Posix.FileSys.chmod (name, cgiMode)
                end
        in
-           if !ErrorMsg.anyErrors then
+           if !err_flag then
                (TextIO.print "Errors compiling templates.\n";
                 OS.Process.failure)
            else