1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- [#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]
|