summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler.sml59
-rw-r--r--tests/comment.ur0
-rw-r--r--tests/comment.urp4
3 files changed, 41 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)
diff --git a/tests/comment.ur b/tests/comment.ur
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/comment.ur
diff --git a/tests/comment.urp b/tests/comment.urp
new file mode 100644
index 00000000..4865c8bd
--- /dev/null
+++ b/tests/comment.urp
@@ -0,0 +1,4 @@
+#library common
+database dbname=comment
+
+comment