parsi/fn/extract.hpp

namespace parsi

Functions

template<is_parser F, std::invocable<std::string_view> G>
constexpr auto extract(F &&parser, G &&visitor) noexcept -> fn::Extract<std::remove_cvref_t<F>, std::remove_cvref_t<G>>

Creates a parser that extracts (non-owning) the portion that was successfully parsed with the given parser, and passes the subspan portion to the given visitor.

See also

fn::Extract

namespace fn
template<is_parser F, std::invocable<std::string_view> G>
struct Extract
#include <extract.hpp>

Visits the sub portion of the stream that was successfully parsed via parser by passing the subspan/substr to the visitor, and if the parser fails, the visitor won’t be called.

The visitor can optionally return a boolean to indicate success or failure of the parser.

Public Functions

inline constexpr auto operator()(Stream stream) const noexcept -> Result

Public Members

std::remove_cvref_t<F> parser
std::remove_cvref_t<G> visitor