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

In opt_parser, don't forget to clear the attribute if the subparser fails.

Fixes #279
This commit is contained in:
Zach Laine
2025-10-13 17:46:27 -05:00
parent 159472ac6e
commit 41e891dc95
2 changed files with 20 additions and 0 deletions

View File

@@ -3235,6 +3235,8 @@ namespace boost { namespace parser {
//[ opt_parser_gen_attr_path
parser_.call(first, last, context, skip, flags, success, retval);
if (!success)
retval = Attribute();
success = true;
//]
}

View File

@@ -344,6 +344,23 @@ void github_issue_248()
}
}
void github_issue_279()
{
namespace bp = boost::parser;
constexpr auto condition_clause = bp::lit(U"while") >
bp::lit(U"someexpression") >> bp::attr(true);
constexpr auto do_statement =
bp::lexeme[bp::lit(U"do") >> &bp::ws] > -condition_clause > bp::eol;
auto const result = bp::parse(
U"do\n", do_statement, bp::blank, bp::trace::off);
BOOST_TEST(result);
std::optional<bool> const & condition = result.value();
BOOST_TEST(!condition.has_value());
}
int main()
{
@@ -356,5 +373,6 @@ int main()
github_issue_209();
github_issue_223();
github_issue_248();
github_issue_279();
return boost::report_errors();
}