aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@csail.mit.edu>2017-03-17 15:15:58 -0400
committerGravatar Adam Chlipala <adamc@csail.mit.edu>2017-03-17 15:15:58 -0400
commit0790751d4c2c97d85d6ccd7865271da23dee85e7 (patch)
tree011f39ae61f88db524c77b6ccc2a5af7f48d2a65
parent3aba065f1d069e033c6993ceac301adc25d865b3 (diff)
Better error message for .urp files with too many blank lines
-rw-r--r--src/compiler.sml26
-rw-r--r--tests/malformed.ur3
-rw-r--r--tests/malformed.urp5
3 files changed, 30 insertions, 4 deletions
diff --git a/src/compiler.sml b/src/compiler.sml
index 481f04b6..3e08fcc6 100644
--- a/src/compiler.sml
+++ b/src/compiler.sml
@@ -543,9 +543,16 @@ fun parseUrp' accLibs fname =
acc
else
let
- val fname = String.implode (List.filter (fn x => not (Char.isSpace x))
- (String.explode line))
- val fname = relifyA fname
+ fun trim s =
+ let
+ val s = Substring.full s
+ val (_, s) = Substring.splitl Char.isSpace s
+ val (s, _) = Substring.splitr Char.isSpace s
+ in
+ Substring.string s
+ end
+
+ val fname = relifyA (trim line)
in
fname :: acc
end
@@ -1005,6 +1012,8 @@ val parse = {
val defed = ref SS.empty
val fulls = ref SS.empty
+ val caughtOneThatIsn'tAFile = ref false
+
fun parseOne fname =
let
val mname = nameOf fname
@@ -1129,7 +1138,16 @@ val parse = {
in
checkErrors ();
d
- end handle MissingFile fname => (ErrorMsg.error ("Missing source file: " ^ fname);
+ end handle MissingFile fname => (if not (!caughtOneThatIsn'tAFile)
+ andalso CharVector.exists Char.isSpace fname then
+ (caughtOneThatIsn'tAFile := true;
+ ErrorMsg.error ("In .urp files, all configuration directives must come before any blank lines.\n"
+ ^ "However, this .urp file contains at least one suspicious line in a position\n"
+ ^ "where filenames belong (after the first blank line) but containing a space\n"
+ ^ "character."))
+ else
+ ();
+ ErrorMsg.error ("Missing source file: " ^ fname);
(Source.DSequence "", ErrorMsg.dummySpan))
val dsFfi = map parseFfi ffi
diff --git a/tests/malformed.ur b/tests/malformed.ur
new file mode 100644
index 00000000..60e0b9f2
--- /dev/null
+++ b/tests/malformed.ur
@@ -0,0 +1,3 @@
+fun main () : transaction page = return <xml><body>
+ FYI, this file isn't the malformed one. That's <tt>malformed.urp</tt>.
+</body></xml>
diff --git a/tests/malformed.urp b/tests/malformed.urp
new file mode 100644
index 00000000..d065a037
--- /dev/null
+++ b/tests/malformed.urp
@@ -0,0 +1,5 @@
+rewrite url Malformed/*
+
+rewrite style Malformed/*
+
+malformed