Header lexy/dsl/capture.hpp

Branch rule lexy::dsl::capture

namespace lexy::dsl
    constexpr branch-rule auto capture(rule auto rule);

capture is a branch rule that parses rule capturing everything it has consumed but excluding whitespace as a value.


rule is either a token rule or lexy::dsl::p  where the production is a token production.

(Branch) Parsing

Parses rule unchanged.


All errors raised by rule. The rule then fails if rule has failed.


A lexy::lexeme  whose range covers everything consumed by token except any trailing whitespace. Then all values produced by rule.

Example 1. Get a single code point
// The type of a lexy::lexeme depends on the input.
using lexeme = lexy_ext::compiler_explorer_lexeme;

struct production
    static constexpr auto rule = dsl::capture(dsl::code_point);

    // Same as `lexy::as_string<std::string>`.
    static constexpr auto value = lexy::callback<std::string>(
        [](lexeme lex) { return std::string(lex.begin(), lex.end()); });
Use the callback lexy::as_string  to convert the lexy::lexeme  to a string.
In most cases, you should prefer lexy::dsl::identifier  instead.

See also