fail.qbk
1.28 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
[#fail]
[section fail]
[h1 Synopsis]
template <class Msg>
struct fail;
This is a [link parser parser].
[table Arguments
[[Name] [Type]]
[[`Msg`] [[link parsing_error_message parsing error message]]]
]
[h1 Description]
Parser rejecting every input.
[h1 Header]
#include <boost/metaparse/fail.hpp>
[h1 Expression semantics]
For any `msg` parsing error message, `s` compile-time string and `pos` source
position
fail<msg>::apply<s, pos>::type
returns an error with `msg` as the error message.
[h1 Example]
#include <boost/metaparse/fail.hpp>
#include <boost/metaparse/string.hpp>
#include <boost/metaparse/start.hpp>
#include <boost/metaparse/is_error.hpp>
#include <boost/metaparse/get_message.hpp>
#include <boost/metaparse/define_error.hpp>
using namespace boost::metaparse;
BOOST_METAPARSE_DEFINE_ERROR(sample_error, "This is an example parsing error");
using fail_p = fail<sample_error>;
static_assert(
is_error<fail_p::apply<BOOST_METAPARSE_STRING("foo"), start>>::type::value,
"it should reject every input"
);
static_assert(
std::is_same<
get_message<fail_p::apply<BOOST_METAPARSE_STRING("foo"), start>>::type,
sample_error
>::type::value,
"the error message should be the type specified"
);
[endsect]