Skip to content

Commit

Permalink
Fix error detected in tests of token caching introduced in doc exampl…
Browse files Browse the repository at this point in the history
…es. Make

sure not to copy tokens_view within the *parse() call graph.

See #202.
  • Loading branch information
tzlaine committed Nov 30, 2024
1 parent 92c4993 commit 3176c6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
18 changes: 9 additions & 9 deletions include/boost/parser/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2520,7 +2520,7 @@ namespace boost { namespace parser {
}

template<typename R>
constexpr auto make_input_subrange(R && r) noexcept
constexpr decltype(auto) make_input_subrange(R && r) noexcept
{
using r_t = remove_cv_ref_t<R>;
using value_type = range_value_t<r_t>;
Expand Down Expand Up @@ -8632,7 +8632,7 @@ namespace boost { namespace parser {
}
}
} else {
auto r = detail::make_input_subrange(first, last);
auto && r = detail::make_input_subrange(first, last);
auto f = r.begin();
auto const l = r.end();
auto _ = detail::scoped_base_assign(first, f);
Expand Down Expand Up @@ -8727,7 +8727,7 @@ namespace boost { namespace parser {
tokens_view);
}
} else {
auto r = detail::make_input_subrange(first, last);
auto && r = detail::make_input_subrange(first, last);
auto f = r.begin();
auto const l = r.end();
auto _ = detail::scoped_base_assign(first, f);
Expand Down Expand Up @@ -8868,7 +8868,7 @@ namespace boost { namespace parser {
#endif
{
detail::attr_reset reset(attr);
auto r_ = detail::make_input_subrange(r);
auto && r_ = detail::make_input_subrange(r);
auto first = r_.begin();
auto const last = r_.end();
return reset = detail::if_full_parse(
Expand Down Expand Up @@ -8966,7 +8966,7 @@ namespace boost { namespace parser {
// clang-format on
#endif
{
auto r_ = detail::make_input_subrange(r);
auto && r_ = detail::make_input_subrange(r);
auto first = r_.begin();
auto const last = r_.end();
return detail::if_full_parse(
Expand Down Expand Up @@ -9073,7 +9073,7 @@ namespace boost { namespace parser {
!detail::is_token_iter_v<detail::iterator_t<R>>,
"You cannot use a skipper when parsing tokens.");
detail::attr_reset reset(attr);
auto r_ = detail::make_input_subrange(r);
auto && r_ = detail::make_input_subrange(r);
auto first = r_.begin();
auto const last = r_.end();
return reset = detail::if_full_parse(
Expand Down Expand Up @@ -9179,7 +9179,7 @@ namespace boost { namespace parser {
static_assert(
!detail::is_token_iter_v<detail::iterator_t<R>>,
"You cannot use a skipper when parsing tokens.");
auto r_ = detail::make_input_subrange(r);
auto && r_ = detail::make_input_subrange(r);
auto first = r_.begin();
auto const last = r_.end();
return detail::if_full_parse(
Expand Down Expand Up @@ -9290,7 +9290,7 @@ namespace boost { namespace parser {
// clang-format on
#endif
{
auto r_ = detail::make_input_subrange(r);
auto && r_ = detail::make_input_subrange(r);
auto first = r_.begin();
auto const last = r_.end();
return detail::if_full_parse(
Expand Down Expand Up @@ -9406,7 +9406,7 @@ namespace boost { namespace parser {
static_assert(
!detail::is_token_iter_v<detail::iterator_t<R>>,
"You cannot use a skipper when parsing tokens.");
auto r_ = detail::make_input_subrange(r);
auto && r_ = detail::make_input_subrange(r);
auto first = r_.begin();
auto const last = r_.end();
return detail::if_full_parse(
Expand Down
8 changes: 6 additions & 2 deletions test/lexer_and_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ int main()
auto parser = identifier >> '=' >> true_false >> ';';
std::vector<bp::token<char>> cache;
auto r = "foo = false;" | bp::to_tokens(adobe_lexer, std::ref(cache));
bp::parse(r, parser);
auto result = bp::parse(r, parser);
BOOST_TEST(std::get<0>(*result) == "foo");
BOOST_TEST(std::get<1>(*result) == false);
BOOST_TEST(cache.size() == 4u);
}

Expand All @@ -109,7 +111,9 @@ int main()
auto parser = identifier >> '=' > true_false >> ';';
std::vector<bp::token<char>> cache;
auto r = "foo = false;" | bp::to_tokens(adobe_lexer, std::ref(cache));
bp::parse(r, parser);
auto result = bp::parse(r, parser);
BOOST_TEST(std::get<0>(*result) == "foo");
BOOST_TEST(std::get<1>(*result) == false);
BOOST_TEST(cache.size() == 2u);
}

Expand Down

0 comments on commit 3176c6f

Please sign in to comment.