]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [#BOOST_METAPARSE_DEFINE_ERROR] |
2 | [section BOOST_METAPARSE_DEFINE_ERROR] | |
3 | ||
4 | [h1 Synopsis] | |
5 | ||
6 | #define BOOST_METAPARSE_DEFINE_ERROR(name, msg) \ | |
7 | // unspecified | |
8 | ||
9 | This is a macro. | |
10 | ||
11 | [table Arguments | |
12 | [[Name] [Type]] | |
13 | [[`name`] [identifier token]] | |
14 | [[`msg`] [string literal]] | |
15 | ] | |
16 | ||
17 | [h1 Description] | |
18 | ||
19 | Macro for defining a [link parsing_error_message parsing error message] class. | |
20 | `name` is the name of the class representing the error message and `msg` is a | |
21 | string literal containing the description of the error. | |
22 | ||
23 | [h1 Header] | |
24 | ||
25 | #include <boost/metaparse/define_error.hpp> | |
26 | ||
27 | [h1 Expression semantics] | |
28 | ||
29 | For any `n` name and `m` string literal, given the following is defined: | |
30 | ||
31 | BOOST_METAPARSE_DEFINE_ERROR(n, m); | |
32 | ||
33 | the following pairs of expressions are equivalent: | |
34 | ||
35 | n::get_value() | |
36 | std::string(m) | |
37 | ||
38 | n::type | |
39 | n | |
40 | ||
41 | [h1 Example] | |
42 | ||
43 | #include <boost/metaparse/define_error.hpp> | |
44 | #include <boost/metaparse/repeated1.hpp> | |
45 | #include <boost/metaparse/letter.hpp> | |
46 | #include <boost/metaparse/int_.hpp> | |
47 | #include <boost/metaparse/token.hpp> | |
48 | #include <boost/metaparse/sequence.hpp> | |
49 | #include <boost/metaparse/change_error_message.hpp> | |
50 | #include <boost/metaparse/start.hpp> | |
51 | #include <boost/metaparse/get_message.hpp> | |
52 | #include <boost/metaparse/string.hpp> | |
53 | ||
54 | #include <type_traits> | |
55 | ||
56 | using namespace boost::metaparse; | |
57 | ||
58 | BOOST_METAPARSE_DEFINE_ERROR(age_expected, "Age expected"); | |
59 | ||
60 | using name_token = token<repeated1<letter>>; | |
61 | using age_token = token<change_error_message<int_, age_expected>>; | |
62 | ||
63 | using name_age = sequence<name_token, age_token>; | |
64 | ||
65 | static_assert( | |
66 | std::is_same< | |
67 | age_expected, | |
68 | get_message<name_age::apply<BOOST_METAPARSE_STRING("Joe "), start>>::type | |
69 | >::type::value, | |
70 | "the error message should be age_expected when the age is missing" | |
71 | ); | |
72 | ||
73 | [endsect] | |
74 |