mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 21:33:04 +00:00
* 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:
@@ -30,10 +30,6 @@
|
||||
#include "files.h"
|
||||
#include "getargs.h"
|
||||
|
||||
/* The calling program should define program_name and set it to the
|
||||
name of the executing program. */
|
||||
extern char *program_name;
|
||||
|
||||
bool complaint_issued;
|
||||
|
||||
|
||||
|
||||
25
src/files.c
25
src/files.c
@@ -153,12 +153,20 @@ tr (char *s, char from, char to)
|
||||
static void
|
||||
compute_exts_from_gf (const char *ext)
|
||||
{
|
||||
src_extension = xstrdup (ext);
|
||||
header_extension = xstrdup (ext);
|
||||
tr (src_extension, 'y', 'c');
|
||||
tr (src_extension, 'Y', 'C');
|
||||
tr (header_extension, 'y', 'h');
|
||||
tr (header_extension, 'Y', 'H');
|
||||
if (strcmp (ext, ".y") == 0)
|
||||
{
|
||||
src_extension = xstrdup (language->src_extension);
|
||||
header_extension = xstrdup (language->header_extension);
|
||||
}
|
||||
else
|
||||
{
|
||||
src_extension = xstrdup (ext);
|
||||
header_extension = xstrdup (ext);
|
||||
tr (src_extension, 'y', 'c');
|
||||
tr (src_extension, 'Y', 'C');
|
||||
tr (header_extension, 'y', 'h');
|
||||
tr (header_extension, 'Y', 'H');
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute extensions from the given c source file extension. */
|
||||
@@ -281,7 +289,10 @@ compute_file_name_parts (void)
|
||||
xstrndup (base, (strlen (base) - (ext ? strlen (ext) : 0)));
|
||||
}
|
||||
|
||||
all_but_ext = concat2 (all_but_tab_ext, TAB_EXT);
|
||||
if (language->add_tab)
|
||||
all_but_ext = concat2 (all_but_tab_ext, TAB_EXT);
|
||||
else
|
||||
all_but_ext = xstrdup (all_but_tab_ext);
|
||||
|
||||
/* Compute the extensions from the grammar file name. */
|
||||
if (ext && !yacc_flag)
|
||||
|
||||
@@ -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':
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
#ifndef GETARGS_H_
|
||||
# define GETARGS_H_
|
||||
|
||||
#include "location.h"
|
||||
|
||||
extern char *program_name;
|
||||
|
||||
/* flags set by % directives */
|
||||
|
||||
/* for -S */
|
||||
@@ -65,6 +69,18 @@ extern bool push_parser;
|
||||
extern bool nondeterministic_parser;
|
||||
|
||||
|
||||
/* --language. */
|
||||
struct bison_language
|
||||
{
|
||||
char language[sizeof "c++"];
|
||||
char skeleton[sizeof "c++-skel.m4"];
|
||||
char src_extension[sizeof ".cc"];
|
||||
char header_extension[sizeof ".hh"];
|
||||
bool add_tab;
|
||||
};
|
||||
|
||||
extern struct bison_language const *language;
|
||||
|
||||
/*-----------.
|
||||
| --report. |
|
||||
`-----------*/
|
||||
@@ -126,4 +142,8 @@ extern int warnings_flag;
|
||||
*/
|
||||
void getargs (int argc, char *argv[]);
|
||||
|
||||
/* Used by parse-gram.y. */
|
||||
void language_argmatch (char const *arg, int prio, location const *loc);
|
||||
void skeleton_arg (const char *arg, int prio, location const *loc);
|
||||
|
||||
#endif /* !GETARGS_H_ */
|
||||
|
||||
@@ -50,9 +50,6 @@
|
||||
#include "tables.h"
|
||||
#include "uniqstr.h"
|
||||
|
||||
/* The name this program was run with, for messages. */
|
||||
char *program_name;
|
||||
|
||||
|
||||
|
||||
int
|
||||
|
||||
16
src/output.c
16
src/output.c
@@ -622,16 +622,13 @@ prepare (void)
|
||||
muscle_insert ("pre_prologue", obstack_finish (&pre_prologue_obstack));
|
||||
muscle_insert ("post_prologue", obstack_finish (&post_prologue_obstack));
|
||||
|
||||
/* Find the right skeleton file. */
|
||||
if (!skeleton)
|
||||
{
|
||||
if (glr_parser || nondeterministic_parser)
|
||||
skeleton = "glr.c";
|
||||
else
|
||||
skeleton = "yacc.c";
|
||||
}
|
||||
/* Find the right skeleton file, and add muscles about the skeletons. */
|
||||
if (skeleton)
|
||||
MUSCLE_INSERT_C_STRING ("skeleton", skeleton);
|
||||
else
|
||||
skeleton = language->skeleton;
|
||||
|
||||
/* About the skeletons. */
|
||||
/* About the skeletons. */
|
||||
{
|
||||
char const *pkgdatadir = getenv ("BISON_PKGDATADIR");
|
||||
/* b4_pkgdatadir is used inside m4_include in the skeletons, so digraphs
|
||||
@@ -639,7 +636,6 @@ prepare (void)
|
||||
his Bison installation path. */
|
||||
MUSCLE_INSERT_STRING_RAW ("pkgdatadir",
|
||||
pkgdatadir ? pkgdatadir : PKGDATADIR);
|
||||
MUSCLE_INSERT_C_STRING ("skeleton", skeleton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -143,6 +143,7 @@ static int current_prec = 0;
|
||||
PERCENT_FILE_PREFIX "%file-prefix"
|
||||
PERCENT_GLR_PARSER "%glr-parser"
|
||||
PERCENT_INITIAL_ACTION "%initial-action"
|
||||
PERCENT_LANGUAGE "%language"
|
||||
PERCENT_LEX_PARAM "%lex-param"
|
||||
PERCENT_LOCATIONS "%locations"
|
||||
PERCENT_NAME_PREFIX "%name-prefix"
|
||||
@@ -245,6 +246,7 @@ prologue_declaration:
|
||||
{
|
||||
muscle_code_grow ("initial_action", translate_symbol_action ($2, @2), @2);
|
||||
}
|
||||
| "%language" STRING { language_argmatch ($2, 1, &@1); }
|
||||
| "%lex-param" "{...}" { add_param ("lex_param", $2, @2); }
|
||||
| "%locations" { locations_flag = true; }
|
||||
| "%name-prefix" STRING { spec_name_prefix = $2; }
|
||||
@@ -257,7 +259,7 @@ prologue_declaration:
|
||||
| "%pure-parser" { pure_parser = true; }
|
||||
| "%push-parser" { push_parser = true; pure_parser = true; }
|
||||
| "%require" STRING { version_check (&@2, $2); }
|
||||
| "%skeleton" STRING { skeleton = $2; }
|
||||
| "%skeleton" STRING { skeleton_arg ($2, 1, &@1); }
|
||||
| "%token-table" { token_table_flag = true; }
|
||||
| "%verbose" { report_flag = report_states; }
|
||||
| "%yacc" { yacc_flag = true; }
|
||||
|
||||
@@ -172,6 +172,7 @@ splice (\\[ \f\t\v]*\n)*
|
||||
"%fixed"[-_]"output"[-_]"files" return PERCENT_YACC;
|
||||
"%initial-action" return PERCENT_INITIAL_ACTION;
|
||||
"%glr-parser" return PERCENT_GLR_PARSER;
|
||||
"%language" return PERCENT_LANGUAGE;
|
||||
"%left" return PERCENT_LEFT;
|
||||
"%lex-param" return PERCENT_LEX_PARAM;
|
||||
"%locations" return PERCENT_LOCATIONS;
|
||||
|
||||
Reference in New Issue
Block a user