pspp-dev
[Top][All Lists]
Advanced

[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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]