get_position.qbk 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. [#get_position]
  2. [section get_position]
  3. [h1 Synopsis]
  4. template <class D>
  5. struct get_position;
  6. This is a [link lazy_metafunction lazy template metafunction].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`D`] [[link accept accept] or [link reject reject] value]]
  10. ]
  11. [h1 Description]
  12. Returns the source position information of a parsing result.
  13. [h1 Header]
  14. #include <boost/metaparse/get_position.hpp>
  15. [h1 Example]
  16. #include <boost/metaparse/get_position.hpp>
  17. #include <boost/metaparse/start.hpp>
  18. #include <boost/metaparse/accept.hpp>
  19. #include <boost/metaparse/reject.hpp>
  20. #include <boost/metaparse/string.hpp>
  21. #include <boost/metaparse/define_error.hpp>
  22. #include <type_traits>
  23. using namespace boost::metaparse;
  24. BOOST_METAPARSE_DEFINE_ERROR(sample_error, "Sample error message");
  25. struct returns_reject
  26. {
  27. using type = reject<sample_error, start>;
  28. };
  29. static_assert(
  30. std::is_same<
  31. start,
  32. get_position<reject<sample_error, start>>::type
  33. >::type::value,
  34. "It should return the position of a reject"
  35. );
  36. static_assert(
  37. std::is_same<
  38. start,
  39. get_position<
  40. accept<sample_error, BOOST_METAPARSE_STRING("foo"), start>
  41. >::type
  42. >::type::value,
  43. "It should return the position of an accept"
  44. );
  45. static_assert(
  46. std::is_same<start, get_position<returns_reject>::type>::type::value,
  47. "It should support lazy evaluation"
  48. );
  49. [endsect]