diff src/compiler.sml @ 1151:de48dc2c9ee8

Allow .urp files without initial blank lines
author Adam Chlipala <adamc@hcoop.net>
date Sat, 06 Feb 2010 15:34:41 -0500
parents 7fdea74b1dd9
children 76f607cefdb1
line wrap: on
line diff
--- a/src/compiler.sml	Sat Feb 06 13:53:26 2010 -0500
+++ b/src/compiler.sml	Sat Feb 06 15:34:41 2010 -0500
@@ -282,7 +282,25 @@
         fun pu filename =
             let
                 val dir = OS.Path.dir filename
-                val inf = TextIO.openIn (OS.Path.joinBaseExt {base = filename, ext = SOME "urp"})
+                fun opener () = TextIO.openIn (OS.Path.joinBaseExt {base = filename, ext = SOME "urp"})
+
+                val inf = opener ()
+
+                fun hasAnyLine () =
+                    case TextIO.inputLine inf of
+                        NONE => false
+                      | SOME "\n" => false
+                      | _ => true
+
+                fun hasBlankLine () =
+                    case TextIO.inputLine inf of
+                        NONE => false
+                      | SOME "\n" => hasAnyLine ()
+                      | _ => hasBlankLine ()
+
+                val hasBlankLine = hasBlankLine ()
+
+                val inf = (TextIO.closeIn inf; opener ())
 
                 fun pathify fname =
                     if size fname > 0 andalso String.sub (fname, 0) = #"$" then
@@ -591,7 +609,10 @@
                             read ()
                         end
 
-                val job = read ()
+                val job = if hasBlankLine then
+                              read ()
+                          else
+                              finish (readSources [])
             in
                 TextIO.closeIn inf;
                 Settings.setUrlPrefix (#prefix job);