Header lexy/dsl/sequence.hpp

Rule lexy::dsl::operator+

lexy/dsl/sequence.hpp
namespace lexy::dsl
{
    constexpr rule auto operator+(rule auto lhs, rule auto rhs);
}

operator+ (sequence) is a rule that parses multiple rules one after the other.

Parsing

Parses lhs, then parses rhs.

Errors

All errors raised by lhs and/or rhs. The rule fails if either of them has failed.

Values

All values produced from rhs followed by all values produced by rhs.

Example 1. Sequence rule is used practically all the time
struct name
{
    static constexpr auto rule
        // One or more alpha numeric characters, underscores or hyphens.
        = dsl::identifier(dsl::unicode::alnum / dsl::lit_c<'_'> / dsl::lit_c<'-'>);
};

struct production
{
    // Allow arbitrary spaces between individual tokens.
    static constexpr auto whitespace = dsl::ascii::space;

    static constexpr auto rule = [] {
        auto greeting = LEXY_LIT("Hello");
        return greeting + dsl::p<name> + dsl::exclamation_mark + dsl::eof;
    }();
};