parse.hpp
3.01 KB
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
141
142
143
144
//
// 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_PARSE_HPP
#define BOOST_URL_GRAMMAR_PARSE_HPP
#include <boost/url/detail/config.hpp>
#include <boost/url/error_types.hpp>
#include <boost/url/string_view.hpp>
#include <boost/url/grammar/type_traits.hpp>
namespace boost {
namespace urls {
namespace grammar {
//------------------------------------------------
/** Parse a character buffer using a rule
@param it A pointer to the start. The
caller's variable is changed to
reflect the amount of input consumed.
@param end A pointer to the end.
@param r The rule to use
@return The parsed value upon success,
otherwise an error.
@see
@ref result.
*/
template<class Rule>
result<typename Rule::value_type>
parse(
char const*& it,
char const* end,
Rule const& r);
/** Parse a character buffer using a rule
This function parses a complete string into
the specified sequence of rules. If the
string is not completely consumed, an
error is returned instead.
@param s The input string
@param r The rule to use
@return The parsed value upon success,
otherwise an error.
@see
@ref result.
*/
template<class Rule>
result<typename Rule::value_type>
parse(
string_view s,
Rule const& r);
//------------------------------------------------
#ifndef BOOST_URL_DOCS
namespace detail {
template<class Rule>
struct rule_ref
{
Rule const& r_;
using value_type =
typename Rule::value_type;
result<value_type>
parse(
char const*& it,
char const* end) const
{
return r_.parse(it, end);
}
};
} // detail
#endif
/** Return a reference to a rule
This function returns a rule which
references the specified object. This is
used to reduce the number of bytes of
storage (`sizeof`) required by a combinator
when it stores a copy of the object.
<br>
Ownership of the object is not transferred;
the caller is responsible for ensuring the
lifetime of the object is extended until it
is no longer referenced. For best results,
`ref` should only be used with compile-time
constants.
@param r The rule to use
*/
template<class Rule>
constexpr
#ifdef BOOST_URL_DOCS
__implementation_defined__
#else
typename std::enable_if<
is_rule<Rule>::value &&
! std::is_same<Rule,
detail::rule_ref<Rule> >::value,
detail::rule_ref<Rule> >::type
#endif
ref(Rule const& r) noexcept
{
return detail::rule_ref<
Rule>{r};
}
#ifndef BOOST_URL_DOCS
// If you get a compile error here it
// means you called ref with something
// that is not a CharSet or Rule!
constexpr
void
ref(...) = delete;
#endif
} // grammar
} // urls
} // boost
#include <boost/url/grammar/impl/parse.hpp>
#endif