format-parser: Improve error message when format specifier lacks width.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 25 Nov 2012 01:26:38 +0000 (17:26 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 25 Nov 2012 01:26:38 +0000 (17:26 -0800)
Until now, parse_format_specifier() was willing to parse, e.g. "datetime"
as a format specifier.  It would then be rejected later by e.g.
fmt_check_input() with a message like "Input format DATETIME0.0 specifies
width 0, but DATETIME requires a width between 17 and 40," which makes no
sense to the user.  This commit improves the error message.

src/language/lexer/format-parser.c
tests/language/expressions/evaluate.at

index 45a0b4b1e32d1c4cb473cfcdc810d3add3c52361..78af09da311e2d2af24f5c9a410e68311f6f769a 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2010, 2011, 2012 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -117,6 +117,13 @@ parse_format_specifier (struct lexer *lexer, struct fmt_spec *format)
       return false;
     }
 
+  if (format->w == 0 && !strchr (lex_tokcstr (lexer), '0'))
+    {
+      msg (SE, _("Format specifier `%s' lacks required width."),
+           lex_tokcstr (lexer));
+      return false;
+    }
+
   lex_get (lexer);
   return true;
 }
index e56a3a457e53c46d4a6905d95c8521c355891556..8fa027e62278a83925491f9becb7234bb1280642 100644 (file)
@@ -487,7 +487,7 @@ ANY(string, string[, string]...).]],
   [[any('a', 'a  ', 'b', 'c')], [true]],
   [[any('b   ', 'a', 'b', 'c')], [true]],
   [[any('c   ', 'a', 'b', 'c     ')], [true]],
-  [[any(a, 'b', 'c', 'd')], [error],
+  [[any(a10, 'b', 'c', 'd')], [error],
    [error: DEBUG EVALUATE: Function invocation any(format, string, string, string) does not match any known function.  Candidates are:
 ANY(number, number[, number]...)
 ANY(string, string[, string]...).]],