@@ -348,22 +348,36 @@ void github_issue_248()
348348namespace github_issue_268_ {
349349 namespace bp = boost::parser;
350350 constexpr bp::rule<struct name , std::string_view> name = " name" ;
351- auto name_def = bp::string_view[bp::lexeme[+(bp::lower | bp::upper | bp::digit | bp::char_(" _" ))]];
351+ auto name_def = bp::string_view[bp::lexeme[+(
352+ bp::lower | bp::upper | bp::digit | bp::char_(" _" ))]];
352353 BOOST_PARSER_DEFINE_RULES (name)
353354 constexpr bp::rule<struct qd_vec, std::vector<double>> qd_vec = "qd_vec";
354- auto qd_vec_def = bp::lit(" \" " ) >> bp::double_ % (bp::lit(" ," ) | (bp::lit(" \" " ) >> bp::lit (" ," ) >> bp::lit(" \" " ))) >> bp::lit(' \" ' );
355+ auto qd_vec_def = bp::lit(" \" " ) >>
356+ bp::double_ %
357+ (bp::lit(" ," ) |
358+ (bp::lit(" \" " ) >> bp::lit (" ," ) >> bp::lit(" \" " ))) >>
359+ bp::lit(' \" ' );
355360 BOOST_PARSER_DEFINE_RULES (qd_vec)
356361 struct lu_table_template_1
357362 {
358363 std::vector<double > index_1;
359364 std::string_view variable_1;
360365 };
361- constexpr boost::parser::rule<struct lu_table_template_1_tag , lu_table_template_1> lu_table_template_1_rule = " lu_table_template_1" ;
362- auto lu_table_template_1_rule_def = (bp::lit(" index_1" ) >> ' (' >> qd_vec >> ' )' >> ' ;' ) >> (bp::lit(" variable_1" ) >> ' :' >> name >> ' ;' );
366+ constexpr boost::parser::
367+ rule<struct lu_table_template_1_tag , lu_table_template_1>
368+ lu_table_template_1_rule = " lu_table_template_1" ;
369+ auto lu_table_template_1_rule_def = (bp::lit(" index_1" ) >> ' (' >> qd_vec >>
370+ ' )' >> ' ;' ) >>
371+ (bp::lit(" variable_1" ) >> ' :' >> name >>
372+ ' ;' );
363373 BOOST_PARSER_DEFINE_RULES (lu_table_template_1_rule)
364374
365- constexpr boost::parser::rule<struct lu_table_template_1_permut_tag, lu_table_template_1> lu_table_template_1_permut_rule = "lu_table_template_1";
366- auto lu_table_template_1_permut_rule_def = (bp::lit(" index_1" ) >> ' (' >> qd_vec >> ' )' >> ' ;' ) || (bp::lit(" variable_1" ) >> ' :' >> name >> ' ;' );
375+ constexpr boost::parser::
376+ rule<struct lu_table_template_1_permut_tag, lu_table_template_1>
377+ lu_table_template_1_permut_rule = "lu_table_template_1";
378+ auto lu_table_template_1_permut_rule_def =
379+ (bp::lit(" index_1" ) >> ' (' >> qd_vec >> ' )' >> ' ;' ) ||
380+ (bp::lit(" variable_1" ) >> ' :' >> name >> ' ;' );
367381 BOOST_PARSER_DEFINE_RULES (lu_table_template_1_permut_rule)
368382}
369383#endif
@@ -377,22 +391,32 @@ void github_issue_268()
377391
378392 auto const def_result = bp::parse (
379393 inputstring, lu_table_template_1_rule_def, bp::blank, bp::trace::off);
380- std::cout<< " seq_parser generates this type:\n " << typeid (def_result.value ()).name () << std::endl;
394+ std::cout << " seq_parser generates this type:\n "
395+ << typeid (def_result.value ()).name () << std::endl;
381396 BOOST_TEST (def_result);
382397
383398 auto const permut_def_result = bp::parse (
384- inputstring, lu_table_template_1_permut_rule_def, bp::blank, bp::trace::off);
385- std::cout<< " permut_parser generates this type:\n " << typeid (permut_def_result.value ()).name () << std::endl;
399+ inputstring,
400+ lu_table_template_1_permut_rule_def,
401+ bp::blank,
402+ bp::trace::off);
403+ std::cout << " permut_parser generates this type:\n "
404+ << typeid (permut_def_result.value ()).name () << std::endl;
386405 BOOST_TEST (permut_def_result);
387406
388407 auto const result = bp::parse (
389408 inputstring, lu_table_template_1_rule, bp::blank, bp::trace::off);
390- std::cout<< " seq_parser in rule generates this type:\n " << typeid (result.value ()).name () << std::endl;
409+ std::cout << " seq_parser in rule generates this type:\n "
410+ << typeid (result.value ()).name () << std::endl;
391411 BOOST_TEST (result);
392412
393413 auto const permut_result = bp::parse (
394- inputstring, lu_table_template_1_permut_rule, bp::blank, bp::trace::off);
395- std::cout<< " permut_parser generates this type:\n " << typeid (permut_result.value ()).name () << std::endl;
414+ inputstring,
415+ lu_table_template_1_permut_rule,
416+ bp::blank,
417+ bp::trace::off);
418+ std::cout << " permut_parser generates this type:\n "
419+ << typeid (permut_result.value ()).name () << std::endl;
396420 BOOST_TEST (permut_result);
397421#endif
398422}
@@ -401,17 +425,80 @@ void github_issue_279()
401425{
402426 namespace bp = boost::parser;
403427
404- constexpr auto condition_clause = bp::lit (U" while" ) >
405- bp::lit (U" someexpression" ) >> bp::attr (true );
428+ {
429+ constexpr auto condition_clause =
430+ bp::lit (U" while" ) > bp::lit (U" someexpression" ) >> bp::attr (true );
406431
407- constexpr auto do_statement =
408- bp::lexeme[bp::lit (U" do" ) >> &bp::ws] > -condition_clause > bp::eol;
432+ constexpr auto do_statement =
433+ bp::lexeme[bp::lit (U" do" ) >> &bp::ws] > -condition_clause > bp::eol;
409434
410- auto const result = bp::parse (
411- U" do\n " , do_statement, bp::blank, bp::trace::off);
435+ auto const result =
436+ bp::parse (U" do\n " , do_statement, bp::blank, bp::trace::off);
437+ BOOST_TEST (result);
438+ std::optional<bool > const & condition = result.value ();
439+ BOOST_TEST (!condition.has_value ());
440+ }
441+
442+ {
443+ constexpr auto condition_clause =
444+ bp::lit (U" while" ) > bp::lit (U" someexpression" ) >> bp::attr (true );
445+
446+ constexpr auto do_statement_reverse =
447+ -condition_clause > bp::lexeme[bp::lit (U" do" ) >> &bp::ws] > bp::eol;
448+
449+ auto const result =
450+ bp::parse (U" do\n " , do_statement_reverse, bp::blank, bp::trace::off);
451+ BOOST_TEST (result);
452+ std::optional<bool > const & condition = result.value ();
453+ BOOST_TEST (!condition.has_value ());
454+ }
455+ }
456+
457+ namespace github_issue_285_ {
458+ namespace bp = boost::parser;
459+
460+ struct Content
461+ {
462+ ~Content ()
463+ {
464+ int setbreakpointhere = 0 ;
465+ (void )setbreakpointhere;
466+ }
467+ };
468+ constexpr bp::rule<struct content_tag , std::shared_ptr<Content>> content =
469+ " content" ;
470+ constexpr auto content_action = [](auto & ctx) {
471+ std::shared_ptr<Content> & result = _val (ctx);
472+ result = std::make_shared<Content>();
473+ };
474+ constexpr auto content_def =
475+ (bp::lit(U" content" ) >> bp::eol)[content_action];
476+ BOOST_PARSER_DEFINE_RULES (content);
477+ }
478+
479+ void github_issue_285 ()
480+ {
481+ using namespace github_issue_285_ ;
482+ namespace bp = boost::parser;
483+
484+ constexpr auto prolog = bp::lit (U" prolog" ) >> bp::eol;
485+
486+ constexpr auto epilog =
487+ bp::no_case[bp::lexeme[bp::lit (U" epi" ) >> bp::lit (U" log" )]] >> bp::eol;
488+
489+ constexpr auto full_parser = prolog >> content >> epilog;
490+
491+ std::string teststring =
492+ " prolog\n "
493+ " content\n "
494+ " epilog\n " ;
495+
496+ // "content" produces a shared_ptr with the result.
497+ // The "epilog" parser must not delete the result.
498+
499+ auto const result = bp::parse (teststring, full_parser, bp::blank);
412500 BOOST_TEST (result);
413- std::optional<bool > const & condition = result.value ();
414- BOOST_TEST (!condition.has_value ());
501+ BOOST_TEST (result.value ().get () != nullptr );
415502}
416503
417504
@@ -428,5 +515,6 @@ int main()
428515 github_issue_248 ();
429516 github_issue_268 ();
430517 github_issue_279 ();
518+ github_issue_285 ();
431519 return boost::report_errors ();
432520}
0 commit comments