* src/getargs.c (skeleton_arg): Last arg is now location const *.

Rewrite to simplify the logic.
(language_argmatch): Likewise.

* doc/bison.texinfo (Decl Summary, Bison Options): Don't claim
Java is supported.
* src/complain.c (program_name): Remove decl; no longer needed.
* src/main.c (program_name): Remove; now belongs to getargs.

2006-12-18  Paolo Bonzini  <bonzini@gnu.org>

* NEWS: Document %language.

* data/Makefile.am (dist_pkgdata_DATA): Add c-skel.m4, c++-skel.m4.

* data/c-skel.m4, data/c++-skel.m4: New files.
* data/glr.c: Complain on push parsers.

* doc/bison.texinfo (C++ Parser Interface): Prefer %language
over %skeleton.
(Directives): Document %language and %skeleton.
(Command line): Document -L.

* examples/extexi: Rewrite %require directive.
* examples/calc++/Makefile.am: Pass VERSION to extexi.

* src/files.c (compute_exts_from_gc): Look in language structure
for .y extension.
(compute_file_name_parts): Check whether .tab should be added.
* src/getargs.c (valid_languages, skeleton_prio, language_prio):
(language, skeleton_arg, language_argmatch): New.
(long_options): Add --language.
(getargs): Use skeleton_arg, add -L/--language.
* src/getargs.h: Include location.h.
(struct bison_language, language, skeleton_arg, language_argmatch): New.
* src/output.c (prepare): Pick default skeleton from struct language.
Don't dispatch C skeletons here.
* src/parse-gram.y (PERCENT_LANGUAGE): New.
(prologue_declaration): Add "%language" rule, use skeleton_arg.
* src/scan-gram.l ("%language"): New rule.

* tests/calc.at: Test %skeleton and %language.
* tests/local.at (AT_SKEL_CC_IF): Look for %language.
(AT_GLR_IF): Look for %skeleton "glr.cc".
(AT_LALR1_CC_IF, AT_GLR_CC_IF): Rewrite.
(AT_YACC_IF): Reject %language.

2006-12-18  Paul Eggert  <eggert@cs.ucla.edu>
This commit is contained in:
Paul Eggert
2006-12-19 00:34:37 +00:00
parent db06f0ce72
commit 0e021770cc
19 changed files with 287 additions and 51 deletions

View File

@@ -66,10 +66,19 @@ int report_flag = report_none;
int trace_flag = trace_none;
int warnings_flag = warnings_none;
static struct bison_language const valid_languages[] = {
{ "c", "c-skel.m4", ".c", ".h", true },
{ "c++", "c++-skel.m4", ".cc", ".hh", true },
{ "", "", "", "", false }
};
static int skeleton_prio = 2;
const char *skeleton = NULL;
static int language_prio = 2;
struct bison_language const *language = &valid_languages[0];
const char *include = NULL;
extern char *program_name;
char *program_name;
/** Decode an option's set of keys.
@@ -323,12 +332,63 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
}
/*-------------------------------------.
| --skeleton and --language handling. |
`--------------------------------------*/
void
skeleton_arg (char const *arg, int prio, location const *loc)
{
if (prio < skeleton_prio)
{
skeleton_prio = prio;
skeleton = arg;
}
else if (prio == skeleton_prio)
{
char const *msg =
_("multiple skeleton declarations are invalid");
if (loc)
complain_at (*loc, msg);
else
complain (msg);
}
}
void
language_argmatch (char const *arg, int prio, location const *loc)
{
char const *msg;
if (prio < language_prio)
{
int i;
for (i = 0; valid_languages[i].language[0]; i++)
if (strcasecmp (arg, valid_languages[i].language) == 0)
{
language_prio = prio;
language = &valid_languages[i];
return;
}
msg = _("invalid language `%s'");
}
else if (language_prio == prio)
msg = _("multiple language declarations are invalid");
else
return;
if (loc)
complain_at (*loc, msg, arg);
else
complain (msg, arg);
}
/*----------------------.
| Process the options. |
`----------------------*/
/* Shorts options. */
static char const short_options[] = "yvegdhr:ltknVo:b:p:S:T::W";
static char const short_options[] = "yvegdhr:L:ltknVo:b:p:S:T::W";
/* Values for long options that do not have single-letter equivalents. */
enum
@@ -374,6 +434,7 @@ static struct option const long_options[] =
{ "no-parser", no_argument, 0, 'n' },
{ "raw", no_argument, 0, 0 },
{ "skeleton", required_argument, 0, 'S' },
{ "language", required_argument, 0, 'L' },
{ "token-table", no_argument, 0, 'k' },
{0, 0, 0, 0}
@@ -414,8 +475,12 @@ getargs (int argc, char *argv[])
case 'h':
usage (EXIT_SUCCESS);
case 'L':
language_argmatch (optarg, 0, NULL);
break;
case 'S':
skeleton = AS_FILE_NAME (optarg);
skeleton_arg (AS_FILE_NAME (optarg), 0, NULL);
break;
case 'I':