[#boost-urls-grammar-Rule]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/grammar.adoc[grammar]::Rule
:relfileprefix: ../../../
:mrdocs:

Concept for a grammar Rule

== Synopsis

Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/grammar/type_traits.hpp#L119[boost&sol;url&sol;grammar&sol;type&lowbar;traits&period;hpp]&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class T&gt;
concept Rule = requires (T t, char const&ast;&amp; it, char const&ast; end)
    &lcub;
        typename T&colon;&colon;value&lowbar;type&semi;
        &lcub; t&period;parse(it, end) &rcub; &hyphen;&gt; std&colon;&colon;same&lowbar;as&lt;system&colon;&colon;result&lt;typename T&colon;&colon;value&lowbar;type&gt;&gt;&semi;
    &rcub;;
----

== Description

This concept is satisfied if `T` is a valid grammar Rule

A `Rule` defines an algorithm used to match an input buffer of ASCII characters against a set of syntactical specifications&period;

Each rule represents either a terminal symbol or a composition in the represented grammar&period;

The library comes with a set of rules for productions typically found in RFC documents&period; Rules are not invoked directly&semi; instead, rule variables are used with overloads of xref:boost/urls/grammar/parse-09.adoc[`parse`] which provide a convenient, uniform front end&period;

== Exemplar

For best results, it is suggested that all constructors for rules be marked `constexpr`&period;

[,cpp]
----
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{};
----
== Model

* `dec&lowbar;octet&lowbar;rule`
* `delim&lowbar;rule`
* `not&lowbar;empty&lowbar;rule`
* `optional&lowbar;rule`
* `range&lowbar;rule`
* `token&lowbar;rule`
* `tuple&lowbar;rule`
* `unsigned&lowbar;rule`
* `variant&lowbar;rule`

== See Also

xref:boost/urls/grammar/parse-09.adoc[`parse`], xref:boost/urls/grammar/is_rule.adoc[`is&lowbar;rule`]&period;


[.small]#Created with https://www.mrdocs.com[MrDocs]#
