placement-parser: Improve error messages for format assignment.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 12 Sep 2022 17:33:13 +0000 (10:33 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 12 Sep 2022 17:33:13 +0000 (10:33 -0700)
src/language/data-io/placement-parser.c
tests/language/data-io/data-list.at

index c789a16b52e5c22da4d2b8b28dcc46a38e718d5a..983bec84929b62fbace8791592ce4ca36d011670 100644 (file)
@@ -81,21 +81,21 @@ parse_var_placements (struct lexer *lexer, struct pool *pool, size_t n_vars,
                                 formats, n_formats);
   else if (lex_match (lexer, T_LPAREN))
     {
-      size_t n_assignments;
-      size_t i;
-
+      int start_ofs = lex_ofs (lexer);
       if (!fixed_parse_fortran (lexer, pool, use, formats, n_formats))
         return false;
+      int end_ofs = lex_ofs (lexer) - 1;
 
-      n_assignments = 0;
-      for (i = 0; i < *n_formats; i++)
+      size_t n_assignments = 0;
+      for (size_t i = 0; i < *n_formats; i++)
         n_assignments += (*formats)[i].type < FMT_NUMBER_OF_FORMATS;
 
       if (n_assignments != n_vars)
         {
-          msg (SE, _("Number of variables specified (%zu) "
-                     "differs from number of variable formats (%zu)."),
-               n_vars, n_assignments);
+          lex_ofs_error (lexer, start_ofs, end_ofs,
+                         _("Number of variables specified (%zu) "
+                           "differs from number of variable formats (%zu)."),
+                         n_vars, n_assignments);
           return false;
         }
 
@@ -125,9 +125,10 @@ fixed_parse_columns (struct lexer *lexer, struct pool *pool, size_t n_vars,
   int w = (lc - fc + 1) / n_vars;
   if ((lc - fc + 1) % n_vars)
     {
-      msg (SE, _("The %d columns %d-%d "
-                "can't be evenly divided into %zu fields."),
-          lc - fc + 1, fc, lc, n_vars);
+      lex_ofs_error (lexer, start_ofs, lex_ofs (lexer) - 1,
+                     _("The %d columns %d-%d "
+                       "can't be evenly divided into %zu fields."),
+                     lc - fc + 1, fc, lc, n_vars);
       return false;
     }
 
index d7e98db79ef5fa8c88bdc70e3144cfcb5d9b8aef..b20fd35b7b43870e7e8999f5d1bf215fb1e88161 100644 (file)
@@ -402,38 +402,33 @@ Case Number,A
 AT_CLEANUP
 
 
-AT_SETUP([DATA LIST - Negative SKIP])
+AT_SETUP([DATA LIST syntax errors])
+AT_DATA([insert.sps], [dnl
+INSERT FILE='data-list.sps' ERROR=IGNORE.
+])
 AT_DATA([data-list.sps], [dnl
 DATA LIST LIST FILE='f.in' NOTABLE SKIP=-1 /a b c d.
-
-EXECUTE.
+DATA LIST LIST FILE='f.in' NOTABLE RECORDS=-1 /a b c d.
+DATA LIST FIXED FILE='f.in' NOTABLE/a (F8.0, F9.0).
+DATA LIST FIXED FILE='f.in' NOTABLE/a b 1-3.
 ])
 
-AT_CHECK([pspp -O format=csv data-list.sps], [1], [dnl
+AT_CHECK([pspp --testing-mode -O format=csv insert.sps], [1], [dnl
 "data-list.sps:1.41-1.42: error: DATA LIST: Syntax error expecting non-negative integer for SKIP.
     1 | DATA LIST LIST FILE='f.in' NOTABLE SKIP=-1 /a b c d.
       |                                         ^~"
 
-data-list.sps:3: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
-])
-
-AT_CLEANUP
-
-
-AT_SETUP([DATA LIST - Negative RECORDS])
-AT_DATA([data-list.sps], [dnl
-DATA LIST LIST FILE='f.in' NOTABLE RECORDS=-1 /a b c d.
-
-EXECUTE.
-])
-
-AT_CHECK([pspp -O format=csv data-list.sps], [1], [dnl
-"data-list.sps:1.44-1.45: error: DATA LIST: Syntax error expecting non-negative integer for RECORDS.
-    1 | DATA LIST LIST FILE='f.in' NOTABLE RECORDS=-1 /a b c d.
+"data-list.sps:2.44-2.45: error: DATA LIST: Syntax error expecting non-negative integer for RECORDS.
+    2 | DATA LIST LIST FILE='f.in' NOTABLE RECORDS=-1 /a b c d.
       |                                            ^~"
 
-data-list.sps:3: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
+"data-list.sps:3.40-3.50: error: DATA LIST: Number of variables specified (1) differs from number of variable formats (2).
+    3 | DATA LIST FIXED FILE='f.in' NOTABLE/a (F8.0, F9.0).
+      |                                        ^~~~~~~~~~~"
+
+"data-list.sps:4.41-4.43: error: DATA LIST: The 3 columns 1-3 can't be evenly divided into 2 fields.
+    4 | DATA LIST FIXED FILE='f.in' NOTABLE/a b 1-3.
+      |                                         ^~~"
 ])
 
 AT_CLEANUP
-