int
cmd_reread (struct lexer *lexer, struct dataset *ds)
{
- struct file_handle *fh; /* File to be re-read. */
- struct expression *e; /* Expression for column to set. */
- struct reread_trns *t; /* Created transformation. */
char *encoding = NULL;
-
- fh = fh_get_default_handle ();
- e = NULL;
+ struct file_handle *fh = fh_get_default_handle ();
+ struct expression *e = NULL;
while (lex_token (lexer) != T_ENDCMD)
{
if (lex_match_id (lexer, "COLUMN"))
}
else
{
- lex_error (lexer, NULL);
+ lex_error_expecting (lexer, "COLUMN", "FILE", "ENCODING");
goto error;
}
}
- t = xmalloc (sizeof *t);
- t->reader = dfm_open_reader (fh, lexer, encoding);
- t->column = e;
+ struct reread_trns *t = xmalloc (sizeof *t);
+ *t = (struct reread_trns) {
+ .reader = dfm_open_reader (fh, lexer, encoding),
+ .column = e,
+ };
add_transformation (ds, &reread_trns_class, t);
fh_unref (fh);
2 | END FILE.
3 | END INPUT PROGRAM.
])
+AT_CLEANUP
+
+AT_SETUP([REREAD syntax errors])
+AT_DATA([reread.sps], [dnl
+INPUT PROGRAM.
+REREAD COLUMN=1 COLUMN=**.
+END INPUT PROGRAM.
+
+INPUT PROGRAM.
+REREAD COLUMN=**.
+END INPUT PROGRAM.
+
+INPUT PROGRAM.
+REREAD FILE=**.
+END INPUT PROGRAM.
+
+INPUT PROGRAM.
+REREAD ENCODING=**.
+END INPUT PROGRAM.
+
+INPUT PROGRAM.
+REREAD **.
+END INPUT PROGRAM.
+])
+AT_DATA([insert.sps], [dnl
+INSERT FILE='reread.sps' ERROR=IGNORE.
+])
+AT_CHECK([pspp --testing-mode -O format=csv insert.sps], [1], [dnl
+"reread.sps:2.17-2.22: error: REREAD: Subcommand COLUMN may only be specified once.
+ 2 | REREAD COLUMN=1 COLUMN=**.
+ | ^~~~~~"
+
+"reread.sps:6.15-6.16: error: REREAD: Syntax error.
+ 6 | REREAD COLUMN=**.
+ | ^~"
+
+"reread.sps:10.13-10.14: error: REREAD: Syntax error expecting a file name or handle name.
+ 10 | REREAD FILE=**.
+ | ^~"
+
+"reread.sps:14.17-14.18: error: REREAD: Syntax error expecting string.
+ 14 | REREAD ENCODING=**.
+ | ^~"
+
+"reread.sps:18.8-18.9: error: REREAD: Syntax error expecting COLUMN, FILE, or ENCODING.
+ 18 | REREAD **.
+ | ^~"
+])
AT_CLEANUP
\ No newline at end of file