Skip to content

Commit 41e891d

Browse files
committed
In opt_parser, don't forget to clear the attribute if the subparser fails.
Fixes #279
1 parent 159472a commit 41e891d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

include/boost/parser/parser.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3235,6 +3235,8 @@ namespace boost { namespace parser {
32353235

32363236
//[ opt_parser_gen_attr_path
32373237
parser_.call(first, last, context, skip, flags, success, retval);
3238+
if (!success)
3239+
retval = Attribute();
32383240
success = true;
32393241
//]
32403242
}

test/github_issues.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,23 @@ void github_issue_248()
344344
}
345345
}
346346

347+
void github_issue_279()
348+
{
349+
namespace bp = boost::parser;
350+
351+
constexpr auto condition_clause = bp::lit(U"while") >
352+
bp::lit(U"someexpression") >> bp::attr(true);
353+
354+
constexpr auto do_statement =
355+
bp::lexeme[bp::lit(U"do") >> &bp::ws] > -condition_clause > bp::eol;
356+
357+
auto const result = bp::parse(
358+
U"do\n", do_statement, bp::blank, bp::trace::off);
359+
BOOST_TEST(result);
360+
std::optional<bool> const & condition = result.value();
361+
BOOST_TEST(!condition.has_value());
362+
}
363+
347364

348365
int main()
349366
{
@@ -356,5 +373,6 @@ int main()
356373
github_issue_209();
357374
github_issue_223();
358375
github_issue_248();
376+
github_issue_279();
359377
return boost::report_errors();
360378
}

0 commit comments

Comments
 (0)