Header lexy/dsl/member.hpp
Rule lexy::dsl::member
lexy/dsl/member.hppnamespace lexy
{
    template <typename Fn>
    struct member {};
}
namespace lexy::dsl
{
    class member-dsl // note: not a rule itself
    {
    public:
        constexpr rule        auto operator=(rule        auto rule);
        constexpr branch-rule auto operator=(branch-rule auto rule);
    };
    template <auto MemberPtr>
    constexpr member-dsl member;
}
#define LEXY_MEM(Name) lexy::dsl::member<...>member is a rule that can be used to specify a member of an aggregate that will receive the resulting value a rule.
A rule is formed by writing member<MemberPtr> = rule.
- Requires
- MemberPtris a member point of some aggregate type- Aggregate.
- ruleproduces exactly one value.
 
- (Branch) Parsing
- Parses - rule.
- Errors
- All errors raised by - rule. The rule then fails if- rulehas failed.
- Values
- Two values. The first is a value of type - lexy::member<Fn>{}. Here,- Fnis a default constructible function object that takes two arguments: a reference to an- Aggregateobject and the value of- rule. When invoked, it will set the member described- MemberPtrof the- Aggregateobject to the value of- rule. The second is the value- rulehas produced.
The macro version LEXY_MEM(member) = rule behaves identical, except that member is not a member pointer but the name of a member.
The resulting Fn can take an arbitrary aggregate type and will assign the member with that name.
It is designed to be used with lexy::as_aggregate as the callback.
struct point
{
    int x, y;
};
struct production
{
    static constexpr auto rule = [] {
        auto value = dsl::integer<int>;
        // Parse an integer into the x/y member of point.
        auto x_coord = (dsl::member<& point::x> = value);
        auto y_coord = (dsl::member<& point::y> = value);
        return x_coord + dsl::comma + y_coord;
    }();
    // `lexy::as_aggregate` accepts the `lexy::member<Fn>` + value pairs.
    static constexpr auto value = lexy::as_aggregate<point>;
};| Tip | The memberrule works good in combination withlexy::dsl::combinationwhere rules are parsed in an arbitrary order. |