summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/complain.c2
-rw-r--r--src/files.c1
-rw-r--r--src/files.h2
-rw-r--r--src/parse-gram.y33
-rw-r--r--src/scan-gram.l4
-rw-r--r--tests/input.at20
-rw-r--r--tests/local.at5
7 files changed, 51 insertions, 16 deletions
diff --git a/src/complain.c b/src/complain.c
index 82258c62..c177e202 100644
--- a/src/complain.c
+++ b/src/complain.c
@@ -407,7 +407,7 @@ duplicate_directive (char const *directive,
if (feature_flag & feature_caret)
complain_indent (&second, Wother, &i, _("duplicate directive"));
else
- complain_indent (&second, Wother, &i, _("duplicate directive: %s"), directive);
+ complain_indent (&second, Wother, &i, _("duplicate directive: %s"), quote (directive));
i += SUB_INDENT;
complain_indent (&first, Wother, &i, _("previous declaration"));
fixits_register (&second, "");
diff --git a/src/files.c b/src/files.c
index f805524c..759b81ea 100644
--- a/src/files.c
+++ b/src/files.c
@@ -43,6 +43,7 @@
char const *spec_outfile = NULL; /* for -o. */
char const *spec_file_prefix = NULL; /* for -b. */
+location spec_file_prefix_loc = EMPTY_LOCATION_INIT;
char const *spec_name_prefix = NULL; /* for -p. */
char *spec_verbose_file = NULL; /* for --verbose. */
char *spec_graph_file = NULL; /* for -g. */
diff --git a/src/files.h b/src/files.h
index 9c60dcd5..14f524c6 100644
--- a/src/files.h
+++ b/src/files.h
@@ -21,6 +21,7 @@
#ifndef FILES_H_
# define FILES_H_
+# include "location.h"
# include "uniqstr.h"
/* File name specified with -o for the output file, or 0 if no -o. */
@@ -34,6 +35,7 @@ extern const char *spec_name_prefix;
/* File name prefix specified with -b, or 0 if no -b. */
extern char const *spec_file_prefix;
+extern location spec_file_prefix_loc;
/* --verbose. */
extern char *spec_verbose_file;
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 1a192300..872be4d4 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -85,6 +85,11 @@
/* Handle a %error-verbose directive. */
static void handle_error_verbose (location const *loc, char const *directive);
+ /* Handle a %file-prefix directive. */
+ static void handle_file_prefix (location const *loc,
+ location const *dir_loc,
+ char const *directive, char const *value);
+
/* Handle a %name-prefix directive. */
static void handle_name_prefix (location const *loc,
char const *directive, char const *value);
@@ -204,7 +209,7 @@
%type <uniqstr>
BRACKETED_ID ID ID_COLON
- PERCENT_ERROR_VERBOSE PERCENT_FLAG PERCENT_NAME_PREFIX
+ PERCENT_ERROR_VERBOSE PERCENT_FILE_PREFIX PERCENT_FLAG PERCENT_NAME_PREFIX
PERCENT_YACC
TAG tag tag.opt variable
%printer { fputs ($$, yyo); } <uniqstr>
@@ -312,7 +317,7 @@ prologue_declaration:
| "%error-verbose" { handle_error_verbose (&@$, $1); }
| "%expect" INT { expected_sr_conflicts = $2; }
| "%expect-rr" INT { expected_rr_conflicts = $2; }
-| "%file-prefix" STRING { spec_file_prefix = $2; }
+| "%file-prefix" STRING { handle_file_prefix (&@$, &@1, $1, $2); }
| "%glr-parser"
{
nondeterministic_parser = true;
@@ -873,6 +878,30 @@ handle_error_verbose (location const *loc, char const *directive)
static void
+handle_file_prefix (location const *loc,
+ location const *dir_loc,
+ char const *directive, char const *value)
+{
+ bison_directive (loc, directive);
+ bool warned = false;
+
+ if (location_empty (spec_file_prefix_loc))
+ {
+ spec_file_prefix_loc = *loc;
+ spec_file_prefix = value;
+ }
+ else
+ {
+ duplicate_directive (directive, spec_file_prefix_loc, *loc);
+ warned = true;
+ }
+
+ if (!warned
+ && STRNEQ (directive, "%file-prefix"))
+ deprecated_directive (dir_loc, directive, "%file-prefix");
+}
+
+static void
handle_name_prefix (location const *loc,
char const *directive, char const *value)
{
diff --git a/src/scan-gram.l b/src/scan-gram.l
index e1536f5c..61b3f836 100644
--- a/src/scan-gram.l
+++ b/src/scan-gram.l
@@ -228,7 +228,7 @@ eqopt ({sp}=)?
"%empty" return BISON_DIRECTIVE (EMPTY);
"%expect" return BISON_DIRECTIVE (EXPECT);
"%expect-rr" return BISON_DIRECTIVE (EXPECT_RR);
- "%file-prefix" return BISON_DIRECTIVE (FILE_PREFIX);
+ "%file-prefix" RETURN_VALUE (PERCENT_FILE_PREFIX, uniqstr_new (yytext));
"%fixed-output-files" RETURN_VALUE (PERCENT_YACC, uniqstr_new (yytext));
"%initial-action" return BISON_DIRECTIVE (INITIAL_ACTION);
"%glr-parser" return BISON_DIRECTIVE (GLR_PARSER);
@@ -273,7 +273,7 @@ eqopt ({sp}=)?
"%default"[-_]"prec" DEPRECATED ("%default-prec");
"%error"[-_]"verbose" RETURN_VALUE (PERCENT_ERROR_VERBOSE, uniqstr_new (yytext));
"%expect"[-_]"rr" DEPRECATED ("%expect-rr");
- "%file-prefix"{eqopt} DEPRECATED ("%file-prefix");
+ "%file-prefix"{eqopt} RETURN_VALUE (PERCENT_FILE_PREFIX, uniqstr_new (yytext));
"%fixed"[-_]"output"[-_]"files" RETURN_VALUE (PERCENT_YACC, uniqstr_new (yytext));
"%no"[-_]"default"[-_]"prec" DEPRECATED ("%no-default-prec");
"%no"[-_]"lines" DEPRECATED ("%no-lines");
diff --git a/tests/input.at b/tests/input.at
index 8e30d23f..3bd2be65 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -2522,14 +2522,15 @@ input.y:12.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [
fix-it:"input.y":{12:1-12:11}:"%expect-rr"
input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-prefix' [-Wdeprecated]
fix-it:"input.y":{13:1-13:15}:"%file-prefix"
-input.y:14.1-15.2: warning: deprecated directive: '%file-prefix\n =', use '%file-prefix' [-Wdeprecated]
-fix-it:"input.y":{14:1-15:3}:"%file-prefix"
+input.y:14.1-16.5: warning: duplicate directive: '%file-prefix\n =' [-Wother]
+input.y:13.1-20: previous declaration [-Wother]
+fix-it:"input.y":{14:1-16:6}:""
input.y:17.1-19: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated]
fix-it:"input.y":{17:1-17:20}:"%fixed-output-files"
-input.y:18.1-19: warning: duplicate directive: %fixed_output-files [-Wother]
+input.y:18.1-19: warning: duplicate directive: '%fixed_output-files' [-Wother]
input.y:17.1-19: previous declaration [-Wother]
fix-it:"input.y":{18:1-18:20}:""
-input.y:19.1-19: warning: duplicate directive: %fixed-output-files [-Wother]
+input.y:19.1-19: warning: duplicate directive: '%fixed-output-files' [-Wother]
input.y:17.1-19: previous declaration [-Wother]
fix-it:"input.y":{19:1-19:20}:""
input.y:20.1-19: warning: deprecated directive: '%name-prefix= "foo"', use '%define api.prefix {foo}' [-Wdeprecated]
@@ -2584,8 +2585,6 @@ AT_CHECK([cat input.y], [],
%define parse.error verbose
%expect-rr 0
%file-prefix "foo"
-%file-prefix
-"bar"
%fixed-output-files
%define api.prefix {foo}
%no-default-prec
@@ -2601,10 +2600,10 @@ exp : '0'
]])
AT_BISON_CHECK([[-fcaret input.y]], [[1]], [],
-[[input.y:25.1-24: error: %define variable 'api.prefix' redefined
+[[input.y:23.1-24: error: %define variable 'api.prefix' redefined
%define api.prefix {bar}
^~~~~~~~~~~~~~~~~~~~~~~~
-input.y:17.1-24: previous definition
+input.y:15.1-24: previous definition
%define api.prefix {foo}
^~~~~~~~~~~~~~~~~~~~~~~~
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
@@ -2677,7 +2676,10 @@ AT_DATA_GRAMMAR([[input.y]],
]])
AT_BISON_CHECK([[input.y]], [[0]], [[]],
-[[input.y: warning: %expect-rr applies only to GLR parsers [-Wother]
+[[input.y:14.1-15.5: warning: duplicate directive: '%file-prefix' [-Wother]
+input.y:13.1-18: previous declaration [-Wother]
+input.y: warning: %expect-rr applies only to GLR parsers [-Wother]
+input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
AT_CLEANUP
diff --git a/tests/local.at b/tests/local.at
index a0ce6707..0bd0ce5c 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -707,8 +707,9 @@ if test "$POSIXLY_CORRECT_IS_EXPORTED" = false; then
# Build expected stderr up to and including the "warnings being
# treated as errors" message.
]AT_DATA([[experr]], [$4])[
- $PERL -pi -e 's{(.*): warning: (.*)\[-W(.*)\]$}
- {$][1: error: $][2\@<:@-Werror=$][3@:>@}' experr
+ $PERL -pi -e 's{(.*): warning:}{$][1: error:};' \
+ -e 's{\[-W(.*)\]$}{@<:@-Werror=$][1@:>@}' \
+ experr
]AT_CHECK([[sed 's,.*/$,,' stderr 1>&2]], [[0]], [[]], [experr])[
# Now check --warnings=error.