build_parser.qbk 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. [#build_parser]
  2. [section build_parser]
  3. [h1 Synopsis]
  4. template <class P>
  5. struct build_parser;
  6. This is a [link metafunction template metafunction].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`P`] [[link parser parser]]]
  10. ]
  11. [h1 Description]
  12. It generates a simple interface for parser. It returns a metafunction class that
  13. takes an input string, parses it with `P` and returns the result of parsing. It
  14. generates a compilation error when parsing fails.
  15. [h1 Return value]
  16. It returns a [link metafunction_class template metafunction class]:
  17. struct
  18. {
  19. template <class S>
  20. struct apply;
  21. };
  22. [table Arguments
  23. [[Name] [Type]]
  24. [[`S`] [[link string string]]]
  25. ]
  26. [h1 Header]
  27. #include <boost/metaparse/build_parser.hpp>
  28. [h1 Expression semantics]
  29. For any `p` parser and `s` compile-time string
  30. build_parser<p>::type::apply<s>
  31. is equivalent to
  32. get_result<p::apply<s>>
  33. [h1 Example]
  34. #include <boost/metaparse/build_parser.hpp>
  35. #include <boost/metaparse/int_.hpp>
  36. #include <boost/metaparse/string.hpp>
  37. using namespace boost::metaparse;
  38. using string_to_int = build_parser<int_>::type;
  39. static_assert(
  40. string_to_int::apply<BOOST_METAPARSE_STRING("1113")>::type::value == 1113,
  41. "string_to_int should be a metafunction turning a string into an int"
  42. );
  43. [endsect]