Skip to content

Commit

Permalink
Address TODO about non-obviously ill-formed code using merge[].
Browse files Browse the repository at this point in the history
  • Loading branch information
tzlaine committed Jan 29, 2024
1 parent b58b3a0 commit 68c33a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 13 additions & 1 deletion doc/tutorial.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,19 @@ whether they are inside or outside the _sep_ directive; you force each
subparser to have a separate attribute.

The rules for _merge_ and _sep_ overrule the steps of the algorithm described
above for combining the attributes of a sequence parser.
above for combining the attributes of a sequence parser. Consider an example.

namespace bp = boost::parser;
constexpr auto parser =
bp::char_ >> bp::merge[(bp::string("abc") >> bp::char_ >> bp::char_) >> bp::string("ghi")];

You might think that `_ATTR_np_(parser)` would be `bp::tuple<char,
std::string>`. It is not. The parser above does not even compile. Since we
created a merge group above, we disabled the default behavior in which the
`char_` parsers would have collapsed into the `string` parser that preceded
them. Since they are all treated as separate entities, and since they have
different attribute types, the use of _merge_ is an error.


[heading Other directives that affect attribute generation]

Expand Down
3 changes: 1 addition & 2 deletions test/merge_separate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ TEST(merge_separate, merge_)
*result, detail::hl::make_tuple('z', std::string("abcdefghi")));
}
}
#if 0 // TODO: Document that this does not work, and why (flattening), and how
// making a rule for the parethesized part is a fix.
#if 0 // Intentionally ill-formed.
{
constexpr auto parser =
char_ >> merge[(string("abc") >> char_ >> char_) >> string("ghi")];
Expand Down

0 comments on commit 68c33a0

Please sign in to comment.