yacc.c: yypstate_expected_tokens

In push parsers, when asking for the list of expected tokens at some
point, it makes no sense to build a yyparse_context_t: the yypstate
alone suffices (the only difference being the lookahead).  Instead of
forcing the user to build a useless shell around yypstate, let's offer
yypstate_expected_tokens.

See https://lists.gnu.org/r/bison-patches/2020-03/msg00025.html.

* data/skeletons/yacc.c (yypstate): Declare earlier, so that we can
use it for...
(yypstate_expected_tokens): this new function, when in push parsers.
Adjust dependencies.
* examples/c/bistromathic/parse.y: Simplify: use
yypstate_expected_tokens.
Style fixes.
Reduce scopes (reported by Joel E. Denny).
This commit is contained in:
Akim Demaille
2020-03-08 17:31:28 +01:00
parent 0c3dd3a669
commit 44ac18d136
3 changed files with 61 additions and 34 deletions

16
NEWS
View File

@@ -75,6 +75,16 @@ GNU Bison NEWS
the translated symbol (i.e., it returns '_("variable")' rather that
'"variable"').
*** List of expected tokens (yacc.c)
At any point during parsing (including even before submitting the first
token), push parsers may now invoke yypstate_expected_tokens to get the
list of possible tokens. This feature can be used to propose
autocompletion (see below the "bistromathic" example).
It makes little sense to use this feature without enabling LAC (lookahead
correction).
*** Modernize display of explanatory statements in diagnostics
Since Bison 2.7, output was indented four spaces for explanatory
@@ -106,9 +116,9 @@ GNU Bison NEWS
A new C example, bistromathic, is a fully featured interactive calculator
using many Bison features: pure interface, push parser, autocompletion
based on the current parser state (using yyexpected_tokens), location
tracking, internationalized custom error messages, lookahead-correction,
rich debug traces, etc.
based on the current parser state (using yypstate_expected_tokens),
location tracking, internationalized custom error messages, lookahead
correction, rich debug traces, etc.
* Noteworthy changes in release 3.5.3 (2020-03-08) [stable]