Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the master branch, built from commit 68cc668162.
PrevUpHomeNext
grammar::range_rule (1 of 2 overloads)

Match a repeating number of elements.

Synopsis

Defined in header <boost/url/grammar/range_rule.hpp>

template<
    class Rule>
constexpr implementation-defined
range_rule(
    Rule next,
    std::size_t N = 0,
    std::size_t M = std::size_t(-1));
Description

Elements are matched using the passed rule.

Normally when the rule returns an error, the range ends and the input is rewound to one past the last character that matched successfully. However, if the rule returns the special value error::end_of_range, the input is not rewound. This allows for rules which consume input without producing elements in the range. For example, to relax the grammar for a comma-delimited list by allowing extra commas in between elements.

Value Type
using value_type = range< typename Rule::value_type >;
Example

Rules are used with the function parse.

// range    = 1*( ";" token )

system::result< range<core::string_view> > rv = parse( ";alpha;xray;charlie" ,
    range_rule(
        tuple_rule(
            squelch( delim_rule( ';' ) ),
            token_rule( alpha_chars ) ),
        1 ) );
BNF
range        = <N>*<M>next
Specification
Parameters

Name

Description

next

The rule to use for matching each element. The range extends until this rule returns an error.

N

The minimum number of elements for the range to be valid. If omitted, this defaults to zero.

M

The maximum number of elements for the range to be valid. If omitted, this defaults to unlimited.

See Also

alpha_chars, delim_rule, error::end_of_range, parse, range, tuple_rule, squelch.

Convenience header <boost/url/grammar.hpp>


PrevUpHomeNext