keyword.qbk 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. [#keyword]
  2. [section keyword]
  3. [h1 Synopsis]
  4. template <class S, class ResultType = /* unspecified */>
  5. struct keyword;
  6. This is a [link parser parser].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`S`] [[link string string]]]
  10. [[`ResultType`] [[link metaprogramming_value template metaprogramming value]]]
  11. ]
  12. [h1 Description]
  13. Parser accepting the keyword `S`. The result of parsing is `ResultType`, which
  14. is optional; when not given, the result of successful parsing is undefined.
  15. [h1 Header]
  16. #include <boost/metaparse/keyword.hpp>
  17. [h1 Expression semantics]
  18. For any `r` class and `s` compile-time string that is built from the characters
  19. `c1` ... `cn` the following are equivalent:
  20. keyword<s, r>
  21. last_of<lit<c1>, /* ... */, lit<cn>, return_<r>>
  22. [h1 Example]
  23. #include <boost/metaparse/keyword.hpp>
  24. #include <boost/metaparse/string.hpp>
  25. #include <boost/metaparse/start.hpp>
  26. #include <boost/metaparse/get_result.hpp>
  27. #include <boost/metaparse/is_error.hpp>
  28. #include <type_traits>
  29. using namespace boost::metaparse;
  30. static_assert(
  31. get_result<
  32. keyword<BOOST_METAPARSE_STRING("for"), std::integral_constant<int, 13>>
  33. ::apply<BOOST_METAPARSE_STRING("for"), start>
  34. >::type::value == 13,
  35. "the result of parsing the keyword is keyword's second argument"
  36. );
  37. static_assert(
  38. is_error<
  39. keyword<BOOST_METAPARSE_STRING("for"), std::integral_constant<int, 13>>
  40. ::apply<BOOST_METAPARSE_STRING("if"), start>
  41. >::type::value,
  42. "a word other than the keyword is an error"
  43. );
  44. [endsect]