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 5002c2d6a2.
PrevUpHomeNext

Rule

A Rule defines an algorithm used to match an input buffer of ASCII characters against a set of syntactical specifications. Each rule represents either a terminal symbol or a composition in the represented grammar. The library comes with a set of rules for productions typically found in RFC documents. Rules are not invoked directly; instead, rule variables are used with overloads of parse which provide a convenient, uniform front end.

Related Identifiers

is_rule, parse.

Requirements

In this table:

Table 1.11. Valid expressions

Expression

Type

Semantics, Pre/Post-conditions

T(t)

Copy construction of T throws nothing.

std::is_nothrow_copy_constructible<T>::value == true

T::value_type

Values of this type are returned by the rule when the parse operation is successful

t.parse(it,end)

result<T::value_type>

Attempt to parse the buffer of characters defined by the range [it,end). Upon success, the return result will hold an instance of the rule's value type, and the reference parameter it will be modified to point to the first unconsumed character. Otherwise, upon failure the result will hold an error. In this case the implementation defines if and how the reference parameter it is modified.


Exemplar

For best results, it is suggested that all constructors for rules be marked constexpr.

struct Rule
{
    struct value_type;

    constexpr Rule( Rule const& ) noexcept = default;

    auto parse( char const*& it, char const* end ) const -> result< value_type >;
};

// Declare a variable of type Rule for notational convenience
constexpr Rule rule{};
Models

PrevUpHomeNext