Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) |
3 |
|
|
// |
4 |
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying |
5 |
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 |
|
|
// |
7 |
|
|
// Official repository: https://github.com/boostorg/url |
8 |
|
|
// |
9 |
|
|
|
10 |
|
|
#ifndef BOOST_URL_GRAMMAR_OPTIONAL_RULE_HPP |
11 |
|
|
#define BOOST_URL_GRAMMAR_OPTIONAL_RULE_HPP |
12 |
|
|
|
13 |
|
|
#include <boost/url/detail/config.hpp> |
14 |
|
|
#include <boost/url/optional.hpp> |
15 |
|
|
#include <boost/url/error_types.hpp> |
16 |
|
|
#include <boost/core/empty_value.hpp> |
17 |
|
|
#include <boost/assert.hpp> |
18 |
|
|
|
19 |
|
|
namespace boost { |
20 |
|
|
namespace urls { |
21 |
|
|
namespace grammar { |
22 |
|
|
|
23 |
|
|
/** Match a rule, or the empty string |
24 |
|
|
|
25 |
|
|
Optional BNF elements are denoted with |
26 |
|
|
square brackets. If the specified rule |
27 |
|
|
returns any error it is treated as if |
28 |
|
|
the rule did not match. |
29 |
|
|
|
30 |
|
|
@par Value Type |
31 |
|
|
@code |
32 |
|
|
using value_type = optional< typename Rule::value_type >; |
33 |
|
|
@endcode |
34 |
|
|
|
35 |
|
|
@par Example |
36 |
|
|
Rules are used with the function @ref grammar::parse. |
37 |
|
|
@code |
38 |
|
|
system::result< optional< core::string_view > > rv = parse( "", optional_rule( token_rule( alpha_chars ) ) ); |
39 |
|
|
@endcode |
40 |
|
|
|
41 |
|
|
@par BNF |
42 |
|
|
@code |
43 |
|
|
optional = [ rule ] |
44 |
|
|
@endcode |
45 |
|
|
|
46 |
|
|
@par Specification |
47 |
|
|
@li <a href="https://datatracker.ietf.org/doc/html/rfc5234#section-3.8" |
48 |
|
|
>3.8. Optional Sequence (rfc5234)</a> |
49 |
|
|
|
50 |
|
|
@param r The rule to match |
51 |
|
|
|
52 |
|
|
@see |
53 |
|
|
@ref alpha_chars, |
54 |
|
|
@ref parse, |
55 |
|
|
@ref optional, |
56 |
|
|
@ref token_rule. |
57 |
|
|
*/ |
58 |
|
|
#ifdef BOOST_URL_DOCS |
59 |
|
|
template<class Rule> |
60 |
|
|
constexpr |
61 |
|
|
__implementation_defined__ |
62 |
|
|
optional_rule( Rule r ) noexcept; |
63 |
|
|
#else |
64 |
|
|
namespace implementation_defined { |
65 |
|
|
template<class Rule> |
66 |
|
|
struct optional_rule_t |
67 |
|
|
: private empty_value<Rule> |
68 |
|
|
{ |
69 |
|
|
using value_type = boost::optional< |
70 |
|
|
typename Rule::value_type>; |
71 |
|
|
|
72 |
|
|
system::result<value_type> |
73 |
|
|
parse( |
74 |
|
|
char const*& it, |
75 |
|
|
char const* end) const; |
76 |
|
|
|
77 |
|
|
constexpr |
78 |
|
2030 |
optional_rule_t( |
79 |
|
|
Rule const& r) noexcept |
80 |
|
|
: empty_value<Rule>( |
81 |
|
|
empty_init, |
82 |
|
2030 |
r) |
83 |
|
|
{ |
84 |
|
2030 |
} |
85 |
|
|
}; |
86 |
|
|
} // implementation_defined |
87 |
|
|
|
88 |
|
|
/** Match a rule, or the empty string |
89 |
|
|
|
90 |
|
|
Optional BNF elements are denoted with |
91 |
|
|
square brackets. If the specified rule |
92 |
|
|
returns any error it is treated as if |
93 |
|
|
the rule did not match. |
94 |
|
|
|
95 |
|
|
@par Value Type |
96 |
|
|
@code |
97 |
|
|
using value_type = optional< typename Rule::value_type >; |
98 |
|
|
@endcode |
99 |
|
|
|
100 |
|
|
@par Example |
101 |
|
|
Rules are used with the function @ref grammar::parse. |
102 |
|
|
@code |
103 |
|
|
system::result< optional< core::string_view > > rv = parse( "", optional_rule( token_rule( alpha_chars ) ) ); |
104 |
|
|
@endcode |
105 |
|
|
|
106 |
|
|
@par BNF |
107 |
|
|
@code |
108 |
|
|
optional = [ rule ] |
109 |
|
|
@endcode |
110 |
|
|
|
111 |
|
|
@par Specification |
112 |
|
|
@li <a href="https://datatracker.ietf.org/doc/html/rfc5234#section-3.8" |
113 |
|
|
>3.8. Optional Sequence (rfc5234)</a> |
114 |
|
|
|
115 |
|
|
@param r The rule to match |
116 |
|
|
|
117 |
|
|
@see |
118 |
|
|
@ref alpha_chars, |
119 |
|
|
@ref parse, |
120 |
|
|
@ref optional, |
121 |
|
|
@ref token_rule. |
122 |
|
|
*/ |
123 |
|
|
template<class Rule> |
124 |
|
|
auto |
125 |
|
|
constexpr |
126 |
|
1966 |
optional_rule( |
127 |
|
|
Rule const& r) -> |
128 |
|
|
implementation_defined::optional_rule_t<Rule> |
129 |
|
|
{ |
130 |
|
1966 |
return { r }; |
131 |
|
|
} |
132 |
|
|
#endif |
133 |
|
|
|
134 |
|
|
} // grammar |
135 |
|
|
} // urls |
136 |
|
|
} // boost |
137 |
|
|
|
138 |
|
|
#include <boost/url/grammar/impl/optional_rule.hpp> |
139 |
|
|
|
140 |
|
|
#endif |
141 |
|
|
|