Header lexy/dsl/capture.hpp
Branch rule lexy::dsl::capture
lexy/dsl/capture.hppnamespace 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.
- Requires
ruleis either a token rule orlexy::dsl::pwhere the production is a token production.- (Branch) Parsing
Parses
ruleunchanged.- Errors
All errors raised by
rule. The rule then fails ifrulehas failed.- Values
A
lexy::lexemewhose range covers everything consumed bytokenexcept any trailing whitespace. Then all values produced byrule.
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()); });
};Tip | Use the callback lexy::as_string to convert the lexy::lexeme to a string. |
Tip | In most cases, you should prefer lexy::dsl::identifier instead. |