mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 12:53:03 +00:00
* src/getargs.c (longopts): Support `--output'. getopt is now
able to understand that `--out' is OK: the two racing long options are aliases. (usage): Adjust. * src/lex.h (tok_setopt): Remove, replaced with... (tok_intopt, tok_stropt): these new guys. * src/lex.c (getopt.h): Not needed. (token_buffer, unlexed_token_buffer): Not const. (percent_table): Promote `-' over `_' in directive names. Active `%name-prefix', `file-prefix', and `output'. (parse_percent_token): Accept possible arguments to directives. Promote `-' over `_' in directive names. * doc/bison.texinfo (Decl Summary): Split the list into `directives for grammars' and `directives for bison'. Sort'em. Add description of `%name-prefix', `file-prefix', and `output'. Promote `-' over `_' in directive names. (Bison Options): s/%locactions/%locations/. Nice Freudian slip. Simplify the description of `--name-prefix'. Promote `-' over `_' in directive names. Promote `--output' over `--output-file'. Fix the description of `--defines'. * tests/output.at: Exercise %file-prefix and %output.
This commit is contained in:
@@ -63,6 +63,7 @@ static struct option longopts[] =
|
||||
{"defines", optional_argument, 0, 'd'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"file-prefix", required_argument, 0, 'b'},
|
||||
{"output", required_argument, 0, 'o'},
|
||||
{"output-file", required_argument, 0, 'o'},
|
||||
{"graph", optional_argument, 0, 'g'},
|
||||
|
||||
@@ -118,9 +119,9 @@ Output:\n\
|
||||
-d, --defines also produce a header file\n\
|
||||
-v, --verbose also produce an explanation of the automaton\n\
|
||||
-b, --file-prefix=PREFIX specify a PREFIX for output files\n\
|
||||
-o, --output-file=FILE leave output to FILE\n\
|
||||
-g, --graph also produce a VCG graph description of the \
|
||||
automaton\n"), stream);
|
||||
-o, --output=FILE leave output to FILE\n\
|
||||
-g, --graph also produce a VCG description of the automaton\n\
|
||||
"), stream);
|
||||
putc ('\n', stream);
|
||||
|
||||
fputs (_("\
|
||||
|
||||
120
src/lex.c
120
src/lex.c
@@ -21,7 +21,6 @@
|
||||
#include "system.h"
|
||||
#include "getargs.h"
|
||||
#include "files.h"
|
||||
#include "getopt.h" /* for optarg */
|
||||
#include "symtab.h"
|
||||
#include "lex.h"
|
||||
#include "complain.h"
|
||||
@@ -30,7 +29,7 @@
|
||||
|
||||
/* Buffer for storing the current token. */
|
||||
struct obstack token_obstack;
|
||||
const char *token_buffer = NULL;
|
||||
char *token_buffer = NULL;
|
||||
|
||||
bucket *symval;
|
||||
int numval;
|
||||
@@ -38,7 +37,7 @@ int numval;
|
||||
/* A token to be reread, see unlex and lex. */
|
||||
static token_t unlexed = tok_undef;
|
||||
static bucket *unlexed_symval = NULL;
|
||||
static const char *unlexed_token_buffer = NULL;
|
||||
static char *unlexed_token_buffer = NULL;
|
||||
|
||||
void
|
||||
lex_init (void)
|
||||
@@ -427,7 +426,7 @@ lex (void)
|
||||
/* parse the literal token and compute character code in code */
|
||||
|
||||
{
|
||||
int code, discode;
|
||||
int code;
|
||||
|
||||
obstack_1grow (&token_obstack, '\'');
|
||||
literalchar (&token_obstack, &code, '\'');
|
||||
@@ -435,6 +434,7 @@ lex (void)
|
||||
c = getc (finput);
|
||||
if (c != '\'')
|
||||
{
|
||||
int discode;
|
||||
complain (_("use \"...\" for multi-character literal tokens"));
|
||||
while (1)
|
||||
if (!literalchar (0, &discode, '\''))
|
||||
@@ -553,28 +553,27 @@ struct percent_table_struct percent_table[] =
|
||||
{ "nonassoc", NULL, tok_nonassoc },
|
||||
{ "binary", NULL, tok_nonassoc },
|
||||
{ "prec", NULL, tok_prec },
|
||||
{ "locations", &locations_flag, tok_noop }, /* -l */
|
||||
{ "no_lines", &no_lines_flag, tok_noop }, /* -l */
|
||||
{ "locations", &locations_flag, tok_intopt }, /* -l */
|
||||
{ "no-lines", &no_lines_flag, tok_intopt }, /* -l */
|
||||
{ "raw", NULL, tok_obsolete }, /* -r */
|
||||
{ "token_table", &token_table_flag, tok_noop }, /* -k */
|
||||
{ "yacc", &yacc_flag, tok_noop }, /* -y */
|
||||
{ "fixed_output_files",&yacc_flag, tok_noop }, /* -y */
|
||||
{ "defines", &defines_flag, tok_noop }, /* -d */
|
||||
{ "no_parser", &no_parser_flag, tok_noop }, /* -n */
|
||||
{ "graph", &graph_flag, tok_noop }, /* -g */
|
||||
#if 0
|
||||
/* For the time being, this is not enabled yet, while it's possible
|
||||
though, since we use obstacks. The only risk is with semantic
|
||||
parsers which will output an `include' of an output file: be sure
|
||||
that the name included is indeed the name of the output file. */
|
||||
{ "output_file", &spec_outfile, tok_setopt }, /* -o */
|
||||
{ "file_prefix", &spec_file_prefix, tok_setopt }, /* -b */
|
||||
{ "name_prefix", &spec_name_prefix, tok_setopt }, /* -p */
|
||||
#endif
|
||||
{ "verbose", &verbose_flag, tok_noop }, /* -v */
|
||||
{ "debug", &debug_flag, tok_noop }, /* -t */
|
||||
{ "semantic_parser", &semantic_parser, tok_noop },
|
||||
{ "pure_parser", &pure_parser, tok_noop },
|
||||
{ "token-table", &token_table_flag, tok_intopt }, /* -k */
|
||||
{ "yacc", &yacc_flag, tok_intopt }, /* -y */
|
||||
{ "fixed-output-files",&yacc_flag, tok_intopt }, /* -y */
|
||||
{ "defines", &defines_flag, tok_intopt }, /* -d */
|
||||
{ "no-parser", &no_parser_flag, tok_intopt }, /* -n */
|
||||
{ "graph", &graph_flag, tok_intopt }, /* -g */
|
||||
|
||||
/* FIXME: semantic parsers which will output an `include' of an
|
||||
output file: be sure that the name included is indeed the name of
|
||||
the output file. */
|
||||
{ "output", &spec_outfile, tok_stropt }, /* -o */
|
||||
{ "file-prefix", &spec_file_prefix, tok_stropt }, /* -b */
|
||||
{ "name-prefix", &spec_name_prefix, tok_stropt }, /* -p */
|
||||
|
||||
{ "verbose", &verbose_flag, tok_intopt }, /* -v */
|
||||
{ "debug", &debug_flag, tok_intopt }, /* -t */
|
||||
{ "semantic-parser", &semantic_parser, tok_intopt },
|
||||
{ "pure-parser", &pure_parser, tok_intopt },
|
||||
|
||||
{ NULL, NULL, tok_illegal}
|
||||
};
|
||||
@@ -585,7 +584,10 @@ struct percent_table_struct percent_table[] =
|
||||
token_t
|
||||
parse_percent_token (void)
|
||||
{
|
||||
struct percent_table_struct *tx;
|
||||
struct percent_table_struct *tx = NULL;
|
||||
/* Where `=' was found in token_buffer. */
|
||||
size_t equal_offset = 0;
|
||||
char *arg = NULL;
|
||||
|
||||
int c = getc (finput);
|
||||
|
||||
@@ -597,6 +599,8 @@ parse_percent_token (void)
|
||||
case '{':
|
||||
return tok_percent_left_curly;
|
||||
|
||||
/* FIXME: Who the heck are those 5 guys!?! `%<' = `%left'!!!
|
||||
Let's ask for there removal. */
|
||||
case '<':
|
||||
return tok_left;
|
||||
|
||||
@@ -619,42 +623,80 @@ parse_percent_token (void)
|
||||
obstack_1grow (&token_obstack, '%');
|
||||
while (isalpha (c) || c == '_' || c == '-')
|
||||
{
|
||||
if (c == '-')
|
||||
c = '_';
|
||||
if (c == '_')
|
||||
c = '-';
|
||||
obstack_1grow (&token_obstack, c);
|
||||
c = getc (finput);
|
||||
}
|
||||
|
||||
ungetc (c, finput);
|
||||
if (c == '=')
|
||||
{
|
||||
equal_offset = obstack_object_size (&token_obstack);
|
||||
obstack_1grow (&token_obstack, c);
|
||||
c = getc (finput);
|
||||
if (c = '"')
|
||||
{
|
||||
int code; /* ignored here */
|
||||
|
||||
obstack_1grow (&token_obstack, '"');
|
||||
/* Read up to and including ". */
|
||||
while (literalchar (&token_obstack, &code, '"'))
|
||||
/* nothing */;
|
||||
}
|
||||
}
|
||||
else
|
||||
ungetc (c, finput);
|
||||
|
||||
obstack_1grow (&token_obstack, '\0');
|
||||
token_buffer = obstack_finish (&token_obstack);
|
||||
if (equal_offset)
|
||||
{
|
||||
/* %token_buffer="arg" */
|
||||
arg = token_buffer + equal_offset + 2;
|
||||
arg[strlen (arg) - 1] = '\0';
|
||||
token_buffer[equal_offset] = '\0';
|
||||
}
|
||||
|
||||
/* table lookup % directive */
|
||||
for (tx = percent_table; tx->name; tx++)
|
||||
if (strcmp (token_buffer + 1, tx->name) == 0)
|
||||
break;
|
||||
|
||||
if (tx->set_flag)
|
||||
{
|
||||
*((int *) (tx->set_flag)) = 1;
|
||||
return tok_noop;
|
||||
}
|
||||
if (arg && !tx->retval == tok_stropt)
|
||||
fatal (_("`%s' supports no argument: %s"), token_buffer, quotearg (arg));
|
||||
|
||||
switch (tx->retval)
|
||||
{
|
||||
case tok_setopt:
|
||||
*((char **) (tx->set_flag)) = optarg;
|
||||
case tok_stropt:
|
||||
assert (tx->set_flag);
|
||||
if (arg)
|
||||
{
|
||||
/* Keep only the first assignment: command line options have
|
||||
already been processed, and we want them to have
|
||||
precedence. Side effect: if this %-option is used
|
||||
several times, only the first is honored. Bah. */
|
||||
if (!*((char **) (tx->set_flag)))
|
||||
*((char **) (tx->set_flag)) = arg;
|
||||
}
|
||||
else
|
||||
fatal (_("`%s' requires an argument"), token_buffer);
|
||||
return tok_noop;
|
||||
break;
|
||||
|
||||
case tok_intopt:
|
||||
assert (tx->set_flag);
|
||||
*((int *) (tx->set_flag)) = 1;
|
||||
return tok_noop;
|
||||
break;
|
||||
|
||||
case tok_obsolete:
|
||||
fatal (_("`%s' is no longer supported"), token_buffer);
|
||||
return tok_noop;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Other cases do not apply here. */
|
||||
return tx->retval;
|
||||
break;
|
||||
}
|
||||
|
||||
return tx->retval;
|
||||
abort ();
|
||||
}
|
||||
|
||||
@@ -49,12 +49,13 @@ typedef enum token_e
|
||||
tok_expect,
|
||||
tok_thong,
|
||||
tok_noop,
|
||||
tok_setopt,
|
||||
tok_intopt,
|
||||
tok_stropt,
|
||||
tok_illegal,
|
||||
tok_obsolete
|
||||
} token_t;
|
||||
|
||||
extern const char *token_buffer;
|
||||
extern char *token_buffer;
|
||||
extern bucket *symval;
|
||||
extern int numval;
|
||||
|
||||
|
||||
14
src/reader.c
14
src/reader.c
@@ -936,16 +936,13 @@ parse_dquoted_param (const char *from)
|
||||
static void
|
||||
read_declarations (void)
|
||||
{
|
||||
int c;
|
||||
int tok;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
c = skip_white_space ();
|
||||
int c = skip_white_space ();
|
||||
|
||||
if (c == '%')
|
||||
{
|
||||
tok = parse_percent_token ();
|
||||
token_t tok = parse_percent_token ();
|
||||
|
||||
switch (tok)
|
||||
{
|
||||
@@ -999,6 +996,13 @@ read_declarations (void)
|
||||
case tok_noop:
|
||||
break;
|
||||
|
||||
case tok_stropt:
|
||||
case tok_intopt:
|
||||
case tok_obsolete:
|
||||
case tok_illegal:
|
||||
abort ();
|
||||
break;
|
||||
|
||||
default:
|
||||
complain (_("unrecognized: %s"), token_buffer);
|
||||
skip_to_char ('%');
|
||||
|
||||
Reference in New Issue
Block a user