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.cxx | |
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.cxx')
-rw-r--r-- | libbuild2/parser.cxx | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index fbf3bda..2cb51c6 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -212,6 +212,17 @@ namespace build2 }; void parser:: + reset () + { + pre_parse_ = false; + attributes_.clear (); + default_target_ = nullptr; + peeked_ = false; + replay_ = replay::stop; + replay_data_.clear (); + } + + void parser:: parse_buildfile (istream& is, const path_name& in, scope& root, scope& base) { lexer l (is, in); @@ -223,12 +234,13 @@ namespace build2 { path_ = &l.name (); lexer_ = &l; + root_ = &root; scope_ = &base; - pbase_ = scope_->src_path_; target_ = nullptr; prerequisite_ = nullptr; - default_target_ = nullptr; + + pbase_ = scope_->src_path_; enter_buildfile (*path_); // Needs scope_. @@ -249,11 +261,14 @@ namespace build2 { path_ = &l.name (); lexer_ = &l; + + root_ = nullptr; scope_ = &s; - pbase_ = scope_->src_path_; // Normally NULL. target_ = nullptr; prerequisite_ = nullptr; + pbase_ = scope_->src_path_; // Normally NULL. + token t; type tt; parse_variable (t, tt, var, kind); @@ -268,11 +283,14 @@ namespace build2 { path_ = &l.name (); lexer_ = &l; + + root_ = nullptr; scope_ = &s; - pbase_ = b; target_ = nullptr; prerequisite_ = nullptr; + pbase_ = b; + token t; type tt; value rhs (parse_variable_value (t, tt)); @@ -1968,9 +1986,9 @@ namespace build2 if (val.type != nullptr) untypify (val); - export_value_ = move (val).as<names> (); + export_value = move (val).as<names> (); - if (export_value_.empty ()) + if (export_value.empty ()) fail (l) << "empty value in export"; next_after_newline (t, tt); @@ -3675,7 +3693,7 @@ namespace build2 bool has (tt == type::lsbrace); if (!pre_parse_) - attributes_.push (attributes {has, l, {}}); + attributes_.push_back (attributes {has, l, {}}); if (!has) return make_pair (false, l); @@ -3727,7 +3745,7 @@ namespace build2 } if (!pre_parse_) - attributes_.top ().ats.emplace_back (move (n), move (v)); + attributes_.back ().ats.emplace_back (move (n), move (v)); if (tt == type::comma) next (t, tt); @@ -5592,18 +5610,20 @@ namespace build2 buildspec parser:: parse_buildspec (istream& is, const path_name& in) { - path_ = ∈ - // We do "effective escaping" and only for ['"\$(] (basically what's // necessary inside a double-quoted literal plus the single quote). // + path_ = ∈ lexer l (is, *path_, 1 /* line */, "\'\"\\$("); lexer_ = &l; - scope_ = root_ = &ctx.global_scope.rw (); - pbase_ = &work; // Use current working directory. + + root_ = &ctx.global_scope.rw (); + scope_ = root_; target_ = nullptr; prerequisite_ = nullptr; + pbase_ = &work; // Use current working directory. + // Turn on the buildspec mode/pairs recognition with '@' as the pair // separator (e.g., src_root/@out_root/exe{foo bar}). // |