From 0790751d4c2c97d85d6ccd7865271da23dee85e7 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Fri, 17 Mar 2017 15:15:58 -0400 Subject: Better error message for .urp files with too many blank lines --- src/compiler.sml | 26 ++++++++++++++++++++++---- tests/malformed.ur | 3 +++ tests/malformed.urp | 5 +++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 tests/malformed.ur create mode 100644 tests/malformed.urp 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 + FYI, this file isn't the malformed one. That's malformed.urp. + 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 -- cgit v1.2.3