semantic action problem
Eugene Varshavsky <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
Klemens, Thank you for the quick reply, Sorry for posting a screen shot in the first place... I am attaching the code this time. It is an exact copy from the Spirit tutorial at: http://ciere.com/cppnow15/x3_docs/spirit/tutorials/semantic_actions.html I am using: Visual Studio Community 2015 Version 14.0.24720.00 Update 1 File call.hpp appears to be part of boost.spirit, it is located at: C/.../Boost/boost_1_62_0/boost/spirit/home/x3/core Using x3::_attr in main for the lambda did not seem to help. Thank you, Eugene ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Spirit-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/spirit-general
feature_descriptor_main.cpp
(text/plain, 1.3 KB)
/*=============================================================================
Copyright (c) 2001-2015 Joel de Guzman
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/home/x3.hpp>
#include <iostream>
// Presented are various ways to attach semantic actions
// * Using plain function pointer
// * Using simple function object
namespace client
{
namespace x3 = boost::spirit::x3;
using x3::_attr;
struct print_action
{
template <typename Context>
void operator()(Context const& ctx) const
{
std::cout << _attr(ctx) << std::endl;
}
};
}
int main()
{
using boost::spirit::x3::int_;
using boost::spirit::x3::parse;
using client::print_action;
{ // example using function object
char const *first = "{43}", *last = first + std::strlen(first);
parse(first, last, '{' >> int_[print_action()] >> '}');
}
{ // example using C++14 lambda
char const *first = "{44}", *last = first + std::strlen(first);
auto f = [](auto& ctx) { std::cout << _attr(ctx) << std::endl; };
parse(first, last, '{' >> int_[f] >> '}');
}
return 0;
}