diff options
author | Adam Chlipala <adam@chlipala.net> | 2011-11-20 18:33:21 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2011-11-20 18:33:21 -0500 |
commit | b8899334290e4d07aa1037c7fb4b5de26a609654 (patch) | |
tree | 7b9e45c721946d9cb2253eec7b4452948f646c9f /src | |
parent | e43dd849a122a59fa2c22278ddf9c9a09d1550bd (diff) |
Don't treat comment-only lines as blank, in determining split point of .urp files
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler.sml | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/src/compiler.sml b/src/compiler.sml index 9b43efa0..a296bfbb 100644 --- a/src/compiler.sml +++ b/src/compiler.sml @@ -1,4 +1,4 @@ -(* Copyright (c) 2008-2010, Adam Chlipala +(* Copyright (c) 2008-2011, Adam Chlipala * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -347,20 +347,34 @@ fun institutionalizeJob (job : job) = Settings.setMinHeap (#minHeap job); Settings.setSigFile (#sigFile job)) +datatype commentableLine = + EndOfFile + | OnlyComment + | Content of string + fun inputCommentableLine inf = - Option.map (fn s => - let - val s = #1 (Substring.splitl (fn ch => ch <> #"#") (Substring.full s)) - val s = #1 (Substring.splitr (not o Char.isSpace) s) - in - Substring.string (if Substring.size s > 0 andalso Char.isSpace (Substring.sub (s, Substring.size s - 1)) then - if Substring.size s > 1 andalso Char.isSpace (Substring.sub (s, Substring.size s - 2)) then - Substring.trimr 2 s - else - Substring.trimr 1 s - else - s) - end) (TextIO.inputLine inf) + case TextIO.inputLine inf of + NONE => EndOfFile + | SOME s => + let + val (befor, after) = Substring.splitl (fn ch => ch <> #"#") (Substring.full s) + in + if not (Substring.isEmpty after) + andalso Substring.foldl (fn (ch, b) => b andalso Char.isSpace ch) true befor then + OnlyComment + else + let + val s = #1 (Substring.splitr (not o Char.isSpace) befor) + in + Content (Substring.string (if Substring.size s > 0 andalso Char.isSpace (Substring.sub (s, Substring.size s - 1)) then + if Substring.size s > 1 andalso Char.isSpace (Substring.sub (s, Substring.size s - 2)) then + Substring.trimr 2 s + else + Substring.trimr 1 s + else + s)) + end + end fun parseUrp' accLibs fname = if not (Posix.FileSys.access (fname ^ ".urp", []) orelse Posix.FileSys.access (fname ^ "/lib.urp", [])) @@ -417,9 +431,9 @@ fun parseUrp' accLibs fname = fun hasSpaceLine () = case inputCommentableLine inf of - NONE => false - | SOME s => s = "debug" orelse s = "profile" - orelse CharVector.exists (fn ch => ch = #" " orelse ch = #"\t") s orelse hasSpaceLine () + Content s => s = "debug" orelse s = "profile" + orelse CharVector.exists (fn ch => ch = #" " orelse ch = #"\t") s orelse hasSpaceLine () + | _ => false val hasBlankLine = hasSpaceLine () @@ -467,8 +481,7 @@ fun parseUrp' accLibs fname = fun readSources acc = case inputCommentableLine inf of - NONE => rev acc - | SOME line => + Content line => let val acc = if CharVector.all Char.isSpace line then acc @@ -483,6 +496,7 @@ fun parseUrp' accLibs fname = in readSources acc end + | _ => rev acc val prefix = ref (case Settings.getUrlPrefix () of "/" => NONE | s => SOME s) val database = ref (Settings.getDbstring ()) @@ -639,9 +653,10 @@ fun parseUrp' accLibs fname = fun read () = case inputCommentableLine inf of - NONE => finish [] - | SOME "" => finish (readSources []) - | SOME line => + EndOfFile => finish [] + | OnlyComment => read () + | Content "" => finish (readSources []) + | Content line => let val (cmd, arg) = Substring.splitl (fn x => not (Char.isSpace x)) (Substring.full line) val cmd = Substring.string (trim cmd) |