]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/example/x3/actions.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2015 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #include <boost/config/warning_disable.hpp>
8 #include <boost/spirit/home/x3.hpp>
12 // Presented are various ways to attach semantic actions
13 // * Using plain function pointer
14 // * Using simple function object
18 namespace x3
= boost::spirit::x3
;
23 template <typename Context
>
24 void operator()(Context
const& ctx
) const
26 std::cout
<< _attr(ctx
) << std::endl
;
33 using boost::spirit::x3::int_
;
34 using boost::spirit::x3::parse
;
35 using client::print_action
;
37 { // example using function object
39 char const *first
= "{43}", *last
= first
+ std::strlen(first
);
40 parse(first
, last
, '{' >> int_
[print_action()] >> '}');
43 { // example using C++14 lambda
45 using boost::spirit::x3::_attr
;
46 char const *first
= "{44}", *last
= first
+ std::strlen(first
);
47 auto f
= [](auto& ctx
){ std::cout
<< _attr(ctx
) << std::endl
; };
48 parse(first
, last
, '{' >> int_
[f
] >> '}');