c++: make operator() an alias to the parse function

* data/glr.cc, data/lalr1.cc (operator()): New.
* doc/bison.texi: Update.
This commit is contained in:
Akim Demaille
2018-10-23 18:42:37 +02:00
parent facfd9c406
commit f9bba892bd
4 changed files with 26 additions and 2 deletions

2
NEWS
View File

@@ -14,6 +14,8 @@ GNU Bison NEWS
Variant-based symbols in C++ should use emplace() rather than build().
In C++ parsers, parser::operator() is now a synonym for the parser::parse.
* Noteworthy changes in release 3.1.91 (2018-10-18) [beta]
** Bug fixes

View File

@@ -166,6 +166,12 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
{
}
int
]b4_parser_class_name[::operator() ()
{
return parse ();
}
int
]b4_parser_class_name[::parse ()
{
@@ -267,6 +273,10 @@ b4_percent_code_get([[requires]])[
]b4_parser_class_name[ (]b4_parse_param_decl[);
virtual ~]b4_parser_class_name[ ();
/// Parse. An alias for parse ().
/// \returns 0 iff parsing succeeded.
int operator() ();
/// Parse.
/// \returns 0 iff parsing succeeded.
virtual int parse ();

View File

@@ -190,6 +190,10 @@ m4_define([b4_shared_declarations],
]b4_parser_class_name[ (]b4_parse_param_decl[);
virtual ~]b4_parser_class_name[ ();
/// Parse. An alias for parse ().
/// \returns 0 iff parsing succeeded.
int operator() ();
/// Parse.
/// \returns 0 iff parsing succeeded.
virtual int parse ();
@@ -743,6 +747,12 @@ m4_if(b4_prefix, [yy], [],
return yyvalue == yytable_ninf_;
}
int
]b4_parser_class_name[::operator() ()
{
return parse ();
}
int
]b4_parser_class_name[::parse ()
{

View File

@@ -10714,8 +10714,10 @@ Build a new parser object. There are no arguments, unless
Instantiate a syntax-error exception.
@end deftypeop
@deftypemethod {parser} {int} parse ()
Run the syntactic analysis, and return 0 on success, 1 otherwise.
@deftypemethod {parser} {int} operator() ()
@deftypemethodx {parser} {int} parse ()
Run the syntactic analysis, and return 0 on success, 1 otherwise. Both
routines are equivalent, @code{operator()} being more C++ish.
@cindex exceptions
The whole function is wrapped in a @code{try}/@code{catch} block, so that