File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -2809,6 +2809,8 @@ namespace boost { namespace parser {
28092809 {
28102810 if constexpr (is_nope_v<ParserAttr>) {
28112811 return nope{};
2812+ } else if constexpr (is_optional_v<ParserAttr>) {
2813+ return ParserAttr{};
28122814 } else {
28132815 using value_type = range_value_t <GivenContainerAttr>;
28142816 return std::conditional_t <
Original file line number Diff line number Diff line change @@ -258,6 +258,41 @@ void github_issue_209()
258258 std::end (bp::detail::char_set<detail::upper_case_chars>::chars)));
259259}
260260
261+ void github_issue_223 ()
262+ {
263+ namespace bp = boost::parser;
264+
265+ // failing case
266+ {
267+ std::vector<char > v;
268+ const auto parser = *(' x' | bp::char_ (' y' ));
269+ bp::parse (" xy" , parser, bp::ws, v);
270+
271+ BOOST_TEST (v.size () == 1 );
272+ BOOST_TEST (v == std::vector<char >({' y' }));
273+
274+ std::cout << " v.size()=" << v.size () << " \n " ;
275+ for (auto c : v) {
276+ std::cout << std::hex << (int )c << ' ' ;
277+ }
278+ std::cout << " \n " ;
279+
280+ // the assert fails since there are two elements in the vector: '\0'
281+ // and 'y'. Seems pretty surprising to me
282+ }
283+
284+ // working case
285+ {
286+ const auto parser = *(' x' | bp::char_ (' y' ));
287+ const auto result = bp::parse (" xy" , parser, bp::ws);
288+
289+ BOOST_TEST (result->size () == 1 );
290+ BOOST_TEST (*result == std::vector<std::optional<char >>({' y' }));
291+
292+ // success, the vector has only one 'y' element
293+ }
294+ }
295+
261296
262297int main ()
263298{
@@ -268,5 +303,6 @@ int main()
268303 github_issue_90 ();
269304 github_issue_125 ();
270305 github_issue_209 ();
306+ github_issue_223 ();
271307 return boost::report_errors ();
272308}
You can’t perform that action at this time.
0 commit comments