1 [#transform_error_message]
2 [section transform_error_message]
6 template <class P, class F>
7 struct transform_error_message;
9 This is a [link parser_combinator parser combinator].
13 [[`P`] [[link parser parser]]]
14 [[`F`] [[link metafunction_class template metafunction class] taking one argument]]
19 It parses the input with `P`. When this succeeds, the result of parsing with
20 `transform_error_message` will be the result of parsing with `P`. When it fails,
21 the error `P` returns is forwarded to the caller of `transform_error_message`,
22 but the message of it is transformed with `F`.
26 #include <boost/metaparse/transform_error_message.hpp>
28 [h1 Expression semantics]
30 For any `p` parser and `f` metafunction class accepting one argument
32 transform_error_message<p, f>::apply<s, pos>
34 is equivalent to `p::apply<s, pos>` when `p` accepts the input.
36 `reject<f::apply<get_message<p::apply<s, pos>>::type>, get_position<p::apply<s, pos>>>`
41 #include <boost/metaparse/transform_error_message.hpp>
42 #include <boost/metaparse/repeated1.hpp>
43 #include <boost/metaparse/letter.hpp>
44 #include <boost/metaparse/keyword.hpp>
45 #include <boost/metaparse/last_of.hpp>
46 #include <boost/metaparse/token.hpp>
47 #include <boost/metaparse/string.hpp>
48 #include <boost/metaparse/is_error.hpp>
49 #include <boost/metaparse/start.hpp>
50 #include <boost/metaparse/get_message.hpp>
51 #include <boost/metaparse/define_error.hpp>
52 #include <boost/metaparse/reject.hpp>
54 #include <type_traits>
56 using namespace boost::metaparse;
58 BOOST_METAPARSE_DEFINE_ERROR(name_expected, "Name expected");
60 struct return_name_expected
62 typedef return_name_expected type;
65 struct apply : name_expected {};
68 using keyword_name = token<keyword<BOOST_METAPARSE_STRING("name")>>;
69 using name_token = token<repeated1<letter>>;
74 transform_error_message<name_token, return_name_expected>
79 name_parser::apply<BOOST_METAPARSE_STRING("name Bela"), start>
81 "name_parser should accept \"name <a name>\""
86 name_parser::apply<BOOST_METAPARSE_STRING("name ?"), start>
88 "name_parser should reject input when name is a question mark"
94 name_parser::apply<BOOST_METAPARSE_STRING("name ?"), start>
98 "the error message should be the one specified by change_error_message"