From dfd19b9637c6b917a40413a57b391d7ff27f50da Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 26 Mar 2020 07:03:50 +0200 Subject: Make buildfile parser reset'able Note that the testscript parser (which derives from the buildfile parser) is (still) not reset'able (this functionality is currently not needed so why complicate things). --- libbuild2/parser.hxx | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'libbuild2/parser.hxx') diff --git a/libbuild2/parser.hxx b/libbuild2/parser.hxx index ba707da..6d78ce1 100644 --- a/libbuild2/parser.hxx +++ b/libbuild2/parser.hxx @@ -4,8 +4,6 @@ #ifndef LIBBUILD2_PARSER_HXX #define LIBBUILD2_PARSER_HXX -#include - #include #include #include @@ -60,9 +58,22 @@ namespace build2 parse_export_stub (istream& is, const path_name& name, scope& r, scope& b) { parse_buildfile (is, name, r, b); - return move (export_value_); + return move (export_value); } + // The above functions may be called again on the same parser instance + // after a reset. + // + void + reset (); + + // Ad hoc parsing results for some cases. + // + // Note that these are not touched by reset(). + // + public: + names export_value; + // Recursive descent parser. // protected: @@ -246,13 +257,13 @@ namespace build2 attributes_pop () { assert (!pre_parse_); - attributes r (move (attributes_.top ())); - attributes_.pop (); + attributes r (move (attributes_.back ())); + attributes_.pop_back (); return r; } attributes& - attributes_top () {return attributes_.top ();} + attributes_top () {return attributes_.back ();} // Source a stream optionnaly entering it as a buildfile and performing // the default target processing. @@ -703,6 +714,10 @@ namespace build2 protected: const fail_mark fail; + // Parser state. + // + // NOTE: remember to update reset() if adding anything here. + // protected: context& ctx; stage stage_; @@ -719,10 +734,9 @@ namespace build2 const dir_path* pbase_ = nullptr; // Current pattern base directory. - std::stack attributes_; + small_vector attributes_; - target* default_target_; - names export_value_; + target* default_target_ = nullptr; replay_token peek_; bool peeked_ = false; -- cgit v1.1