lit.qbk 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. [#lit]
  2. [section lit]
  3. [h1 Synopsis]
  4. template <class C>
  5. struct lit;
  6. This is a [link parser parser].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`C`] [[link boxed_value boxed] character value]]
  10. ]
  11. [h1 Description]
  12. Parser accepting only the `C` character. The result of parsing is the accepted
  13. character.
  14. [h1 Header]
  15. #include <boost/metaparse/lit.hpp>
  16. [h1 Expression semantics]
  17. For any `c` boxed character the following are equivalent:
  18. lit<c>
  19. accept_when<
  20. one_char,
  21. boost::mpl::lambda<boost::mpl::equal_to<boost::mpl::_1, c>>::type,
  22. error::literal_expected<c::type::value>
  23. >
  24. [h1 Example]
  25. #include <boost/metaparse/lit.hpp>
  26. #include <boost/metaparse/start.hpp>
  27. #include <boost/metaparse/string.hpp>
  28. #include <boost/metaparse/is_error.hpp>
  29. #include <boost/metaparse/get_result.hpp>
  30. #include <type_traits>
  31. using namespace boost::metaparse;
  32. static_assert(
  33. is_error<
  34. lit<std::integral_constant<char, 'x'>>
  35. ::apply<BOOST_METAPARSE_STRING("a"), start>
  36. >::type::value,
  37. "a different character should be an error"
  38. );
  39. static_assert(
  40. is_error<
  41. lit<std::integral_constant<char, 'x'>>
  42. ::apply<BOOST_METAPARSE_STRING(""), start>
  43. >::type::value,
  44. "empty input should be an error"
  45. );
  46. static_assert(
  47. get_result<
  48. lit<std::integral_constant<char, 'x'>>
  49. ::apply<BOOST_METAPARSE_STRING("x"), start>
  50. >::type::value == 'x',
  51. "result of parsing should be the accepted character"
  52. );
  53. [endsect]