metaparse/doc/build_parser.qbk
2015-07-19 09:53:35 +02:00

68 lines
1.3 KiB
Plaintext

[#build_parser]
[section build_parser]
[h1 Synopsis]
template <class P>
struct build_parser;
This is a [link metafunction template metafunction].
[table Arguments
[[Name] [Type]]
[[`P`] [[link parser parser]]]
]
[h1 Description]
It generates a simple interface for parser. It returns a metafunction class that
takes an input string, parses it with `P` and returns the result of parsing. It
generates a compilation error when parsing fails.
[h1 Return value]
It returns a [link metafunction_class template metafunction class]:
struct
{
template <class S>
struct apply;
};
[table Arguments
[[Name] [Type]]
[[`S`] [[link string string]]]
]
[h1 Header]
#include <boost/metaparse/build_parser.hpp>
[h1 Expression semantics]
For any `p` parser and `s` compile-time string
build_parser<p>::type::apply<s>
is equivalent to
get_result<p::apply<s>>
[h1 Example]
#include <boost/metaparse/build_parser.hpp>
#include <boost/metaparse/int_.hpp>
#include <boost/metaparse/string.hpp>
using namespace boost::metaparse;
using string_to_int = build_parser<int_>::type;
static_assert(
string_to_int::apply<BOOST_METAPARSE_STRING("1113")>::type::value == 1113,
"string_to_int should be a metafunction turning a string into an int"
);
[endsect]