2
0
mirror of https://github.com/boostorg/parser.git synced 2026-01-19 04:22:13 +00:00

Parse the attribute of quoted_string into a temporary, and assign at the end,

if successful.  This makes the code well-formed when the attribute type is an
optional.

Addresses PR #290.
This commit is contained in:
Zach Laine
2025-11-15 16:39:34 -06:00
parent 6826f957a1
commit 885595f7bd
2 changed files with 19 additions and 3 deletions

View File

@@ -7635,9 +7635,10 @@ namespace boost { namespace parser {
auto const prev_first = first;
auto append = [&retval,
std::string temp;
auto append = [&temp,
gen_attrs = detail::gen_attrs(flags)](auto & ctx) {
detail::move_back(retval, _attr(ctx), gen_attrs);
detail::move_back(temp, _attr(ctx), gen_attrs);
};
auto quote_ch = [&]() {
@@ -7695,7 +7696,10 @@ namespace boost { namespace parser {
detail::disable_skip(flags),
success);
if (!success) {
if (success) {
if (detail::gen_attrs(flags))
detail::assign(retval, std::move(temp));
} else {
retval = Attribute();
first = prev_first;
}

View File

@@ -501,6 +501,17 @@ void github_issue_285()
BOOST_TEST(result.value().get() != nullptr);
}
void github_pr_290()
{
namespace bp = boost::parser;
auto const pTest = bp::lit("TEST:") > -bp::quoted_string;
auto result = bp::parse("TEST: \"foo\"", pTest, bp::blank);
BOOST_TEST(result);
BOOST_TEST(*result == "foo");
}
int main()
{
@@ -516,5 +527,6 @@ int main()
github_issue_268();
github_issue_279();
github_issue_285();
github_pr_290();
return boost::report_errors();
}