[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[q2c 08/12] lexer: New functions lex_spec_missing(), lex_spec_only_once(
From: |
Ben Pfaff |
Subject: |
[q2c 08/12] lexer: New functions lex_spec_missing(), lex_spec_only_once(). |
Date: |
Sat, 5 Nov 2011 20:11:30 -0700 |
These functions don't have many users yet but they make logical
sense to me.
---
src/language/dictionary/mrsets.c | 9 +++------
src/language/lexer/lexer.c | 18 ++++++++++++++++++
src/language/lexer/lexer.h | 5 +++++
tests/language/dictionary/mrsets.at | 4 ++--
4 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/src/language/dictionary/mrsets.c b/src/language/dictionary/mrsets.c
index 621cdc8..2f7c8f6 100644
--- a/src/language/dictionary/mrsets.c
+++ b/src/language/dictionary/mrsets.c
@@ -205,14 +205,12 @@ parse_group (struct lexer *lexer, struct dictionary *dict,
if (mrset->name == NULL)
{
- msg (SE, _("Required %s specification missing from %s subcommand."),
- "NAME", subcommand_name);
+ lex_spec_missing (lexer, subcommand_name, "NAME");
goto error;
}
else if (mrset->n_vars == 0)
{
- msg (SE, _("Required %s specification missing from %s subcommand."),
- "VARIABLES", subcommand_name);
+ lex_spec_missing (lexer, subcommand_name, "VARIABLES");
goto error;
}
@@ -221,8 +219,7 @@ parse_group (struct lexer *lexer, struct dictionary *dict,
/* Check that VALUE is specified and is valid for the VARIABLES. */
if (!has_value)
{
- msg (SE, _("Required %s specification missing from %s subcommand."),
- "VALUE", subcommand_name);
+ lex_spec_missing (lexer, subcommand_name, "VALUE");
goto error;
}
else if (var_is_alpha (mrset->vars[0]))
diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c
index e372568..bbb0059 100644
--- a/src/language/lexer/lexer.c
+++ b/src/language/lexer/lexer.c
@@ -362,6 +362,24 @@ lex_sbc_missing (const char *sbc)
msg (SE, _("Required subcommand %s was not specified."), sbc);
}
+/* Reports an error to the effect that specification SPEC may only be specified
+ once within subcommand SBC. */
+void
+lex_spec_only_once (struct lexer *lexer, const char *sbc, const char *spec)
+{
+ lex_error (lexer, _("%s may only be specified once within subcommand %s"),
+ spec, sbc);
+}
+
+/* Reports an error to the effect that specification SPEC is missing within
+ subcommand SBC. */
+void
+lex_spec_missing (struct lexer *lexer, const char *sbc, const char *spec)
+{
+ lex_error (lexer, _("Required %s specification missing from %s subcommand"),
+ sbc, spec);
+}
+
/* Prints a syntax error message containing the current token and
given message MESSAGE (if non-null). */
void
diff --git a/src/language/lexer/lexer.h b/src/language/lexer/lexer.h
index 2a7055a..17129c2 100644
--- a/src/language/lexer/lexer.h
+++ b/src/language/lexer/lexer.h
@@ -160,6 +160,11 @@ void lex_error_expecting (struct lexer *, const char *,
...) SENTINEL(0);
void lex_sbc_only_once (const char *);
void lex_sbc_missing (const char *);
+void lex_spec_only_once (struct lexer *, const char *subcommand,
+ const char *specification);
+void lex_spec_missing (struct lexer *, const char *subcommand,
+ const char *specification);
+
void lex_error_valist (struct lexer *, const char *, va_list)
PRINTF_FORMAT (2, 0);
void lex_next_error_valist (struct lexer *lexer, int n0, int n1,
diff --git a/tests/language/dictionary/mrsets.at
b/tests/language/dictionary/mrsets.at
index 04abfc7..edff6ae 100644
--- a/tests/language/dictionary/mrsets.at
+++ b/tests/language/dictionary/mrsets.at
@@ -239,7 +239,7 @@ AT_DATA([mrsets.sps],
MRSETS /MCGROUP VARIABLES=a b c.
])
AT_CHECK([pspp -O format=csv mrsets.sps], [1],
- [mrsets.sps:6: error: MRSETS: Required NAME specification missing from
MCGROUP subcommand.
+ [mrsets.sps:6.32: error: MRSETS: Syntax error at end of command: Required
MCGROUP specification missing from NAME subcommand.
])
AT_CLEANUP
@@ -249,7 +249,7 @@ AT_DATA([mrsets.sps],
MRSETS /MCGROUP NAME=$Mcgroup.
])
AT_CHECK([pspp -O format=csv mrsets.sps], [1],
- [mrsets.sps:6: error: MRSETS: Required VARIABLES specification missing from
MCGROUP subcommand.
+ [mrsets.sps:6.30: error: MRSETS: Syntax error at end of command: Required
MCGROUP specification missing from VARIABLES subcommand.
])
AT_CLEANUP
--
1.7.2.5
- [q2c 00/12] Fix i18n problems in q2c-generated strings, Ben Pfaff, 2011/11/05
- [q2c 01/12] SET: Warn for more obsolete subcommands., Ben Pfaff, 2011/11/05
- [q2c 04/12] LOOP: Correctly implement MXLOOPS and add a test., Ben Pfaff, 2011/11/05
- [q2c 03/12] settings: Implement MXLOOPS subcommand., Ben Pfaff, 2011/11/05
- [q2c 09/12] lexer: New function lex_force_string_or_id()., Ben Pfaff, 2011/11/05
- [q2c 08/12] lexer: New functions lex_spec_missing(), lex_spec_only_once().,
Ben Pfaff <=
- [q2c 07/12] lexer: Use error helper functions in more situations., Ben Pfaff, 2011/11/06
- [q2c 12/12] q2c: Remove gettext.h #include from generated code., Ben Pfaff, 2011/11/06
- [q2c 02/12] settings: Update default MXLOOPS and document., Ben Pfaff, 2011/11/06
- [q2c 06/12] lexer: Drop lexer parameter from lex_sbc_missing()., Ben Pfaff, 2011/11/06
- [q2c 11/12] q2c: Remove final untranslated strings from q2c.c., Ben Pfaff, 2011/11/06
- [q2c 10/12] q2c: Use new subc_list_error() to report too many subcommands., Ben Pfaff, 2011/11/06
- [q2c 05/12] lexer: New function lex_error_expecting()., Ben Pfaff, 2011/11/06
- Re: [q2c 00/12] Fix i18n problems in q2c-generated strings, John Darrington, 2011/11/06