OUTPUT MODIFY: Improve error messages and coding style.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 21 Nov 2022 06:15:11 +0000 (22:15 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 21 Nov 2022 06:25:01 +0000 (22:25 -0800)
src/language/command.def
src/language/utilities/output.c
tests/automake.mk
tests/language/utilities/output.at [new file with mode: 0644]

index d269ceac3681509d49c9c6f4cb0762851e818892..5d642d693af867b1d56f97cefb90caf827574698 100644 (file)
@@ -35,7 +35,7 @@ DEF_CMD (S_ANY, 0, "MCONVERT", cmd_mconvert)
 DEF_CMD (S_ANY, 0, "N OF CASES", cmd_n_of_cases)
 DEF_CMD (S_ANY, F_ABBREV, "N", cmd_n_of_cases)
 DEF_CMD (S_ANY, 0, "NEW FILE", cmd_new_file)
-DEF_CMD (S_ANY, 0, "OUTPUT", cmd_output)
+DEF_CMD (S_ANY, 0, "OUTPUT MODIFY", cmd_output_modify)
 DEF_CMD (S_ANY, 0, "PERMISSIONS", cmd_permissions)
 DEF_CMD (S_ANY, 0, "PRESERVE", cmd_preserve)
 DEF_CMD (S_ANY, F_ABBREV, "Q", cmd_finish)
index f0dd016a829bfb2daa7e4c1049453d8c4964a622..38d437ae18fa9a9050c234d699b31ee9d77a0176 100644 (file)
 #define _(msgid) gettext (msgid)
 
 int
-cmd_output (struct lexer *lexer, struct dataset *ds UNUSED)
+cmd_output_modify (struct lexer *lexer, struct dataset *ds UNUSED)
 {
   struct string_set rc_names = STRING_SET_INITIALIZER (rc_names);
 
-  if (!lex_force_match_id (lexer, "MODIFY"))
-    {
-      lex_error (lexer, NULL);
-      goto error;
-    }
-
   while (lex_token (lexer) != T_ENDCMD)
     {
       lex_match (lexer, T_SLASH);
 
       if (lex_match_id (lexer, "SELECT"))
        {
-         if (!lex_match_id (lexer, "TABLES"))
-           {
-             lex_error (lexer, NULL);
-             goto error;
-           }
+         if (!lex_force_match_id (lexer, "TABLES"))
+            goto error;
        }
       else if (lex_match_id (lexer, "TABLECELLS"))
        {
@@ -68,10 +59,10 @@ cmd_output (struct lexer *lexer, struct dataset *ds UNUSED)
            {
              if (lex_match_id (lexer, "SELECT"))
                {
-                 if (! lex_force_match (lexer, T_EQUALS))
+                 if (!lex_force_match (lexer, T_EQUALS))
                    goto error;
 
-                 if (! lex_force_match (lexer, T_LBRACK))
+                 if (!lex_force_match (lexer, T_LBRACK))
                    goto error;
 
                  while (lex_token (lexer) == T_ID)
@@ -80,7 +71,7 @@ cmd_output (struct lexer *lexer, struct dataset *ds UNUSED)
                       lex_get (lexer);
                     }
 
-                 if (! lex_force_match (lexer, T_RBRACK))
+                 if (!lex_force_match (lexer, T_RBRACK))
                    goto error;
                }
              else if (lex_match_id (lexer, "FORMAT"))
@@ -89,13 +80,10 @@ cmd_output (struct lexer *lexer, struct dataset *ds UNUSED)
                  uint16_t width;
                  uint8_t decimals;
 
-                 if (! lex_force_match (lexer, T_EQUALS))
-                   goto error;
-                 if (! parse_abstract_format_specifier (lexer, type, &width, &decimals))
-                   {
-                     lex_error (lexer, NULL);
-                     goto error;
-                   }
+                 if (!lex_force_match (lexer, T_EQUALS)
+                      || !parse_abstract_format_specifier (lexer, type,
+                                                           &width, &decimals))
+                    goto error;
 
                  if (width <= 0)
                    {
@@ -114,7 +102,7 @@ cmd_output (struct lexer *lexer, struct dataset *ds UNUSED)
                }
              else
                {
-                 lex_error (lexer, NULL);
+                 lex_error_expecting (lexer, "SELECT", "FORMAT");
                  goto error;
                }
            }
@@ -130,7 +118,7 @@ cmd_output (struct lexer *lexer, struct dataset *ds UNUSED)
        }
       else
        {
-         lex_error (lexer, NULL);
+         lex_error_expecting (lexer, "SELECT", "TABLECELLS");
          goto error;
        }
     }
@@ -140,5 +128,5 @@ cmd_output (struct lexer *lexer, struct dataset *ds UNUSED)
 
  error:
   string_set_destroy (&rc_names);
-  return CMD_SUCCESS;
+  return CMD_FAILURE;
 }
index 679be89537cba15ceb86e27b2ccc2e548d0b248e..b39a7bbebbc7f34ca87e66e70fb9734172071eab 100644 (file)
@@ -426,6 +426,7 @@ TESTSUITE_AT = \
        tests/language/utilities/date.at \
        tests/language/utilities/host.at \
        tests/language/utilities/insert.at \
+       tests/language/utilities/output.at \
        tests/language/utilities/permissions.at \
        tests/language/utilities/set.at \
        tests/language/utilities/show.at \
diff --git a/tests/language/utilities/output.at b/tests/language/utilities/output.at
new file mode 100644 (file)
index 0000000..95b9b63
--- /dev/null
@@ -0,0 +1,47 @@
+AT_BANNER([OUTPUT MODIFY])
+
+AT_SETUP([OUTPUT MODIFY syntax errors])
+AT_DATA([output.sps], [dnl
+OUTPUT MODIFY/SELECT **.
+OUTPUT MODIFY/TABLECELLS SELECT **.
+OUTPUT MODIFY/TABLECELLS SELECT=**.
+OUTPUT MODIFY/TABLECELLS SELECT=[[**]].
+OUTPUT MODIFY/TABLECELLS FORMAT **.
+OUTPUT MODIFY/TABLECELLS FORMAT=ASDF5.
+OUTPUT MODIFY/TABLECELLS **.
+OUTPUT MODIFY/TABLECELLS SELECT="xyzzy" FORMAT=F8.2.
+])
+AT_CHECK([pspp -O format=csv output.sps], [1], [dnl
+"output.sps:1.22-1.23: error: OUTPUT MODIFY: Syntax error expecting TABLES.
+    1 | OUTPUT MODIFY/SELECT **.
+      |                      ^~"
+
+"output.sps:2.33-2.34: error: OUTPUT MODIFY: Syntax error expecting `='.
+    2 | OUTPUT MODIFY/TABLECELLS SELECT **.
+      |                                 ^~"
+
+"output.sps:3.33-3.34: error: OUTPUT MODIFY: Syntax error expecting `[['.
+    3 | OUTPUT MODIFY/TABLECELLS SELECT=**.
+      |                                 ^~"
+
+"output.sps:4.34-4.35: error: OUTPUT MODIFY: Syntax error expecting `]]'.
+    4 | OUTPUT MODIFY/TABLECELLS SELECT=[[**]].
+      |                                  ^~"
+
+"output.sps:5.33-5.34: error: OUTPUT MODIFY: Syntax error expecting `='.
+    5 | OUTPUT MODIFY/TABLECELLS FORMAT **.
+      |                                 ^~"
+
+"output.sps:6.38: error: OUTPUT MODIFY: Unknown format type `ASDF'.
+    6 | OUTPUT MODIFY/TABLECELLS FORMAT=ASDF5.
+      |                                      ^"
+
+"output.sps:7.26-7.27: error: OUTPUT MODIFY: Syntax error expecting SELECT or FORMAT.
+    7 | OUTPUT MODIFY/TABLECELLS **.
+      |                          ^~"
+
+"output.sps:8.33-8.39: error: OUTPUT MODIFY: Syntax error expecting `@<:@'.
+    8 | OUTPUT MODIFY/TABLECELLS SELECT=""xyzzy"" FORMAT=F8.2.
+      |                                 ^~~~~~~"
+])
+AT_CLEANUP
\ No newline at end of file