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:
Akim Demaille
2019-01-12 17:00:49 +01:00
parent a88f8117b0
commit 72c488aa62
4 changed files with 41 additions and 11 deletions

View File

@@ -85,7 +85,7 @@ exp: %empty;
]])
AT_BISON_CHECK([--defines -o input.c input.y], [], [],
[[input.y:11.1-12: warning: deprecated directive: '%name-prefix', use '%define api.prefix' [-Wdeprecated]
[[input.y:11.1-18: warning: deprecated directive: '%name-prefix "my_"', use '%define api.prefix {my_}' [-Wdeprecated]
]])
# YYLTYPE should be defined, and MY_LLOC declared.