mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 05:13:04 +00:00
diagnostics: improve them for %name-prefix
Currently the diagnostics for %name-prefix are not precise enough. In
particular, they does not show that braces must be used instead of
quotes.
Before:
foo.y:3.1-14: warning: deprecated directive, use '%define api.prefix' [-Wdeprecated]
%name-prefix = "foo"
^^^^^^^^^^^^^^
After:
foo.y:3.1-20: warning: deprecated directive, use '%define api.prefix {foo}' [-Wdeprecated]
%name-prefix = "foo"
^^^^^^^^^^^^^^^^^^^^
To do this we need the value passed to %name-prefix, so move the
warning from the scanner to the parser.
Accuracy will be very important for the forthcoming changes.
* src/parse-gram.y (do_name_prefix): New.
(PERCENT_NAME_PREFIX): Have a semantic value: the raw source, with
possibly underscores, equal sign, and spaces. This is used to provide
a more accurate message. It does not take comments into account,
but...
* src/scan-gram.l (%name-prefix): Delegate the warnings to the parser.
* tests/headers.at, tests/input.at: Adjust expectations.
This commit is contained in:
@@ -43,8 +43,9 @@
|
||||
#include "named-ref.h"
|
||||
#include "quotearg.h"
|
||||
#include "reader.h"
|
||||
#include "scan-gram.h"
|
||||
#include "scan-code.h"
|
||||
#include "scan-gram.h"
|
||||
#include "vasnprintf.h"
|
||||
#include "xmemdup0.h"
|
||||
|
||||
static int current_prec = 0;
|
||||
@@ -81,6 +82,10 @@
|
||||
string from the scanner (should be CODE). */
|
||||
static char const *translate_code_braceless (char *code, location loc);
|
||||
|
||||
/* Handle a %name-prefix directive. */
|
||||
static void do_name_prefix (location const *loc,
|
||||
char const *directive, char const *value);
|
||||
|
||||
/* Handle a %require directive. */
|
||||
static void do_require (location const *loc, char const *version);
|
||||
|
||||
@@ -190,7 +195,9 @@
|
||||
%printer { fputs (quotearg_style (c_quoting_style, $$), yyo); } STRING
|
||||
%printer { fprintf (yyo, "{\n%s\n}", $$); } <char*>
|
||||
|
||||
%type <uniqstr> BRACKETED_ID ID ID_COLON PERCENT_FLAG TAG tag tag.opt variable
|
||||
%type <uniqstr>
|
||||
BRACKETED_ID ID ID_COLON PERCENT_FLAG PERCENT_NAME_PREFIX TAG
|
||||
tag tag.opt variable
|
||||
%printer { fputs ($$, yyo); } <uniqstr>
|
||||
%printer { fprintf (yyo, "[%s]", $$); } BRACKETED_ID
|
||||
%printer { fprintf (yyo, "%s:", $$); } ID_COLON
|
||||
@@ -307,7 +314,7 @@ prologue_declaration:
|
||||
code_scanner_last_string_free ();
|
||||
}
|
||||
| "%language" STRING { language_argmatch ($2, grammar_prio, @1); }
|
||||
| "%name-prefix" STRING { spec_name_prefix = $2; }
|
||||
| "%name-prefix" STRING { do_name_prefix (&@$, $1, $2); }
|
||||
| "%no-lines" { no_lines_flag = true; }
|
||||
| "%nondeterministic-parser" { nondeterministic_parser = true; }
|
||||
| "%output" STRING { spec_outfile = $2; }
|
||||
@@ -846,6 +853,31 @@ add_param (param_type type, char *decl, location loc)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
do_name_prefix (location const *loc,
|
||||
char const *directive, char const *value)
|
||||
{
|
||||
spec_name_prefix = value;
|
||||
|
||||
char buf1[1024];
|
||||
size_t len1 = sizeof (buf1);
|
||||
char *old = asnprintf (buf1, &len1, "%s\"%s\"", directive, value);
|
||||
if (!old)
|
||||
xalloc_die ();
|
||||
char buf2[1024];
|
||||
size_t len2 = sizeof (buf2);
|
||||
char *new = asnprintf (buf2, &len2, "%%define api.prefix {%s}", value);
|
||||
if (!new)
|
||||
xalloc_die ();
|
||||
bison_directive (loc, old);
|
||||
deprecated_directive (loc, old, new);
|
||||
if (old != buf1)
|
||||
free (old);
|
||||
if (new != buf2)
|
||||
free (new);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
do_require (location const *loc, char const *version)
|
||||
{
|
||||
|
||||
@@ -144,7 +144,8 @@ splice (\\[ \f\t\v]*\n)*
|
||||
|
||||
/* An equal sign, with optional leading whitespaces. This is used in some
|
||||
deprecated constructs. */
|
||||
eqopt ([[:space:]]*=)?
|
||||
sp [[:space:]]*
|
||||
eqopt ({sp}=)?
|
||||
|
||||
%%
|
||||
%{
|
||||
@@ -266,10 +267,7 @@ eqopt ([[:space:]]*=)?
|
||||
|
||||
/* Deprecated since Bison 2.6 (2012-07-19), but the warning is
|
||||
issued only since Bison 3.3. */
|
||||
"%name"[-_]"prefix"{eqopt} {
|
||||
deprecated_directive (loc, yytext, "%define api.prefix");
|
||||
return BISON_DIRECTIVE (NAME_PREFIX);
|
||||
}
|
||||
"%name"[-_]"prefix"{eqopt}{sp} RETURN_VALUE (PERCENT_NAME_PREFIX, uniqstr_new (yytext));
|
||||
|
||||
/* Deprecated since Bison 2.7.90, 2012. */
|
||||
"%default"[-_]"prec" DEPRECATED ("%default-prec");
|
||||
|
||||
Reference in New Issue
Block a user