BOOST_METAPARSE_DEFINE_ERROR.qbk 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. [#BOOST_METAPARSE_DEFINE_ERROR]
  2. [section BOOST_METAPARSE_DEFINE_ERROR]
  3. [h1 Synopsis]
  4. #define BOOST_METAPARSE_DEFINE_ERROR(name, msg) \
  5. // unspecified
  6. This is a macro.
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`name`] [identifier token]]
  10. [[`msg`] [string literal]]
  11. ]
  12. [h1 Description]
  13. Macro for defining a [link parsing_error_message parsing error message] class.
  14. `name` is the name of the class representing the error message and `msg` is a
  15. string literal containing the description of the error.
  16. [h1 Header]
  17. #include <boost/metaparse/define_error.hpp>
  18. [h1 Expression semantics]
  19. For any `n` name and `m` string literal, given the following is defined:
  20. BOOST_METAPARSE_DEFINE_ERROR(n, m);
  21. the following pairs of expressions are equivalent:
  22. n::get_value()
  23. std::string(m)
  24. n::type
  25. n
  26. [h1 Example]
  27. #include <boost/metaparse/define_error.hpp>
  28. #include <boost/metaparse/repeated1.hpp>
  29. #include <boost/metaparse/letter.hpp>
  30. #include <boost/metaparse/int_.hpp>
  31. #include <boost/metaparse/token.hpp>
  32. #include <boost/metaparse/sequence.hpp>
  33. #include <boost/metaparse/change_error_message.hpp>
  34. #include <boost/metaparse/start.hpp>
  35. #include <boost/metaparse/get_message.hpp>
  36. #include <boost/metaparse/string.hpp>
  37. #include <type_traits>
  38. using namespace boost::metaparse;
  39. BOOST_METAPARSE_DEFINE_ERROR(age_expected, "Age expected");
  40. using name_token = token<repeated1<letter>>;
  41. using age_token = token<change_error_message<int_, age_expected>>;
  42. using name_age = sequence<name_token, age_token>;
  43. static_assert(
  44. std::is_same<
  45. age_expected,
  46. get_message<name_age::apply<BOOST_METAPARSE_STRING("Joe "), start>>::type
  47. >::type::value,
  48. "the error message should be age_expected when the age is missing"
  49. );
  50. [endsect]