There's no point in passing in the lexer and using lex_error(),
because the extra information that lex_error() outputs does
not help the user find the error.
---
src/language/control/loop.c | 2 +-
src/language/data-io/combine-files.c | 2 +-
src/language/data-io/file-handle.q | 2 +-
src/language/data-io/get.c | 2 +-
src/language/data-io/save-translate.c | 4 ++--
src/language/data-io/save.c | 2 +-
src/language/lexer/lexer.c | 21 +++++++++++++++------
src/language/lexer/lexer.h | 2 +-
8 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/src/language/control/loop.c b/src/language/control/loop.c
index e4877b9..cece7f6 100644
--- a/src/language/control/loop.c
+++ b/src/language/control/loop.c
@@ -261,7 +261,7 @@ parse_index_clause (struct dataset *ds, struct lexer *lexer,
}
if (loop->last_expr == NULL)
{
- lex_sbc_missing (lexer, "TO");
+ lex_sbc_missing ("TO");
return false;
}
if (loop->by_expr == NULL)
diff --git a/src/language/data-io/combine-files.c
b/src/language/data-io/combine-files.c
index e09b36e..f306cad 100644
--- a/src/language/data-io/combine-files.c
+++ b/src/language/data-io/combine-files.c
@@ -376,7 +376,7 @@ combine_files (enum comb_command_type command,
{
if (command == COMB_UPDATE)
{
- msg (SE, _("The BY subcommand is required."));
+ lex_sbc_missing ("BY");
goto error;
}
if (n_tables)
diff --git a/src/language/data-io/file-handle.q
b/src/language/data-io/file-handle.q
index 9bf6a6b..80fdaca 100644
--- a/src/language/data-io/file-handle.q
+++ b/src/language/data-io/file-handle.q
@@ -86,7 +86,7 @@ cmd_file_handle (struct lexer *lexer, struct dataset *ds)
properties = *fh_default_properties ();
if (cmd.s_name == NULL)
{
- lex_sbc_missing (lexer, "NAME");
+ lex_sbc_missing ("NAME");
goto exit_free_cmd;
}
diff --git a/src/language/data-io/get.c b/src/language/data-io/get.c
index ea65b5c..028cc3c 100644
--- a/src/language/data-io/get.c
+++ b/src/language/data-io/get.c
@@ -106,7 +106,7 @@ parse_read_command (struct lexer *lexer, struct dataset
*ds, enum reader_command
if (fh == NULL)
{
- lex_sbc_missing (lexer, "FILE");
+ lex_sbc_missing ("FILE");
goto error;
}
diff --git a/src/language/data-io/save-translate.c
b/src/language/data-io/save-translate.c
index cbed4b1..bc68e55 100644
--- a/src/language/data-io/save-translate.c
+++ b/src/language/data-io/save-translate.c
@@ -237,12 +237,12 @@ cmd_save_translate (struct lexer *lexer, struct dataset
*ds)
if (type == 0)
{
- lex_sbc_missing (lexer, "TYPE");
+ lex_sbc_missing ("TYPE");
goto error;
}
else if (handle == NULL)
{
- lex_sbc_missing (lexer, "OUTFILE");
+ lex_sbc_missing ("OUTFILE");
goto error;
}
else if (!replace && fn_exists (fh_get_file_name (handle)))
diff --git a/src/language/data-io/save.c b/src/language/data-io/save.c
index 66cdd45..b930855 100644
--- a/src/language/data-io/save.c
+++ b/src/language/data-io/save.c
@@ -279,7 +279,7 @@ parse_write_command (struct lexer *lexer, struct dataset
*ds,
if (handle == NULL)
{
- lex_sbc_missing (lexer, "OUTFILE");
+ lex_sbc_missing ("OUTFILE");
goto error;
}
diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c
index a356b38..e372568 100644
--- a/src/language/lexer/lexer.c
+++ b/src/language/lexer/lexer.c
@@ -337,20 +337,29 @@ lex_error_expecting (struct lexer *lexer, const char
*option0, ...)
}
}
-/* Reports an error to the effect that subcommand SBC may only be
- specified once. */
+/* Reports an error to the effect that subcommand SBC may only be specified
+ once.
+
+ This function does not take a lexer as an argument or use lex_error(),
+ because the result would ordinarily just be redundant: "Syntax error at
+ SUBCOMMAND: Subcommand SUBCOMMAND may only be specified once.", which does
+ not help the user find the error. */
void
lex_sbc_only_once (const char *sbc)
{
msg (SE, _("Subcommand %s may only be specified once."), sbc);
}
-/* Reports an error to the effect that subcommand SBC is
- missing. */
+/* Reports an error to the effect that subcommand SBC is missing.
+
+ This function does not take a lexer as an argument or use lex_error(),
+ because a missing subcommand can normally be detected only after the whole
+ command has been parsed, and so lex_error() would always report "Syntax
+ error at end of command", which does not help the user find the error. */
void
-lex_sbc_missing (struct lexer *lexer, const char *sbc)
+lex_sbc_missing (const char *sbc)
{
- lex_error (lexer, _("missing required subcommand %s"), sbc);
+ msg (SE, _("Required subcommand %s was not specified."), sbc);
}
/* Prints a syntax error message containing the current token and
diff --git a/src/language/lexer/lexer.h b/src/language/lexer/lexer.h
index b0787e8..2a7055a 100644
--- a/src/language/lexer/lexer.h
+++ b/src/language/lexer/lexer.h
@@ -158,7 +158,7 @@ int lex_end_of_command (struct lexer *);
void lex_error_expecting (struct lexer *, const char *, ...) SENTINEL(0);
void lex_sbc_only_once (const char *);
-void lex_sbc_missing (struct lexer *, const char *);
+void lex_sbc_missing (const char *);
void lex_error_valist (struct lexer *, const char *, va_list)
PRINTF_FORMAT (2, 0);
--
1.7.2.5
_______________________________________________
pspp-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/pspp-dev