2 [section transform_error]
6 template <class P, class F>
7 struct transform_error;
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` will be the result of parsing with `P`. When it fails, `F` is
21 evaluated with the error `P` returned as argument. Parsing with
22 `transform_error` will fail and the error will be what `F` returns. Therefore,
23 `F` is expected to accept and return a [link reject `reject`] value.
27 #include <boost/metaparse/transform_error.hpp>
29 [h1 Expression semantics]
31 For any `p` parser and `f` metafunction class accepting one argument
33 transform_error<p, f>::apply<s, pos>
35 is equivalent to `p::apply<s, pos>` when `p` accepts the input. It is equivalent
36 to `f::apply<p::apply<s, pos>::type>` otherwise.
40 #include <boost/metaparse/transform_error.hpp>
41 #include <boost/metaparse/repeated1.hpp>
42 #include <boost/metaparse/letter.hpp>
43 #include <boost/metaparse/keyword.hpp>
44 #include <boost/metaparse/last_of.hpp>
45 #include <boost/metaparse/token.hpp>
46 #include <boost/metaparse/string.hpp>
47 #include <boost/metaparse/is_error.hpp>
48 #include <boost/metaparse/start.hpp>
49 #include <boost/metaparse/get_message.hpp>
50 #include <boost/metaparse/get_position.hpp>
51 #include <boost/metaparse/define_error.hpp>
52 #include <boost/metaparse/reject.hpp>
54 #include <boost/mpl/lambda.hpp>
56 #include <type_traits>
58 using namespace boost::metaparse;
60 BOOST_METAPARSE_DEFINE_ERROR(name_expected, "Name expected");
62 using keyword_name = token<keyword<BOOST_METAPARSE_STRING("name")>>;
63 using name_token = token<repeated1<letter>>;
71 reject<name_expected, get_position<boost::mpl::_1> >
78 name_parser::apply<BOOST_METAPARSE_STRING("name Bela"), start>
80 "name_parser should accept \"name <a name>\""
85 name_parser::apply<BOOST_METAPARSE_STRING("name ?"), start>
87 "name_parser should reject input when name is a question mark"
93 name_parser::apply<BOOST_METAPARSE_STRING("name ?"), start>
97 "the error message should be the one specified by change_error_message"