[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[q2c 09/12] lexer: New function lex_force_string_or_id().
From: |
Ben Pfaff |
Subject: |
[q2c 09/12] lexer: New function lex_force_string_or_id(). |
Date: |
Sat, 5 Nov 2011 20:11:31 -0700 |
This new function removes a string from q2c.c that requires
translation but currently cannot be translated.
---
src/language/lexer/lexer.c | 15 +++++++++++++++
src/language/lexer/lexer.h | 1 +
src/language/lexer/q2c.c | 8 +-------
src/language/utilities/include.c | 8 ++------
4 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c
index bbb0059..e72a3e4 100644
--- a/src/language/lexer/lexer.c
+++ b/src/language/lexer/lexer.c
@@ -625,6 +625,21 @@ lex_force_string (struct lexer *lexer)
}
}
+/* 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
diff --git a/src/language/lexer/lexer.h b/src/language/lexer/lexer.h
index 17129c2..a6be161 100644
--- a/src/language/lexer/lexer.h
+++ b/src/language/lexer/lexer.h
@@ -128,6 +128,7 @@ bool lex_force_int (struct lexer *);
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 *);
diff --git a/src/language/lexer/q2c.c b/src/language/lexer/q2c.c
index 48f7d33..5473e11 100644
--- a/src/language/lexer/q2c.c
+++ b/src/language/lexer/q2c.c
@@ -1524,14 +1524,8 @@ dump_specifier_parse (const specifier *spec, const
subcommand *sbc)
}
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));
diff --git a/src/language/utilities/include.c b/src/language/utilities/include.c
index 89da3b9..a05456e 100644
--- a/src/language/utilities/include.c
+++ b/src/language/utilities/include.c
@@ -59,12 +59,8 @@ do_insert (struct lexer *lexer, struct dataset *ds, enum
variant variant)
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);
--
1.7.2.5
- [q2c 00/12] Fix i18n problems in q2c-generated strings, Ben Pfaff, 2011/11/05
- [q2c 01/12] SET: Warn for more obsolete subcommands., Ben Pfaff, 2011/11/05
- [q2c 04/12] LOOP: Correctly implement MXLOOPS and add a test., Ben Pfaff, 2011/11/05
- [q2c 03/12] settings: Implement MXLOOPS subcommand., Ben Pfaff, 2011/11/05
- [q2c 09/12] lexer: New function lex_force_string_or_id().,
Ben Pfaff <=
- [q2c 08/12] lexer: New functions lex_spec_missing(), lex_spec_only_once()., Ben Pfaff, 2011/11/05
- [q2c 07/12] lexer: Use error helper functions in more situations., Ben Pfaff, 2011/11/06
- [q2c 12/12] q2c: Remove gettext.h #include from generated code., Ben Pfaff, 2011/11/06
- [q2c 02/12] settings: Update default MXLOOPS and document., Ben Pfaff, 2011/11/06
- [q2c 06/12] lexer: Drop lexer parameter from lex_sbc_missing()., Ben Pfaff, 2011/11/06
- [q2c 11/12] q2c: Remove final untranslated strings from q2c.c., Ben Pfaff, 2011/11/06
- [q2c 10/12] q2c: Use new subc_list_error() to report too many subcommands., Ben Pfaff, 2011/11/06
- [q2c 05/12] lexer: New function lex_error_expecting()., Ben Pfaff, 2011/11/06
- Re: [q2c 00/12] Fix i18n problems in q2c-generated strings, John Darrington, 2011/11/06