fail.qbk 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. [#fail]
  2. [section fail]
  3. [h1 Synopsis]
  4. template <class Msg>
  5. struct fail;
  6. This is a [link parser parser].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`Msg`] [[link parsing_error_message parsing error message]]]
  10. ]
  11. [h1 Description]
  12. Parser rejecting every input.
  13. [h1 Header]
  14. #include <boost/metaparse/fail.hpp>
  15. [h1 Expression semantics]
  16. For any `msg` parsing error message, `s` compile-time string and `pos` source
  17. position
  18. fail<msg>::apply<s, pos>::type
  19. returns an error with `msg` as the error message.
  20. [h1 Example]
  21. #include <boost/metaparse/fail.hpp>
  22. #include <boost/metaparse/string.hpp>
  23. #include <boost/metaparse/start.hpp>
  24. #include <boost/metaparse/is_error.hpp>
  25. #include <boost/metaparse/get_message.hpp>
  26. #include <boost/metaparse/define_error.hpp>
  27. using namespace boost::metaparse;
  28. BOOST_METAPARSE_DEFINE_ERROR(sample_error, "This is an example parsing error");
  29. using fail_p = fail<sample_error>;
  30. static_assert(
  31. is_error<fail_p::apply<BOOST_METAPARSE_STRING("foo"), start>>::type::value,
  32. "it should reject every input"
  33. );
  34. static_assert(
  35. std::is_same<
  36. get_message<fail_p::apply<BOOST_METAPARSE_STRING("foo"), start>>::type,
  37. sample_error
  38. >::type::value,
  39. "the error message should be the type specified"
  40. );
  41. [endsect]