lexer: Make lex_error_expecting() easier to use.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 7 Jul 2019 18:44:43 +0000 (11:44 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 7 Jul 2019 18:44:43 +0000 (11:44 -0700)
With this change, the caller doesn't have to explicitly supply the null
sentinel since the macro does it automatically.

19 files changed:
src/language/data-io/get-data.c
src/language/data-io/get.c
src/language/data-io/save-translate.c
src/language/data-io/save.c
src/language/data-io/trim.c
src/language/dictionary/attributes.c
src/language/dictionary/formats.c
src/language/dictionary/modify-variables.c
src/language/dictionary/numeric.c
src/language/expressions/parse.c
src/language/lexer/lexer.c
src/language/lexer/lexer.h
src/language/lexer/q2c.c
src/language/stats/aggregate.c
src/language/stats/graph.c
src/language/stats/sort-criteria.c
src/language/utilities/include.c
src/language/utilities/permissions.c
src/language/utilities/set.q

index 8a58be434c71a6b61de8497bb255458fd3d3daf5..a4514135c89d3a7c96b84a4e04b645e7ce886ff1 100644 (file)
@@ -425,7 +425,7 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds)
                            DP_DELIMITED, &has_type);
           else
             {
-              lex_error_expecting (lexer, "FIXED", "DELIMITED", NULL_SENTINEL);
+              lex_error_expecting (lexer, "FIXED", "DELIMITED");
               goto error;
             }
           if (!ok)
@@ -463,7 +463,7 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds)
             }
           else
             {
-              lex_error_expecting (lexer, "LINE", "VARIABLES", NULL_SENTINEL);
+              lex_error_expecting (lexer, "LINE", "VARIABLES");
               goto error;
             }
         }
@@ -560,7 +560,7 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds)
         break;
       else
         {
-          lex_error_expecting (lexer, "VARIABLES", NULL_SENTINEL);
+          lex_error_expecting (lexer, "VARIABLES");
           goto error;
         }
     }
index 6e99187ba11c5a311d137b2f6be1dbc0990ae3ed..0f66f64f98ba38ee830654863e8b190ab6541fee 100644 (file)
@@ -109,7 +109,7 @@ parse_read_command (struct lexer *lexer, struct dataset *ds,
          if (!lex_match_id (lexer, "COMM")
               && !lex_match_id (lexer, "TAPE"))
            {
-             lex_error_expecting (lexer, "COMM", "TAPE", NULL_SENTINEL);
+             lex_error_expecting (lexer, "COMM", "TAPE");
               goto error;
            }
        }
index e2e787347f9bb6f55d39735c084df8e85737925f..0da3c8b96f0f9a807972b1c2cb6e5ee9e586ef4e 100644 (file)
@@ -121,7 +121,7 @@ cmd_save_translate (struct lexer *lexer, struct dataset *ds)
             type = TAB_FILE;
           else
             {
-              lex_error_expecting (lexer, "CSV", "TAB", NULL_SENTINEL);
+              lex_error_expecting (lexer, "CSV", "TAB");
               goto error;
             }
         }
@@ -138,7 +138,7 @@ cmd_save_translate (struct lexer *lexer, struct dataset *ds)
             recode_user_missing = true;
           else
             {
-              lex_error_expecting (lexer, "IGNORE", "RECODE", NULL_SENTINEL);
+              lex_error_expecting (lexer, "IGNORE", "RECODE");
               goto error;
             }
         }
@@ -151,7 +151,7 @@ cmd_save_translate (struct lexer *lexer, struct dataset *ds)
             use_value_labels = true;
           else
             {
-              lex_error_expecting (lexer, "VALUES", "LABELS", NULL_SENTINEL);
+              lex_error_expecting (lexer, "VALUES", "LABELS");
               goto error;
             }
         }
@@ -199,8 +199,7 @@ cmd_save_translate (struct lexer *lexer, struct dataset *ds)
                     decimal = ',';
                   else
                     {
-                      lex_error_expecting (lexer, "DOT", "COMMA",
-                                           NULL_SENTINEL);
+                      lex_error_expecting (lexer, "DOT", "COMMA");
                       goto error;
                     }
                 }
@@ -213,8 +212,7 @@ cmd_save_translate (struct lexer *lexer, struct dataset *ds)
                     use_print_formats = true;
                   else
                     {
-                      lex_error_expecting (lexer, "PLAIN", "VARIABLE",
-                                           NULL_SENTINEL);
+                      lex_error_expecting (lexer, "PLAIN", "VARIABLE");
                       goto error;
                     }
                 }
@@ -231,7 +229,7 @@ cmd_save_translate (struct lexer *lexer, struct dataset *ds)
             retain_unselected = false;
           else
             {
-              lex_error_expecting (lexer, "RETAIN", "DELETE", NULL_SENTINEL);
+              lex_error_expecting (lexer, "RETAIN", "DELETE");
               goto error;
             }
         }
index d12593ffca59ad841412a8cf9db1a37125183cf8..efc7e09d230b2e28442ddf152bb2a16e0b6c1bfe 100644 (file)
@@ -238,8 +238,7 @@ parse_write_command (struct lexer *lexer, struct dataset *ds,
             cw = true;
           else
             {
-              lex_error_expecting (lexer, "READONLY", "WRITEABLE",
-                                   NULL_SENTINEL);
+              lex_error_expecting (lexer, "READONLY", "WRITEABLE");
               goto error;
             }
           sysfile_opts.create_writeable = porfile_opts.create_writeable = cw;
@@ -253,7 +252,7 @@ parse_write_command (struct lexer *lexer, struct dataset *ds,
             *retain_unselected = false;
           else
             {
-              lex_error_expecting (lexer, "RETAIN", "DELETE", NULL_SENTINEL);
+              lex_error_expecting (lexer, "RETAIN", "DELETE");
               goto error;
             }
         }
@@ -284,7 +283,7 @@ parse_write_command (struct lexer *lexer, struct dataset *ds,
             porfile_opts.type = PFM_TAPE;
           else
             {
-              lex_error_expecting (lexer, "COMM", "TAPE", NULL_SENTINEL);
+              lex_error_expecting (lexer, "COMM", "TAPE");
               goto error;
             }
         }
index 68a2b5ed9c1ef28c8963cccfcdac0b364bf1b04b..c2697a26acfaa13de58c0b1949eef4c065dfb9f4 100644 (file)
@@ -111,7 +111,7 @@ parse_dict_rename (struct lexer *lexer, struct dictionary *dict)
        goto done;
       if (!lex_match (lexer, T_EQUALS))
        {
-          lex_error_expecting (lexer, "`='", NULL_SENTINEL);
+          lex_error_expecting (lexer, "`='");
          goto done;
        }
       if (!parse_DATA_LIST_vars (lexer, dict, &new_names, &nn,
index 2f1d6906b9b6b4ee1b76b62857f0968673f8fc99..2fdc11e2a1ad3744f8551a29c360b8a8cd769a5f 100644 (file)
@@ -197,7 +197,7 @@ parse_attributes (struct lexer *lexer, const char *dict_encoding,
         command = DELETE;
       else if (command == UNKNOWN)
         {
-          lex_error_expecting (lexer, "ATTRIBUTE=", "DELETE=", NULL_SENTINEL);
+          lex_error_expecting (lexer, "ATTRIBUTE=", "DELETE=");
           return CMD_FAILURE;
         }
 
index 4b5a2b208ace70f69c896ba4c4bd65941196fa5d..817cdbd6d922cd03dc401a073214116cf8f9ec32 100644 (file)
@@ -84,7 +84,7 @@ internal_cmd_formats (struct lexer *lexer, struct dataset *ds, int which)
 
       if (!lex_match (lexer, T_LPAREN))
        {
-          lex_error_expecting (lexer, "`('", NULL_SENTINEL);
+          lex_error_expecting (lexer, "`('");
          goto fail;
        }
       if (!parse_format_specifier (lexer, &f)
@@ -94,7 +94,7 @@ internal_cmd_formats (struct lexer *lexer, struct dataset *ds, int which)
 
       if (!lex_match (lexer, T_RPAREN))
        {
-          lex_error_expecting (lexer, "`)'", NULL_SENTINEL);
+          lex_error_expecting (lexer, "`)'");
          goto fail;
        }
 
index 98a588b15be47d1d7cbd889a044b0dba6796cc9e..3dbbc18a02bd2e1b15142f333aa68d8bcf7959ba 100644 (file)
@@ -154,7 +154,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds)
                {
                  if (!lex_match (lexer, T_LPAREN))
                    {
-                      lex_error_expecting (lexer, "`('", NULL_SENTINEL);
+                      lex_error_expecting (lexer, "`('");
                      free (v);
                      goto done;
                    }
@@ -166,7 +166,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds)
                    }
                  if (!lex_match (lexer, T_RPAREN))
                    {
-                      lex_error_expecting (lexer, "`)'", NULL_SENTINEL);
+                      lex_error_expecting (lexer, "`)'");
                      free (v);
                      goto done;
                    }
@@ -201,7 +201,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds)
 
              if (!lex_match (lexer, T_LPAREN))
                {
-                  lex_error_expecting (lexer, "`('", NULL_SENTINEL);
+                  lex_error_expecting (lexer, "`('");
                  goto done;
                }
              if (!parse_variables (lexer, dataset_dict (ds),
@@ -210,7 +210,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds)
                goto done;
              if (!lex_match (lexer, T_EQUALS))
                {
-                  lex_error_expecting (lexer, "`='", NULL_SENTINEL);
+                  lex_error_expecting (lexer, "`='");
                  goto done;
                }
 
@@ -230,7 +230,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds)
                }
              if (!lex_match (lexer, T_RPAREN))
                {
-                  lex_error_expecting (lexer, "`)'", NULL_SENTINEL);
+                  lex_error_expecting (lexer, "`)'");
                  goto done;
                }
            }
@@ -340,7 +340,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds)
        break;
       if (lex_token (lexer) != T_SLASH)
        {
-          lex_error_expecting (lexer, "`/'", "`.'", NULL_SENTINEL);
+          lex_error_expecting (lexer, "`/'", "`.'");
          goto done;
        }
       lex_get (lexer);
index 82b175725d27e2ff15070459bea9a899b0ae432d..e306d6b9d28c8ebe4cf4a46493df02e2adcf6a7c 100644 (file)
@@ -71,7 +71,7 @@ cmd_numeric (struct lexer *lexer, struct dataset *ds)
 
          if (!lex_match (lexer, T_RPAREN))
            {
-              lex_error_expecting (lexer, "`)'", NULL_SENTINEL);
+              lex_error_expecting (lexer, "`)'");
              goto fail;
            }
        }
index 0e5f6abbb6323514c3b349f845a962caaacdbbe3..5054b6932105e9e8358065968e70efb9d78829b0 100644 (file)
@@ -1270,7 +1270,7 @@ parse_function (struct lexer *lexer, struct expression *e)
           break;
         else if (!lex_match (lexer, T_COMMA))
           {
-            lex_error_expecting (lexer, "`,'", "`)'", NULL_SENTINEL);
+            lex_error_expecting (lexer, "`,'", "`)'");
             goto fail;
           }
       }
index f87731415c2f7691a75a9934d5a39c88ae857faf..47808898abe1b4f2c8a1a97e35d93d4f55ba7755 100644 (file)
@@ -272,7 +272,7 @@ lex_next_error (struct lexer *lexer, int n0, int n1, const char *format, ...)
 /* Prints a syntax error message saying that OPTION0 or one of the other
    strings following it, up to the first NULL, is expected. */
 void
-lex_error_expecting (struct lexer *lexer, const char *option0, ...)
+(lex_error_expecting) (struct lexer *lexer, const char *option0, ...)
 {
   enum { MAX_OPTIONS = 8 };
   const char *options[MAX_OPTIONS + 1];
@@ -588,7 +588,7 @@ lex_force_match_id (struct lexer *lexer, const char *identifier)
     return true;
   else
     {
-      lex_error_expecting (lexer, identifier, NULL_SENTINEL);
+      lex_error_expecting (lexer, identifier);
       return false;
     }
 }
@@ -609,11 +609,11 @@ lex_force_match (struct lexer *lexer, enum token_type type)
       if (type_string)
        {
          char *s = xasprintf ("`%s'", type_string);
-         lex_error_expecting (lexer, s, NULL_SENTINEL);
+         lex_error_expecting (lexer, s);
          free (s);
        }
       else
-       lex_error_expecting (lexer, token_type_to_name (type), NULL_SENTINEL);
+       lex_error_expecting (lexer, token_type_to_name (type));
 
       return false;
     }
index a0a410ed5a94b0f40d0c01270f1b47da53351fbb..91200ce6cd86488f7aa92e2fe4e5d22865e5c2bb 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "data/identifier.h"
 #include "data/variable.h"
+#include "libpspp/cast.h"
 #include "libpspp/compiler.h"
 #include "libpspp/prompt.h"
 
@@ -161,6 +162,8 @@ void lex_next_error (struct lexer *, int n0, int n1, const char *, ...)
 int lex_end_of_command (struct lexer *);
 
 void lex_error_expecting (struct lexer *, const char *, ...) SENTINEL(0);
+#define lex_error_expecting(...) \
+  lex_error_expecting(__VA_ARGS__, NULL_SENTINEL)
 
 void lex_sbc_only_once (const char *);
 void lex_sbc_missing (const char *);
index 27ff530d318eb9c364ba7db5d59fb8e99c13cc4a..58b9cd19f68334b1e3a02fcb5bbf583b87f1e326 100644 (file)
@@ -1462,8 +1462,7 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc)
                {
                  dump (1, "if (!lex_match (lexer, T_LPAREN))");
                  dump (1, "{");
-                 dump (0, "lex_error_expecting (lexer, \"`('\", "
-                        "NULL_SENTINEL);");
+                 dump (0, "lex_error_expecting (lexer, \"`('\");");
                   dump (0, "goto lossage;");
                  dump (-1, "}");
                  outdent ();
index 7a2c986bf04282051a7854e1c671a097daf35565..5a4b41e1abbec582fa474ed9909aa0ae133afd4a 100644 (file)
@@ -224,7 +224,7 @@ cmd_aggregate (struct lexer *lexer, struct dataset *ds)
          lex_match (lexer, T_EQUALS);
          if (!lex_match_id (lexer, "COLUMNWISE"))
            {
-             lex_error_expecting (lexer, "COLUMNWISE", NULL);
+             lex_error_expecting (lexer, "COLUMNWISE");
               goto error;
            }
          agr.missing = COLUMNWISE;
index 93ecc72b65a88d7dfa981de3ee7010af60a9a656..0992627593aa526ab35d1a72b432c8fe991619b3 100644 (file)
@@ -801,7 +801,7 @@ cmd_graph (struct lexer *lexer, struct dataset *ds)
                }
              else
                {
-                 lex_error_expecting (lexer, "BIVARIATE", NULL);
+                 lex_error_expecting (lexer, "BIVARIATE");
                  goto error;
                }
              if (!lex_force_match (lexer, T_RPAREN))
@@ -953,7 +953,7 @@ cmd_graph (struct lexer *lexer, struct dataset *ds)
     case CT_BAR:
       break;
     case CT_NONE:
-      lex_error_expecting (lexer, "HISTOGRAM", "SCATTERPLOT", "BAR", NULL);
+      lex_error_expecting (lexer, "HISTOGRAM", "SCATTERPLOT", "BAR");
       goto error;
     default:
       NOT_REACHED ();
index 0556f93b6821ef2457c82445aa984ccfde2af6f9..965e7d09dd95f8f77c37be36ea838d7b5540959a 100644 (file)
@@ -71,7 +71,7 @@ parse_sort_criteria (struct lexer *lexer, const struct dictionary *dict,
             direction = SC_ASCEND;
           else
            {
-              lex_error_expecting (lexer, "A", "D", NULL_SENTINEL);
+              lex_error_expecting (lexer, "A", "D");
               goto error;
            }
          if (!lex_force_match (lexer, T_RPAREN))
index ecb33b27670826fd8fa7ae25f1bf435b09ed0f13..1efa3bd2e3c5d5cf196d9dc4be1eb6465cb5cca1 100644 (file)
@@ -105,8 +105,7 @@ do_insert (struct lexer *lexer, struct dataset *ds, enum variant variant)
            syntax_mode = LEX_SYNTAX_AUTO;
          else
            {
-             lex_error_expecting (lexer, "BATCH", "INTERACTIVE", "AUTO",
-                                   NULL_SENTINEL);
+             lex_error_expecting (lexer, "BATCH", "INTERACTIVE", "AUTO");
              goto exit;
            }
        }
@@ -123,7 +122,7 @@ do_insert (struct lexer *lexer, struct dataset *ds, enum variant variant)
            }
          else
            {
-             lex_error_expecting (lexer, "YES", "NO", NULL_SENTINEL);
+             lex_error_expecting (lexer, "YES", "NO");
              goto exit;
            }
        }
@@ -140,7 +139,7 @@ do_insert (struct lexer *lexer, struct dataset *ds, enum variant variant)
            }
          else
            {
-             lex_error_expecting (lexer, "CONTINUE", "STOP", NULL_SENTINEL);
+             lex_error_expecting (lexer, "CONTINUE", "STOP");
              goto exit;
            }
        }
index 3f679c150e21968370c2b2d283fcdfb7145f4131..e1516450371780a94dee8309b1fbe49ca531168c 100644 (file)
@@ -76,7 +76,7 @@ cmd_permissions (struct lexer *lexer, struct dataset *ds UNUSED)
     }
   else
     {
-      lex_error_expecting (lexer, "WRITEABLE", "READONLY", NULL_SENTINEL);
+      lex_error_expecting (lexer, "WRITEABLE", "READONLY");
       goto error;
     }
 
index 8b06448fe474fd9f2540d7036fe5aabb5e8d556f..301cc645e8583257e80a69d599902710c5ede594 100644 (file)
@@ -353,7 +353,7 @@ stc_custom_tnumbers (struct lexer *lexer,
     settings_set_show_values (SETTINGS_VALUE_SHOW_BOTH);
   else
     {
-      lex_error_expecting (lexer, "VALUES", "LABELS", "BOTH", NULL_SENTINEL);
+      lex_error_expecting (lexer, "VALUES", "LABELS", "BOTH");
       return 0;
     }
 
@@ -376,7 +376,7 @@ stc_custom_tvars (struct lexer *lexer,
     settings_set_show_variables (SETTINGS_VALUE_SHOW_BOTH);
   else
     {
-      lex_error_expecting (lexer, "NAMES", "LABELS", "BOTH", NULL_SENTINEL);
+      lex_error_expecting (lexer, "NAMES", "LABELS", "BOTH");
       return 0;
     }