Commit Graph

1382 Commits

Author SHA1 Message Date
Akim Demaille
7498ede3ab tests: improve check for updated variable names
* tests/input.at ("%define" backward compatibility): Don't define
twice "api.namespace", so that we don't get an error, which stops the
process too soon to see an error about the value given to
'lr.keep-unreachable-state'.
2019-01-22 06:52:33 +01:00
Akim Demaille
27104acdbe diagnostics: remove redundancy
Don't repeat the name of the warning in the sub messages.  E.g.,
remove the second "[-Wother]" in the following message

    foo.y:2.1-27: warning: %define variable 'parse.error' redefined [-Wother]
     %define parse.error verbose
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    foo.y:1.1-27:     previous definition [-Wother]
     %define parse.error verbose
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~

* src/complain.c (error_message): Don't print the warning type when
it's indented.
Adjust test cases.
2019-01-21 20:30:36 +01:00
Akim Demaille
ec08b369ec c++: address -Wweak-vtables warnings
Reported by Derek Clegg
http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00021.html

    aux/parser-internal.h:429:12: error: 'syntax_error' has no out-of-line virtual
         method definitions; its vtable will be emitted in every translation unit
         [-Werror,-Wweak-vtables]
       struct syntax_error : std::runtime_error

To avoid this warning, we need syntax_error to have a virtual function
defined in a compilation unit.  Let it be the destructor.  To comply
with C++98, this dtor should be 'throw()'.  Merely making YY_NOEXCEPT
be 'throw()' in C++98 triggers
errors (http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00022.html),
so let's introduce YY_NOTHROW and flag only ~syntax_error with it.

Also, since we now have an explicit dtor, we need to provide an copy
ctor.

* configure.ac (warn_cxx): Add -Wweak-vtables.
* data/skeletons/c++.m4 (YY_NOTHROW): New.
(syntax_error): Declare the dtor, and define the copy ctor.
* data/skeletons/glr.cc, data/skeletons/lalr1.cc (~syntax_error):
Define.
2019-01-20 18:46:44 +01:00
Akim Demaille
eb0f3e79e0 fixits: handle duplicates of %name-prefix
The test case "Deprecated directives" (currently 56) no longer emits
warnings after 'bison -u'!

* src/files.h, src/files.c (spec_name_prefix_loc): New.
* src/parse-gram.y (handle_name_prefix): Emit fixits for duplicate
%name-prefix.
* tests/input.at (Deprecated directives): Adjust.
2019-01-17 18:09:38 +01:00
Akim Demaille
e86adac52d fixits: handle %file-prefix
* src/files.h, src/files.c (spec_file_prefix_loc): New.
* src/scan-gram.l (%file-prefix): Delegate diagnostics to...
* src/parse-gram.y (handle_file_prefix): here.
* src/complain.c (duplicate_directive): Quote the directive.
* tests/input.at: Adjust.
2019-01-17 18:09:38 +01:00
Akim Demaille
5879c8dc5a fixits: handle per-rule duplicates
* src/complain.c (duplicate_rule_directive): Here.
* tests/actions.at (Invalid uses of %empty): Check it.
2019-01-17 18:09:38 +01:00
Akim Demaille
d5d148630a fixits: fix warnings about duplicates
* src/complain.c (duplicate_directive): Fix the complaint level.
* tests/input.at: Adjust.
2019-01-17 18:09:32 +01:00
Akim Demaille
b443932991 diagnostics: properly indent the "previous declaration" message
* src/complain.c (duplicate_directive, duplicate_rule_directive):
Here.
2019-01-16 08:40:47 +01:00
Akim Demaille
b6b397b7f0 fixits: report duplicate %yacc directives
We should use -ffixit and --update to clean files with duplicate
directives.  And we should complain only once about duplicate obsolete
directives: keep only the "duplicate" warning.  Let's start with %yacc.

For instance on:

    %fixed-output_files
    %fixed-output-files
    %yacc
    %%
    exp:

This run of bison:

    $ bison /tmp/foo.y -u
    foo.y:1.1-19: warning: deprecated directive, use '%fixed-output-files' [-Wdeprecated]
     %fixed-output_files
     ^~~~~~~~~~~~~~~~~~~
    foo.y:2.1-19: warning: duplicate directive [-Wother]
     %fixed-output-files
     ^~~~~~~~~~~~~~~~~~~
    foo.y:1.1-19: previous declaration
     %fixed-output_files
     ^~~~~~~~~~~~~~~~~~~
    foo.y:3.1-5: warning: duplicate directive [-Wother]
     %yacc
     ^~~~~
    foo.y:1.1-19: previous declaration
     %fixed-output_files
     ^~~~~~~~~~~~~~~~~~~
    bison: file 'foo.y' was updated (backup: 'foo.y~')

gives:

    %fixed-output-files
    %%
    exp:

* src/location.h, src/location.c (location_empty): New.
* src/complain.h, src/complain.c (duplicate_directive): New.

* src/getargs.h, src/getargs.c (yacc_flag): Instead of a Boolean, be
the location of the definition.
Update dependencies.

* src/scan-gram.l (%yacc, %fixed-output-files): Move the handling of
its warnings to...
* src/parse-gram.y (do_yacc): This new function.

* tests/input.at (Deprecated Directives): Adjust expectations.
2019-01-16 08:40:39 +01:00
Akim Demaille
169fe80c7f fixits: suggest running --update if there are fixits
* src/fixits.h, src/fixits.c (fixits_empty): New.
* src/complain.c (deprecated_directive): Register the Wdeprecated
fixits only if -Wdeprecated was enabled, so that we don't apply
updates if the user didn't ask for them.
* src/main.c (main): If there were fixits, issue a warning suggesting
running with --update.
Free uniqstrs after the fixits, since the latter use the former.
* tests/headers.at, tests/input.at: Update expectations.
2019-01-16 07:59:16 +01:00
Akim Demaille
b7e0d3131d fixits: avoid generating empty lines
* src/fixits.c (fixits_run): If erase the content of a line, also
erase the following \n.
* tests/input.at (Deprecated directives): Update expectations.
2019-01-16 06:55:47 +01:00
Akim Demaille
ad326ada91 c, c++: avoid implicit fall-throw
Reported by Derek Clegg.
http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00004.html

* configure.ac (warn_common): Add -Wimplicit-fallthrough.
This does trigger failures in the test suite.
* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c, tests/c++.at:
Make fall-throws explicit.
2019-01-15 18:07:00 +01:00
Akim Demaille
a049509d04 c++: avoid -Wundefined-func-template warnings from clang
Reported by Derek Clegg.
http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00006.html

Clang does not like this:

    template <typename D>
    struct basic_symbol : D
    {
      basic_symbol();
    };

    struct by_type {};

    struct symbol_type : basic_symbol<by_type>
    {
      symbol_type(){}
    };

It gives:

    $ clang++-mp-7.0 -Wundefined-func-template foo.cc -c
    foo.cc:11:3: warning: instantiation of function 'basic_symbol<by_type>::basic_symbol'
                 required here, but no definition is available [-Wundefined-func-template]
      symbol_type(){}
      ^
    foo.cc:4:3: note: forward declaration of template entity is here
      basic_symbol();
      ^
    foo.cc:11:3: note: add an explicit instantiation declaration to suppress this warning
                 if 'basic_symbol<by_type>::basic_symbol' is explicitly instantiated in
                 another translation unit
      symbol_type(){}
      ^
    1 warning generated.

The same applies for the basic_symbol's destructor and `clear()`.

* configure.ac (warn_cxx): Add -Wundefined-func-template.
This triggered one failure in the test suite:
* tests/headers.at (Sane headers): here, where we check that we can
compile the generated headers in other compilation units than the
parser's.
Add a variant type to make sure that basic_symbol and symbol_type are
properly generated in this case.
* data/skeletons/c++.m4 (basic_symbol): Inline the definitions of the
destructor and of `clear` in the class definition.
2019-01-15 07:10:29 +01:00
Akim Demaille
7c63cc1f6b diagnostics: add fixit support for duplicate removal
* src/muscle-tab.c (muscle_percent_define_insert): Register a fixit
for duplicate removal.
* tests/input.at: Adjust expectations.
2019-01-14 19:57:37 +01:00
Akim Demaille
ba469451d8 diagnostics: improve the accuracy for %error-verbose
Avoid duplicate warnings about %error-verbose, once for deprecation,
another for duplicate.  Keep only the duplicate warning for the second
occurrence of %error-verbose.

This will help removal fixits.

* src/scan-gram.l (%error-verbose): Return as a PERCENT_ERROR_VERBOSE
token.
* src/parse-gram.y (do_error_verbose): New.
Use it.
* src/muscle-tab.c (muscle_percent_variable_update): Handle pseudo
variables such as %error-verbose.
2019-01-14 19:57:37 +01:00
Akim Demaille
41aaa8374c diagnostics: update the grammar file
Let's use the fixits to actually update the grammar files.

* src/getargs.h, src/getargs.c (update_flag): New.
* src/fixits.h, src/fixits.c (fixits_run): New.
* src/main.c (main): Invoke fixits_run when --update is passed.
* tests/input.at (Deprecated directives): Check --update.
2019-01-14 19:57:37 +01:00
Akim Demaille
79e79be298 diagnostics: improve accuracy for deprecated %define variables
* src/parse-gram.y: Use the location of the whole definition to record
the location of a %define variable, instead of just the name of the
variable.
Adjust tests.
2019-01-14 19:57:37 +01:00
Akim Demaille
dad14ec3e4 diagnostics: add -ffixit support for deprecated features
Issue directives for IDE/editors to fix the source file.
http://clang.llvm.org/docs/UsersManual.html#cmdoption-fdiagnostics-parseable-fixits

Do it for deprecated features.  For instance:

    $ cat foo.y
    %error-verbose

    %name-prefix = "foo"
    %name-prefix="bar"
    %define parser_class_name "Parser"

    %%
    exp:;

    $ LC_ALL=C ./_build/8d/tests/bison -ffixit /tmp/foo.yy
    /tmp/foo.yy:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
     %error-verbose
     ^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{1:1-1:15}:"%define parse.error verbose"
    /tmp/foo.yy:3.1-20: warning: deprecated directive, use '%define api.prefix {foo}' [-Wdeprecated]
     %name-prefix = "foo"
     ^^^^^^^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{3:1-3:21}:"%define api.prefix {foo}"
    /tmp/foo.yy:4.1-18: warning: deprecated directive, use '%define api.prefix {bar}' [-Wdeprecated]
     %name-prefix="bar"
     ^^^^^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{4:1-4:19}:"%define api.prefix {bar}"
    /tmp/foo.yy:5.9-25: warning: deprecated directive, use '%define api.parser.class {Parser}' [-Wdeprecated]
     %define parser_class_name "Parser"
             ^^^^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{5:9-5:26}:"%define api.parser.class {Parser}"
    /tmp/foo.yy:5.9-25: error: %define variable 'api.parser.class' is not used
     %define parser_class_name "Parser"
             ^^^^^^^^^^^^^^^^^

* src/getargs.h, src/getargs.c (feature_fixit_parsable): New.
(feature_types, feature_args): Use it.
* src/complain.c (deprecated_directive): Use it.

* tests/input.at: Check it.
2019-01-14 19:57:37 +01:00
Akim Demaille
a7ff1c75be diagnostics: prefer ^~~~ to ^^^^ to underline code
That's what both GCC and Clang do, and it is indeed much nicer to
read.  From:

    foo.y:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
     %error-verbose
     ^^^^^^^^^^^^^^
    foo.y:4.1-20: warning: deprecated directive, use '%define api.prefix {foo}' [-Wdeprecated]
     %name-prefix = "foo"
     ^^^^^^^^^^^^^^^^^^^^

to:

    foo.y:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
     %error-verbose
     ^~~~~~~~~~~~~~
    foo.y:4.1-20: warning: deprecated directive, use '%define api.prefix {foo}' [-Wdeprecated]
     %name-prefix = "foo"
     ^~~~~~~~~~~~~~~~~~~~

* src/location.c (location_caret): Use ^~~~.
Adjust tests expectations.
2019-01-14 19:57:37 +01:00
Akim Demaille
72c488aa62 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.
2019-01-14 19:57:37 +01:00
Akim Demaille
f9db426de6 c++: beware of -Wshadow
This line:

    slice<stack_symbol_type, stack_type> slice (yystack_, yylen);

triggers warnings:

    parse.h:1790:11: note: shadowed declaration is here

Reported by Frank Heckenbach.
http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00002.html

* configure.ac (warn_c): Move -Wshadow to...
(warn_common): here.
* data/skeletons/stack.hh (slice): Define as an inner class of stack.
* data/skeletons/lalr1.cc: Adjust.
Rename the variable as 'range' instead of 'slice'.
2019-01-13 12:26:58 +01:00
Akim Demaille
70a4b97daf tests: fix usage of AT_PARSER_CHECK
The parser must be the first command.  Caught by syntax-check.

* tests/c++.at: here.
2019-01-12 09:38:57 +01:00
Akim Demaille
f0d7f71a64 NEWS: update 2019-01-12 08:19:46 +01:00
Akim Demaille
d3801ad2d1 tests: formatting changes
* tests/input.at, tests/regression.at: here.
2019-01-12 07:34:50 +01:00
Akim Demaille
2471733f1a package: bump copyrights to 2019 2019-01-05 14:58:05 +01:00
Akim Demaille
c0c45cfa38 java/d: rename some %define variables for consistency
See 890ee8a1fd and
https://lists.gnu.org/archive/html/bison-patches/2019-01/msg00024.html.

* data/skeletons/d.m4, data/skeletons/java.m4
(abstract, annotations, extends, final, implements, public, strictfp):
Rename as...
(api.parser.abstract, api.parser.annotations, api.parser.extends)
(api.parser.final, api.parser.implements, api.parser.public)
(api.parser.strictfp):
these.

* src/muscle-tab.c (muscle_percent_variable_update): Ensure backward
compatibility.

* doc/bison.texi, examples/d/calc.y, examples/java/Calc.y,
tests/input.at: Adjust.
2019-01-05 12:28:55 +01:00
Akim Demaille
eb2b5aef0a style: clean tests
* tests/named-refs.at: here.
2019-01-05 10:15:33 +01:00
Akim Demaille
84276bc3d5 glr.cc: fix the handling of syntax_error from the scanner
Commit 90a8537e62 was right, but issued
two error messages.  Commit 80ef7e7639
tried to address that by mapping yychar and yytoken to empty, but that
completely breaks the invariants of glr.c.  In particular, yygetToken
can be called repeatedly and is expected to return the latest result,
unless yytoken is YYEMPTY.  Since the previous attempt was "recording"
that the token was coming from an exception by setting it to YYEMPTY,
instead of getting again the faulty token, we fetched another one.

Rather, revert to the first approach: map yytoken to "invalid token",
but record in yychar the fact that we come from an exception thrown in
the scanner.

* data/skeletons/glr.c (YYFAULTYTOK): New.
(yygetToken): Use it to record syntax errors from the scanner.
* tests/c++.at (Syntax error as exception): In addition to checking
syntax_error with error recovery, make sure it also behaves as
expected without.
2019-01-05 10:15:33 +01:00
Akim Demaille
b90675e67a clearly deprecate %name-prefix
* src/scan-gram.l (%name-prefix): Issue a deprecation warning.

* tests/calc.at, tests/headers.at, tests/input.at, tests/java.at,
* tests/javapush.at, tests/local.at: Adjust expectations.
Or disable -Wdeprecated.

* doc/bison.texi: Document that %name-prefix is replaced by %define
api.prefix.
2019-01-03 09:03:33 +01:00
Akim Demaille
890ee8a1fd rename parser_class_name as api.parser.class
The previous name was historical and inconsistent.

* src/muscle-tab.c (define_directive): Use the proper value passing
syntax, based on the muscle kind.
(muscle_percent_variable_update): Use the right value passing syntax.
Migrate from parser_class_name to api.parser.class.

* data/skeletons: Migrate from parser_class_name to api.parser.class.

* doc/bison.texi (%define Summary): Document both parser_class_name
and api.parser.class.
Promote the latter over the former.
2019-01-02 19:14:32 +01:00
Akim Demaille
80ef7e7639 glr.cc: don't issue two error messages when syntax_error is thrown
Reported by Askar Safin.
https://lists.gnu.org/archive/html/bison-patches/2019-01/msg00000.html

* data/skeletons/glr.c (yygetToken): Return YYEMPTY when an exception
is thrown.
* data/skeletons/lalr1.cc: Log when an exception is caught.
* tests/c++.at (Syntax error as exception): Be sure to recover from
error before triggering another error.
2019-01-02 12:08:04 +01:00
Akim Demaille
90a8537e62 glr.cc: support syntax_error exceptions
Kindly requested by Аскар Сафин (Askar Safin).
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00033.html

* data/skeletons/glr.c (b4_glr_cc_if): New.
Use it.
(yygetToken): Catch syntax_errors.
* data/skeletons/glr.cc (YY_EXCEPTIONS): New.
* tests/c++.at: Check it.
2018-12-31 07:48:09 +01:00
Akim Demaille
9a110873a0 tests: refactor 2018-12-30 14:02:59 +01:00
Akim Demaille
597600fd83 style: formatting changes
* tests/input.at: here.
2018-12-29 09:23:09 +01:00
Akim Demaille
7938ab53ff c++: check several parsers in the same program
* tests/local.at (AT_LOCATION_TYPE_IF): Turn into...
(AT_LOCATION_TYPE_SPAN_IF): this.
Adjust dependencies.
* tests/headers.at (Several parsers): Add another C++ parser,
which uses the first C++ parser's locations.
2018-12-27 18:22:33 +01:00
Akim Demaille
10591c8879 c++: also provide a copy constructor for symbol_type
Suggested by Wolfgang Thaller.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00081.html

* data/c++.m4 (basic_symbol, by_type): Instead of provide either move
or copy constructor, always provide the copy one.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Check it.
2018-12-24 19:03:32 +01:00
Akim Demaille
807bf60cfc c++: fix double free when a symbol_type was moved
Currently the following piece of code crashes (with parse.assert),
because we don't record that s was moved-from, and we invoke its dtor.

    {
      auto s = parser::make_INT (42);
      auto s2 = std::move (s);
    }

Reported by Wolfgang Thaller.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00077.html

* data/c++.m4 (by_type): Provide a move-ctor.
(basic_symbol): Be sure not to read a moved-from value.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Check this case.
2018-12-24 18:58:56 +01:00
Akim Demaille
45cd7dfb7f c++: style: improve tests
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Provide better
assertions.
Use them.
Avoid useless Bison invocations.
2018-12-24 18:58:46 +01:00
Akim Demaille
777b0163de tests: fixes
* tests/c++.at: Use AT_YYLEX_PROTOTYPE etc.
Which requires that we use the same argument names (lvalp, etc.).
* tests/local.at (AT_NAME_PREFIX): Fix regex.
2018-12-23 10:40:07 +01:00
Akim Demaille
e5780041b9 c++: exhibit a safe symbol_type
Instead of introducing make_symbol (whose name, btw, somewhat
infringes on the user's "name space", if she defines a token named
"symbol"), let's make the construction of symbol_type safer, using
assertions.

For instance with:

    %token ':' <std::string> ID <int> INT;

generate:

    symbol_type (int token, const std::string&);
    symbol_type (int token, const int&);
    symbol_type (int token);

It does mean that now named token constructors (make_ID, make_INT,
etc.) go through a useless assert, but I think we can ignore this: I
assume any decent compiler will inline the symbol_type ctor inside the
make_TOKEN functions, which will show that the assert is trivially
verified, hence I expect no code will be emitted for it.  And anyway,
that's an assert, NDEBUG controls it.

* data/c++.m4 (symbol_type): Turn into a subclass of
basic_symbol<by_type>.
Declare symbol constructors when variants are enabled.
* data/variant.hh (_b4_type_constructor_declare)
(_b4_type_constructor_define): Replace with...
(_b4_symbol_constructor_declare, _b4_symbol_constructor_def): these.
Generate symbol_type constructors.
* doc/bison.texi (Complete Symbols): Document.
* tests/types.at: Check.
2018-12-22 14:55:07 +01:00
Akim Demaille
1f4dd2671a c++: provide symbol constructors per type
On

    %token <int> FOO BAR

we currently generate make_FOO(int) and make_BAR(int).  However, in
order to factor their scanners, some users would also like to have
make_symbol(tok, int), where tok is FOO or BAR.  To ensure type
safety, add assertions that do check that value type and token type
match.  Bind this assertion to the parse.assert %define variable.

Suggested by Frank Heckenbach.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00034.html
Should also match expectations from Аскар Сафин.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00023.html

* data/variant.hh: Use b4_token_visible_if where applicable.
(_b4_type_constructor_declare, _b4_type_constructor_define): New.
Use them.
2018-12-22 13:05:28 +01:00
Akim Demaille
34c52d10ac c++: style changes
* data/c++.m4, data/variant.hh: Improve layout of the generated code.
Avoid casts.
(_b4_symbol_constructor_declare, _b4_symbol_constructor_define): Rename
as...
(_b4_token_maker_declare, _b4_token_maker_define): these.
* tests/types.at: Improve pair printing.
2018-12-22 13:05:28 +01:00
Akim Demaille
a8e66fc010 style: simplify tests
* tests/types.at: Simplify C++ instantiations.
2018-12-22 11:28:59 +01:00
Akim Demaille
98d199ccc8 c++: fix token constructors for types with commas
Bitten by macros, again.
See 680b715518.

* data/variant.hh (_b4_symbol_constructor_declare)
(_b4_symbol_constructor_define): Do not use user types, which can
include commas as in `std::pair<int, int>`, to macros.

* tests/local.at: Adjust the lex related macros to support the
case of token constructors.
* tests/types.at: Also check token constructors on types with commas.
2018-12-19 06:40:28 +01:00
Akim Demaille
8e5b1f40ae symbols: check more invalid declarations
* tests/input.at (Invalid %nterm uses): Rename as...
(Invalid symbol declarations): this.
Extend.
2018-12-16 12:27:28 +01:00
Akim Demaille
25b9eada8c symbols: check the previous commit
* tests/input.at (Symbol declarations): New.
2018-12-16 12:27:28 +01:00
Akim Demaille
1d5956f87f symbols: clean up their parsing
Prompted by Rici Lake.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00000.html

We have four classes of directives that declare symbols: %nterm,
%type, %token, and the family of %left etc.  Currently not all of them
support the possibility to have several type tags (`<type>`), and not
all of them support the fact of not having any type tag at all
(%type).  Let's unify this.

- %type
  POSIX Yacc specifies that %type is for nonterminals only.  However,
  some Bison users want to use it for both tokens and nterms
  (actually, Bison's own grammar does this in several places, e.g.,
  CHAR).  So it should accept char/string literals.

  As a consequence cannot be used to declare tokens with their alias:
  `%type foo "foo"` would be ambiguous (are we defining foo = "foo",
  or are these two different symbols?)

  POSIX specifies that it is OK to use %type without a type tag.  I'm
  not sure what it means, but we support it.

- %token
  Accept token declarations with number and string literal:
  (ID|CHAR) NUM? STRING?.

- %left, etc.
  They cannot be the same as %token, because we accept to declare the
  symbol with %token, and to then qualify its precedence with %left.
  Then `%left foo "foo"` would also be ambiguous: foo="foo", or two
  symbols.

  They cannot be simply a list of identifiers, but POSIX Yacc says we
  can declare token numbers here.  I personally think this is a bad
  idea, precedence management is tricky in itself and should not be
  cluttered with token declaration issues.

  We used to accept declaring a token number on a string literal here
  (e.g., `%left "token" 1`).  This is abnormal.  Either the feature is
  useful, and then it should be supported in %token, or it's useless
  and we should not support it in corner cases.

- %nterm
  Obviously cannot accept tokens, nor char/string literals.  Does not
  exist in POSIX Yacc, but since %type also works for terminals, it is
  a nice option to have.

* src/parse-gram.y: Avoid relying on side effects.  For instance, get
rid of current_type, rather, build the list of symbols and iterate
over it to assign the type.
It's not always possible/convenient.  For instance, we still use
current_class.
Prefer "decl" to "def", since in the rest of the implementation we
actually "declare" symbols, we don't "define" them.
(token_decls, token_decls_for_prec, symbol_decls, nterm_decls): New.
Use them for %token, %left, %type and %nterm.
* src/symlist.h, src/symlist.c (symbol_list_type_set): New.
* tests/regression.at b/tests/regression.at
(Token number in precedence declaration): We no longer accept
to give a number to string literals.
2018-12-16 12:27:28 +01:00
Akim Demaille
bc31dee0f7 tests: isolate test about Yacc warnings
* tests/input.at (Yacc warnings): New.
(AT_CHECK_UNUSED_VALUES): Remove checks about yacc.
2018-12-14 05:10:31 +01:00
Akim Demaille
465a47d46b parser: warn about string literals in Yacc mode
* src/scan-gram.l (scan_integer): Warn.
* tests/input.at (Yacc warnings on symbols): Check.
2018-12-14 05:10:31 +01:00
Akim Demaille
953a95695a parser: warn about hexadecimal token numbers in Yacc mode
* src/scan-gram.l (scan_integer): Warn.
* tests/input.at (Yacc warnings on symbols): Check.
2018-12-14 05:10:31 +01:00