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