diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-03-26 07:03:50 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-03-26 07:09:22 +0200 |
commit | dfd19b9637c6b917a40413a57b391d7ff27f50da (patch) | |
tree | 9855eacfe9d3f7b2099d8019aec6ee93cbb977d7 /libbuild2/parser.hxx | |
parent | 0588e48ac1499388f4d2ad5bc03fe9f63782f161 (diff) |
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).
Diffstat (limited to 'libbuild2/parser.hxx')
-rw-r--r-- | libbuild2/parser.hxx | 32 |
1 files changed, 23 insertions, 9 deletions
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 <stack> - #include <libbuild2/types.hxx> #include <libbuild2/forward.hxx> #include <libbuild2/utility.hxx> @@ -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> attributes_; + small_vector<attributes, 2> attributes_; - target* default_target_; - names export_value_; + target* default_target_ = nullptr; replay_token peek_; bool peeked_ = false; |