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

65 lines
1.5 KiB
Plaintext

[#keyword]
[section keyword]
[h1 Synopsis]
template <class S, class ResultType = /* unspecified */>
struct keyword;
This is a [link parser parser].
[table Arguments
[[Name] [Type]]
[[`S`] [[link string string]]]
[[`ResultType`] [[link metaprogramming_value template metaprogramming value]]]
]
[h1 Description]
Parser accepting the keyword `S`. The result of parsing is `ResultType`, which
is optional; when not given, the result of successful parsing is undefined.
[h1 Header]
#include <boost/metaparse/keyword.hpp>
[h1 Expression semantics]
For any `r` class and `s` compile-time string that is built from the characters
`c1` ... `cn` the following are equivalent:
keyword<s, r>
last_of<lit<c1>, /* ... */, lit<cn>, return_<r>>
[h1 Example]
#include <boost/metaparse/keyword.hpp>
#include <boost/metaparse/string.hpp>
#include <boost/metaparse/start.hpp>
#include <boost/metaparse/get_result.hpp>
#include <boost/metaparse/is_error.hpp>
#include <type_traits>
using namespace boost::metaparse;
static_assert(
get_result<
keyword<BOOST_METAPARSE_STRING("for"), std::integral_constant<int, 13>>
::apply<BOOST_METAPARSE_STRING("for"), start>
>::type::value == 13,
"the result of parsing the keyword is keyword's second argument"
);
static_assert(
is_error<
keyword<BOOST_METAPARSE_STRING("for"), std::integral_constant<int, 13>>
::apply<BOOST_METAPARSE_STRING("if"), start>
>::type::value,
"a word other than the keyword is an error"
);
[endsect]