parsi/fn/repeated.hpp

namespace parsi

Functions

template<std::size_t Min = 0, std::size_t Max = std::numeric_limits<std::size_t>::max(), is_parser F>
constexpr auto repeat(F &&parser) noexcept -> fn::Repeated<std::remove_cvref_t<F>, Min, Max>

Creates a repeated parser combinator, a combinator which combines the given parser repeatedly for a given minimum and maximum times.

By default, the range is from 0 to almost infinite, expecting the parser to be repeated from none at all to any amount of times.

See also

fn::Repeated

template<is_parser F>
constexpr auto repeat(F &&parser, std::size_t count) noexcept -> fn::RepeatedRanged<std::remove_cvref_t<F>>

Creates a parser that repeats the given parser with itself consecutively for exactly count times.

template<is_parser F>
constexpr auto repeat(F &&parser, std::size_t min, std::size_t max) noexcept -> fn::RepeatedRanged<std::remove_cvref_t<F>>

Creates a parser that repeats the given parser with itself consecutively for at least min times and maximum max times.

If the parser can successfully parse the stream consecutively within min and max range, then the parsing will be valid, otherwise parsing will fail.

namespace fn
template<is_parser F, std::size_t Min = 0, std::size_t Max = std::numeric_limits<std::size_t>::max()>
struct Repeated
#include <repeated.hpp>

A parser combinator that repeats the parser on stream for a Min up to Max times consecutively.

The parser must succeed to consecutively parse the stream for at least Min times and at most Max times, otherwise it will result in failure.

Min and Max are compile-time for optimization purposes.

Public Functions

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

Public Members

std::remove_cvref_t<F> parser

Private Static Functions

static inline constexpr auto apply_loop(const auto &parser, Stream stream) noexcept -> Result

the generic/general unspecialized loop.

template<is_parser F>
struct RepeatedRanged
#include <repeated.hpp>

A parser combinator that repeats the parser on stream for a range of miniumum and maximum count consecutively.

The parser must succeed to consecutively parse the stream for at least min times and at most max times, otherwise it will fail.

Public Functions

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

Public Members

std::remove_cvref_t<F> parser
std::size_t min = 0
std::size_t max = std::numeric_limits<std::size_t>::max()