From: Ben Pfaff Date: Sun, 6 Nov 2011 03:02:54 +0000 (-0700) Subject: lexer: New function lex_force_string_or_id(). X-Git-Tag: v0.7.9~104 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3368f3a6ecbc0ec5aa1212efe534288b277f13c;p=pspp-builds.git lexer: New function lex_force_string_or_id(). This new function removes a string from q2c.c that requires translation but currently cannot be translated. --- diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c index bbb00593..e72a3e47 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 17129c2b..a6be161f 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 48f7d33b..5473e112 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 89da3b9b..a05456e2 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);