From: Ben Pfaff Date: Sun, 7 Jul 2019 18:44:43 +0000 (-0700) Subject: lexer: Make lex_error_expecting() easier to use. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f20801a82fe1382da0033996c08160a9f93a3da;p=pspp lexer: Make lex_error_expecting() easier to use. With this change, the caller doesn't have to explicitly supply the null sentinel since the macro does it automatically. --- diff --git a/src/language/data-io/get-data.c b/src/language/data-io/get-data.c index 8a58be434c..a4514135c8 100644 --- a/src/language/data-io/get-data.c +++ b/src/language/data-io/get-data.c @@ -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; } } diff --git a/src/language/data-io/get.c b/src/language/data-io/get.c index 6e99187ba1..0f66f64f98 100644 --- a/src/language/data-io/get.c +++ b/src/language/data-io/get.c @@ -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; } } diff --git a/src/language/data-io/save-translate.c b/src/language/data-io/save-translate.c index e2e787347f..0da3c8b96f 100644 --- a/src/language/data-io/save-translate.c +++ b/src/language/data-io/save-translate.c @@ -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; } } diff --git a/src/language/data-io/save.c b/src/language/data-io/save.c index d12593ffca..efc7e09d23 100644 --- a/src/language/data-io/save.c +++ b/src/language/data-io/save.c @@ -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; } } diff --git a/src/language/data-io/trim.c b/src/language/data-io/trim.c index 68a2b5ed9c..c2697a26ac 100644 --- a/src/language/data-io/trim.c +++ b/src/language/data-io/trim.c @@ -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, diff --git a/src/language/dictionary/attributes.c b/src/language/dictionary/attributes.c index 2f1d6906b9..2fdc11e2a1 100644 --- a/src/language/dictionary/attributes.c +++ b/src/language/dictionary/attributes.c @@ -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; } diff --git a/src/language/dictionary/formats.c b/src/language/dictionary/formats.c index 4b5a2b208a..817cdbd6d9 100644 --- a/src/language/dictionary/formats.c +++ b/src/language/dictionary/formats.c @@ -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; } diff --git a/src/language/dictionary/modify-variables.c b/src/language/dictionary/modify-variables.c index 98a588b15b..3dbbc18a02 100644 --- a/src/language/dictionary/modify-variables.c +++ b/src/language/dictionary/modify-variables.c @@ -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); diff --git a/src/language/dictionary/numeric.c b/src/language/dictionary/numeric.c index 82b175725d..e306d6b9d2 100644 --- a/src/language/dictionary/numeric.c +++ b/src/language/dictionary/numeric.c @@ -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; } } diff --git a/src/language/expressions/parse.c b/src/language/expressions/parse.c index 0e5f6abbb6..5054b69321 100644 --- a/src/language/expressions/parse.c +++ b/src/language/expressions/parse.c @@ -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; } } diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c index f87731415c..47808898ab 100644 --- a/src/language/lexer/lexer.c +++ b/src/language/lexer/lexer.c @@ -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; } diff --git a/src/language/lexer/lexer.h b/src/language/lexer/lexer.h index a0a410ed5a..91200ce6cd 100644 --- a/src/language/lexer/lexer.h +++ b/src/language/lexer/lexer.h @@ -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 *); diff --git a/src/language/lexer/q2c.c b/src/language/lexer/q2c.c index 27ff530d31..58b9cd19f6 100644 --- a/src/language/lexer/q2c.c +++ b/src/language/lexer/q2c.c @@ -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 (); diff --git a/src/language/stats/aggregate.c b/src/language/stats/aggregate.c index 7a2c986bf0..5a4b41e1ab 100644 --- a/src/language/stats/aggregate.c +++ b/src/language/stats/aggregate.c @@ -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; diff --git a/src/language/stats/graph.c b/src/language/stats/graph.c index 93ecc72b65..0992627593 100644 --- a/src/language/stats/graph.c +++ b/src/language/stats/graph.c @@ -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 (); diff --git a/src/language/stats/sort-criteria.c b/src/language/stats/sort-criteria.c index 0556f93b68..965e7d09dd 100644 --- a/src/language/stats/sort-criteria.c +++ b/src/language/stats/sort-criteria.c @@ -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)) diff --git a/src/language/utilities/include.c b/src/language/utilities/include.c index ecb33b2767..1efa3bd2e3 100644 --- a/src/language/utilities/include.c +++ b/src/language/utilities/include.c @@ -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; } } diff --git a/src/language/utilities/permissions.c b/src/language/utilities/permissions.c index 3f679c150e..e151645037 100644 --- a/src/language/utilities/permissions.c +++ b/src/language/utilities/permissions.c @@ -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; } diff --git a/src/language/utilities/set.q b/src/language/utilities/set.q index 8b06448fe4..301cc645e8 100644 --- a/src/language/utilities/set.q +++ b/src/language/utilities/set.q @@ -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; }