From f9bba892bdf4b69ab4d4d20ad11f4c2427f97dec Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 23 Oct 2018 18:42:37 +0200 Subject: [PATCH] c++: make operator() an alias to the parse function * data/glr.cc, data/lalr1.cc (operator()): New. * doc/bison.texi: Update. --- NEWS | 2 ++ data/glr.cc | 10 ++++++++++ data/lalr1.cc | 10 ++++++++++ doc/bison.texi | 6 ++++-- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 7ffe90ff..6aa017cd 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/data/glr.cc b/data/glr.cc index cc228995..0401b849 100644 --- a/data/glr.cc +++ b/data/glr.cc @@ -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 (); diff --git a/data/lalr1.cc b/data/lalr1.cc index 984be33a..f38015ba 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -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 () { diff --git a/doc/bison.texi b/doc/bison.texi index 89e2673a..ac2165ed 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -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