}
}
+/* If the current token is a string or an identifier, does nothing and returns
+ true. Otherwise, reports an error and returns false.
+
+ This is meant for use in syntactic situations where we want to encourage the
+ user to supply a quoted string, but for compatibility we also accept
+ identifiers. (One example of such a situation is file names.) Therefore,
+ the error message issued when the current token is wrong only says that a
+ string is expected and doesn't mention that an identifier would also be
+ accepted. */
+bool
+lex_force_string_or_id (struct lexer *lexer)
+{
+ return lex_is_integer (lexer) || lex_force_string (lexer);
+}
+
/* If the current token is an integer, does nothing and returns true.
Otherwise, reports an error and returns false. */
bool
bool lex_force_num (struct lexer *);
bool lex_force_id (struct lexer *);
bool lex_force_string (struct lexer *);
+bool lex_force_string_or_id (struct lexer *);
/* Token accessors. */
enum token_type lex_token (const struct lexer *);
}
else if (s->value == VAL_STRING)
{
- dump (1, "if (lex_token (lexer) != T_ID "
- "&& !lex_is_string (lexer))");
- dump (1, "{");
- dump (0, "msg (SE, _(\"%s specifier of %s subcommand "
- "requires a string argument.\"));",
- s->specname, sbc->name);
+ dump (1, "if (!lex_force_string_or_id (lexer))");
dump (0, "goto lossage;");
- dump (-1, "}");
dump (-1, "free (p->%s%s);", sbc->prefix, st_lower (s->valname));
dump (0, "p->%s%s = ss_xstrdup (ss_tokss (lexer));",
sbc->prefix, st_lower (s->valname));
if (lex_match_id (lexer, "FILE"))
lex_match (lexer, T_EQUALS);
- /* File name can be identifier or string. */
- if (lex_token (lexer) != T_ID && !lex_is_string (lexer))
- {
- lex_error (lexer, _("expecting file name"));
- return CMD_FAILURE;
- }
+ if (!lex_force_string_or_id (lexer))
+ return CMD_FAILURE;
relative_name = utf8_to_filename (lex_tokcstr (lexer));
filename = include_path_search (relative_name);