Header lexy/dsl/capture.hpp
Branch rule lexy::dsl::capture
lexy/dsl/capture.hpp
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.
- Requires
rule
is either a token rule orlexy::dsl::p
where the production is a token production.- (Branch) Parsing
Parses
rule
unchanged.- Errors
All errors raised by
rule
. The rule then fails ifrule
has failed.- Values
A
lexy::lexeme
whose range covers everything consumed bytoken
except 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. |