From: Ben Pfaff Date: Mon, 12 Sep 2022 17:33:13 +0000 (-0700) Subject: placement-parser: Improve error messages for format assignment. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7b99e8ac627ba617827961d851ea70efc39ad76;p=pspp placement-parser: Improve error messages for format assignment. --- diff --git a/src/language/data-io/placement-parser.c b/src/language/data-io/placement-parser.c index c789a16b52..983bec8492 100644 --- a/src/language/data-io/placement-parser.c +++ b/src/language/data-io/placement-parser.c @@ -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; } diff --git a/tests/language/data-io/data-list.at b/tests/language/data-io/data-list.at index d7e98db79e..b20fd35b7b 100644 --- a/tests/language/data-io/data-list.at +++ b/tests/language/data-io/data-list.at @@ -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 -