1 [#change_error_message]
2 [section change_error_message]
6 template <class P, class Msg>
7 struct change_error_message;
9 This is a [link parser_combinator parser combinator].
13 [[`P`] [[link parser parser]]]
14 [[`Msg`] [[link parsing_error_message parsing error message]]]
19 It applies `P` on the input. When `P` succeeds, `change_error_message` returns
20 the result `P` returns, otherwise `change_error_message` rejects the input and
21 the reason will be `Msg`.
25 #include <boost/metaparse/change_error_message.hpp>
27 [h1 Expression semantics]
29 For any `p` parser and `m` parsing error message, `s` compile-time string and
32 change_error_message<p, msg>::apply<s, pos>
34 is equivalent to `p::apply<s, pos>` when `p` accepts the input.
35 It is equivalent to `fail<msg>::apply<s, pos>` otherwise.
39 #include <boost/metaparse/change_error_message.hpp>
40 #include <boost/metaparse/repeated1.hpp>
41 #include <boost/metaparse/letter.hpp>
42 #include <boost/metaparse/keyword.hpp>
43 #include <boost/metaparse/last_of.hpp>
44 #include <boost/metaparse/token.hpp>
45 #include <boost/metaparse/string.hpp>
46 #include <boost/metaparse/is_error.hpp>
47 #include <boost/metaparse/start.hpp>
48 #include <boost/metaparse/get_message.hpp>
49 #include <boost/metaparse/define_error.hpp>
51 #include <type_traits>
53 using namespace boost::metaparse;
55 BOOST_METAPARSE_DEFINE_ERROR(name_expected, "Name expected");
57 using keyword_name = token<keyword<BOOST_METAPARSE_STRING("name")>>;
58 using name_token = token<repeated1<letter>>;
61 last_of<keyword_name, change_error_message<name_token, name_expected>>;
65 name_parser::apply<BOOST_METAPARSE_STRING("name Bela"), start>
67 "name_parser should accept \"name <a name>\""
72 name_parser::apply<BOOST_METAPARSE_STRING("name ?"), start>
74 "name_parser should reject input when name is a question mark"
80 name_parser::apply<BOOST_METAPARSE_STRING("name ?"), start>
84 "the error message should be the one specified by change_error_message"